> ## Documentation Index
> Fetch the complete documentation index at: https://docs.parea.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployed Prompts

> Deploy versioned prompts and use them via the SDK.

Take advantage of Parea's version management with deployed prompts. Deploying a prompt makes it available via the SDK.
All prompt parameters are bundled with a deployment, including function call schemas and model parameters.

## Prerequisites

1. First, you'll need a Parea API key. See [Authentication](/api-reference/authentication#parea-api-key) to get started.
2. For any model you want to use with the SDK, set up your [Provider API keys](/api-reference/authentication#provider-api-keys).

## How to deploy a prompt

Visit the [Playground](https://app.parea.ai/playground) to view or create prompts. After testing your prompt, you can click the blue rocket icon to deploy it.

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/deploy-prompt.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=12f4fdd22eb531829e7d02b1bcb3429c" alt="DeployPrompt" width="673" height="452" data-path="platform/deploy-prompt.png" />

Afterward, optionally provide a name and commit message for the deployment and copy the deployment ID.
*(Don't worry; you can get the deployment ID later from the [Deployments tab](https://app.parea.ai/deployments))*

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/deploy-modal.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=05e61227ee2dc2f7132b7cff53e6fd09" alt="DeployModal" width="794" height="595" data-path="platform/deploy-modal.png" />

Prompt deployments are specific to the selected version. In the Playground, when you change a prompt or its
parameters and save it, a new version will automatically be created.
You can bump or rollback deployment versions while maintaining the same deployment ID.
This makes it easy to change your prompt without updating your code.

### Bumping / Revert a deployment

In the Playground, if a prompt has been previously deployed, and you click the rocket icon on a new version,
you will be prompted to confirm whether to bump (if the current version is > than the deployed) or
revert (if the current version is \< than the deployed) the deployment.
*(You could also create an entirely new deployment with a new deployment name and ID.)*

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/bump-revert.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=650793128dcb3e52ba4b3b1e835db884" alt="BumpRevert" width="802" height="602" data-path="platform/bump-revert.png" />

### A/B test, or QA a prompt

Sometimes you may want to have two branches of the same prompt. One for production, and one for testing.
With the drop-down menu, when bumping or reverting a deployment you can choose which branch should change.

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/branch-switch-dropdown.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=9828f083253171b696b7f02af9e82133" alt="DropdownBranch" width="773" height="153" data-path="platform/branch-switch-dropdown.png" />

#### Common Workflow:

* Deploy prompt v0 to dev and test using experiments
* After you are happy with performance, deploy the same prompt version as a new prod branch
* Continue to iterate on the dev branch by selectively bumping or reverting that branch only
* When ready, bump the prod branch to the latest and greatest version

## How to use a deployed prompt

You can interact with your deployed prompts in two ways. Use the prompt directly or fetch the prompt's data to use in your code.

### Use deployed prompt

Using the [completion](/api-reference/endpoint/completion) endpoint, you can set the `deployment_id`
parameter and provide the prompt template inputs.

<CodeGroup>
  ```python python theme={null}
  def deployed_critic(argument: str) -> CompletionResponse:
      return p.completion(
          Completion(
              deployment_id="p-PSOwRyIPaQRq4xQW3MbpV",
              llm_inputs={"argument": argument},
          )
      )
  ```

  ```typescript typescript theme={null}
  const deployedCritic = async (argument: string): Promise<CompletionResponse> => {
    return await p.completion({
      deployment_id: 'p-PSOwRyIPaQRq4xQW3MbpV',
      llm_inputs: { argument: argument },
    });
  };
  ```

  ```curl curl theme={null}
  curl --location 'https://parea-ai-backend-us-9ac16cdbc7a7b006.onporter.run/api/parea/v1/completion' \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: PAREA_API_KEY' \
  --data '{
      "deployment_id": "p-PSOwRyIPaQRq4xQW3MbpV",
      "llm_inputs": {"argument": "some value"}
  }'
  ```
</CodeGroup>

### Fetch deployed prompt

You can fetch the prompt data and utilize it in your code using the
[get deployed prompt](/api-reference/endpoint/deployed-prompt) endpoint.
The response will include the raw prompt and the prompt filled in with the provided inputs and other metadata.

<Note> If you fetch a deployed prompt to use with your own LLM API, but still want traced logs associated with the deployment, you can either add
`deployment_id` to the trace decorator, or use `trace_insert({"deployment_id": "p-PSOwRyIPaQRq4xQW3MbspVz"})` in your code.</Note>

<CodeGroup>
  ```python python theme={null}
  def get_critic_prompt(argument: str) -> UseDeployedPromptResponse:
      return p.get_prompt(
          UseDeployedPrompt(
              deployment_id="p-PSOwRyIPaQRq4xQW3MbpV",
              llm_inputs={"argument": argument}
          )
      )
  ```

  ```typescript typescript theme={null}
  export const getCriticPrompt = async (): Promise<UseDeployedPromptResponse> => {
    return await p.getPrompt({
      deployment_id: 'p-PSOwRyIPaQRq4xQW3MbpV',
      llm_inputs: {
        argument: 'Hello World',
      },
    });
  };
  ```

  ```curl curl theme={null}
  curl --location 'https://parea-ai-backend-us-9ac16cdbc7a7b006.onporter.run/api/parea/v1/deployed-prompt' \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: PAREA_API_KEY' \
  --data '{
      "deployment_id": "p-PSOwRyIPaQRq4xQW3MbpV",
      "llm_inputs": {"argument": "some value"}
  }'
  ```
</CodeGroup>

<Accordion title="Response Object">
  <CodeGroup>
    ```python python theme={null}
        response_object = UseDeployedPromptResponse(
            deployment_id="p-PSOwRyIPaQRq4xQW3MbpV",
            version_number=1.0,
            name="critic-2",
            functions=[],
            function_call=None,
            prompt=Prompt(
                raw_messages=[
                    {
                        "role": "system",
                        "content": "You are a critic.\n"
                        "What unresolved questions or criticism do you have "
                        "after reading the following argument?"
                        "\nProvide a concise summary of your feedback.",
                    },
                    {"role": "system", "content": "Argument: {{argument}}"},
                ],
                messages=[
                    {
                        "content": "You are a critic.\n"
                        "What unresolved questions or criticism do you have "
                        "after reading the following argument?"
                        "\nProvide a concise summary of your feedback.",
                        "role": "system",
                    },
                    {"content": "Argument: Hello World", "role": "system"},
                ],
                inputs={"argument": "Hello World"},
            ),
            model="gpt-3.5-turbo-0613",
            provider="openai",
            model_params={
                "temp": 0.0,
                "top_p": 1.0,
                "max_length": None,
                "presence_penalty": 0.0,
                "frequency_penalty": 0.0,
            },
        )
    ```

    ```typescript typescript theme={null}
        const responseObject = {
          deployment_id: 'p-PSOwRyIPaQRq4xQW3MbpV',
          version_number: 1,
          name: 'critic-2',
          functions: [],
          function_call: null,
          prompt: {
            raw_messages: [
              {
                role: 'system',
                content:
                  'You are a critic.\n' +
                  'What unresolved questions or criticism do you have after reading the following argument?\n' +
                  'Provide a concise summary of your feedback.',
              },
              { role: 'system', content: 'Argument: {{argument}}' },
            ],
            messages: [
              {
                content:
                  'You are a critic.\n' +
                  'What unresolved questions or criticism do you have after reading the following argument?\n' +
                  'Provide a concise summary of your feedback.',
                role: 'system',
              },
              { content: 'Argument: Hello World', role: 'system' },
            ],
            inputs: { argument: 'Hello World' },
          },
          model: 'gpt-3.5-turbo-0613',
          provider: 'openai',
          model_params: {
            temp: 0,
            top_p: 1,
            max_length: null,
            presence_penalty: 0,
            frequency_penalty: 0,
          },
        };
    ```
  </CodeGroup>
</Accordion>

## Deployments Dashboard

On the [Deployments tab](https://app.parea.ai/deployments) you can get a list of your deployments and associated information. Clicking an item will open a detailed view of your prompt and dashboard specific for that deployment.

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/deployment_table.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=002ad7ac7c85d5397cecb61b4b4e91cb" alt="deployment_table" width="1497" height="450" data-path="platform/deployment_table.png" />

### Detailed Deployment View

The detailed deployments page has two tabs. Prompt and Dashboard.

#### Prompt

On the prompt tab you can view all of the prompt's parameters including the messages and any attached functions. You can also access the history of the deployment and bump or revert to a different version.
By clicking 'Edit' you can jump to the Playground and make changes to the prompt and deploy a new version.

<img src="https://mintcdn.com/pareaai/lIjZ3aMZeTkxaUc8/platform/prompt-view.png?fit=max&auto=format&n=lIjZ3aMZeTkxaUc8&q=85&s=6ad92d882bcf9fc14c69016503456cf0" alt="PromptView" width="1837" height="822" data-path="platform/prompt-view.png" />

#### Dashboard

On the dashboard tab you can see the prompt's usage statistics and trace logs. By clicking any trace you can view the [full detailed trace](/observability/overview#trace-details).

<img src="https://mintcdn.com/pareaai/3kurg3MZRrsWWk8t/platform/deployment-view.png?fit=max&auto=format&n=3kurg3MZRrsWWk8t&q=85&s=e912cc8cd8eef3da632f186434e79b84" alt="DeploymentView" width="1837" height="950" data-path="platform/deployment-view.png" />

## Cookbook examples

* [Python Cookbook](https://github.com/parea-ai/parea-sdk-py/tree/d4d833d79fad4f9c367d38d9a9368153c9471459/cookbook/parea_llm_proxy/deployments)
* [Typescript Cookbook](https://github.com/parea-ai/parea-sdk-ts/blob/58641d0117d935f27818138ff89a107c13034503/cookbook/tracing_with_deployed_prompt.ts)
