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

# Create version

You can create a prompt version by sending a POST request to the prompt versions endpoint. The request should include the list of messages for the prompt version, the model you want to use, and other optional parameters. After you created a prompt version, you can deploy it as the live version by setting the `deploy` parameter to `true`.

Get the `prompt_id` from the [prompts endpoint](/api-endpoints/develop/prompts/create-prompts).

<ParamField body="messages" type="array" required={true}>
  The list of messages for the prompt version. If you want to add a variable, you can use the following format: `{{variable_name}}`.

  <Accordion title="Example">
    ```json theme={"system"}
    {
    "messages": [
        {"role": "system", "content": "You are a helpful {{role}}."}, // role could be assistant, teacher, etc.
        {"role": "user", "content": "Hello, how are you?"}
      ],
    }
    ```
  </Accordion>
</ParamField>

<ParamField body="model" type="string" required>
  Speciy the model you want to use in this version.
</ParamField>

<ParamField body="description" type="string">
  Description of the prompt version
</ParamField>

<ParamField body="stream" type="boolean">
  Whether the prompt version should be streamed or not. Default is `false`.
</ParamField>

<ParamField body="temperature" type="float">
  The temperature of the model.
</ParamField>

<ParamField body="max_tokens" type="integer">
  The maximum number of tokens to generate.
</ParamField>

<ParamField body="top_p" type="float">
  The nucleus sampling probability.
</ParamField>

<ParamField body="frequency_penalty" type="float">
  Specify how much to penalize new tokens based on their existing frequency in the text so far. Decreases the model's likelihood of repeating the same line verbatim
</ParamField>

<ParamField body="presence_penalty" type="float">
  Specify how much to penalize new tokens based on whether they appear in the text so far. Increases the model's likelihood of talking about new topics
</ParamField>

<ParamField body="variables" type="object">
  The list of variables for the prompt version. You can use these variables in the messages.

  <Accordion title="Example">
    ```json theme={"system"}
    {
      "variables": {
        "role": ["assistant", "teacher", "student"]
      }
    }
    ```
  </Accordion>
</ParamField>

<ParamField body="fallback_models" type="array">
  The list of fallback models for the prompt version. Check out [fallback models](/documentation/products/gateway/traffic_management/fallbacks) for more information.

  <Accordion title="Example">
    ```json theme={"system"}
    {
      "fallback_models": ["gpt-4o", "gpt-4o-mini"]
    }
    ```
  </Accordion>
</ParamField>

<ParamField body="load_balance_models" type="array">
  The list of models to load balance the prompt version. Check out [load balancing](/documentation/products/gateway/traffic_management/load-balancing) for more information.

  <Accordion title="Example">
    ```json theme={"system"}
    {
    "load_balance_models": [
        {"model": "gpt-4o", "weight": 0.7},
        {"model": "gpt-4o-mini", "weight": 0.3}
      ],
    }
    ```
  </Accordion>
</ParamField>

<ParamField body="tools" type="array">
  The list of tools to use for the prompt version. Check out [function calling](/documentation/products/gateway/advanced_features/function_calling) for more information.

  <Accordion title="Example">
    ```json theme={"system"}
    {
    "tools": [
        {
          "type": "function",
          "function": {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "parameters": {
              "type": "object",
              "properties": {
                "location": {
                  "type": "string",
                  "description": "The city and state, e.g. San Francisco, CA"
                }
              },
              "required": ["location"]
            }
          }
        }
      ],
    }
    ```
  </Accordion>
</ParamField>

<ParamField body="deploy" type="boolean">
  Whether to deploy this version as the live version Default is `false`.
</ParamField>

<RequestExample>
  ```Python Python theme={"system"}
  import requests

  url = "https://api.keywordsai.co/api/prompts/<prompt_id>/versions/"
  api_key = "YOUR_KEYWORDS_AI_API_KEY" # Replace with your actual Keywords AI API key
  data = {
  "description": "A description of the prompt version",
    "messages": [
      {"role": "system", "content": "You are a helpful {{role}}."},
      {"role": "user", "content": "Hello, how are you?"}
    ],
    "model": "gpt-3.5-turbo",
    "stream": false,
    "temperature": 0.7,
    "max_tokens": 256,
    "top_p": 1.0,
    "frequency_penalty": 0.0,
    "presence_penalty": 0.0,
    "variables": {},
    "fallback_models": ["gpt-3.5-turbo-16k", "gpt-4"],
    "load_balance_models": [
      {"model": "gpt-3.5-turbo", "weight": 0.7},
      {"model": "gpt-4", "weight": 0.3}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the current weather in a given location",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA"
              }
            },
            "required": ["location"]
          }
        }
      }
    ],
    "deploy": True
  }
  headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json"
  }

  response = requests.post(url, headers=headers, json=data)
  print(response.json())
  ```

  ```TypeScript TypeScript theme={"system"}
  // Define the function with TypeScript

  fetch('https://api.keywordsai.co/api/prompts/<prompt_id>/versions/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_KEYWORDS_AI_API_KEY'
      },
      body: JSON.stringify({
          description: "A description of the prompt version",
          messages: [
              {"role": "system", "content": "You are a helpful {{role}}."},
              {"role": "user", "content": "Hello, how are you?"}
          ],
          model: "gpt-3.5-turbo",
          stream: false,
          temperature: 0.7,
          max_tokens: 256,
          top_p: 1.0,
          frequency_penalty: 0.0,
          presence_penalty: 0.0,
          variables: {},
          fallback_models: ["gpt-3.5-turbo-16k", "gpt-4"],
          load_balance_models: [
              {"model": "gpt-3.5-turbo", "weight": 0.7},
              {"model": "gpt-4", "weight": 0.3}
          ],
          tools: [
              {
                  "type": "function",
                  "function": {
                      "name": "get_weather",
                      "description": "Get the current weather in a given location",
                      "parameters": {
                          "type": "object",
                          "properties": {
                              "location": {
                                  "type": "string",
                                  "description": "The city and state, e.g. San Francisco, CA"
                              }
                          },
                          "required": ["location"]
                      }
                  }
              }
          ],
          deploy: true
      })
  })
  .then(response => response.json())
  .then(data => console.log(data));
  ```
</RequestExample>
