> ## 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 a prompt via API

> A guide on how to create and versiona prompt in Keywords AI.

In this guide, we will walk you through the process of creating a new prompt in Keywords AI and how to collaborate with your team.

## Create a prompt in the API

You can also create a prompt in the API. Here are the 2 endpoints you need to use to create a prompt:

1. `https://api.keywordsai.co/api/prompts/` - Create a new prompt.
2. `https://api.keywordsai.co/api/prompts/<prompt_id>/versions/` - Create a new version of a prompt.

### 1. Create a new prompt

You can use the `POST /prompts/` endpoint to create a new prompt. You need to provide the name, and description of the prompt.

<CodeGroup>
  ```python Python {6-7} theme={"system"}
  import requests

  url = "https://api.keywordsai.co/api/prompts/"
  api_key = "YOUR_KEYWORDS_AI_API_KEY" # Replace with your actual Keywords AI API key
  data = {
      "name": "Your Prompt Name",
      "description": "Your Prompt Description"
  }
  headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json"
  }

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

  ```TypeScript TypeScript {8-9} theme={"system"}
  fetch('https://api.keywordsai.co/api/prompts/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_KEYWORDS_AI_API_KEY'
      },
      body: JSON.stringify({
          name: "Your Prompt Name",
          description: "Your Prompt Description"
      })
  })
  .then(response => response.json())
  .then(data => console.log(data));
  ```
</CodeGroup>

### 2. Find the prompt ID

Once you have created a prompt, you can find the prompt ID in the response, or you can go to the [Prompts page](https://platform.keywordsai.co/platform/prompts) and find the prompt ID in the prompt details.

### 3. Create a new version of the prompt

You can use the `POST /api/prompts/<prompt_id>/versions/` endpoint to create a new version of a prompt. You need to provide the content of the prompt.

<CodeGroup>
  ```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": {},
  }
  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"}
  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: {},
      })
  })
  .then(response => response.json())
  .then(data => console.log(data));
  ```
</CodeGroup>

You just finished creating your first prompt in the code!
