Skip to main content
After you create a prompt, you can deploy it to your codebase and call it through the API. Keywords AI provides two powerful override modes to give you complete control over your prompts.

Find the prompt ID

You should first find the Prompt ID of the prompt you want to deploy. You can find the Prompt ID in the Overview panel on the Prompts page.
Prompt ID

Connect the prompt to codebase

from openai import OpenAI

client = OpenAI(
  base_url="https://api.keywordsai.co/api/", # switch to the Keywords AI base URL
  api_key="YOUR_API_KEY", # switch to your Keywords AI API key
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Tell me a long story"}
    ],
    extra_body={"prompt": {"prompt_id":"042f5f",
                "variables":{"task_description":"Square a number", "specific_library":"math"},
                "override": True,
                }
    }
)
Mode 1: Prompt Overrides OpenAI Parameters
Setting override: True tells Keywords AI to ignore the model and messages fields in your request and use the configuration from your saved prompt instead.

Use specific prompt version

You can pin a prompt version for reproducibility and testing.
  • Omit version to use the deployed live version.
  • Set version to a specific number (e.g., 3) to pin that version.
{
    "prompt": {
        "prompt_id": YOUR_PROMPT_ID,
        "version": 3,
    }
}
You can also use the reserved keyword "version": "latest" to use the most recent draft version (not deployed). This is useful for testing changes before deployment.

Override prompt configuration (optional)

You can dynamically override your saved prompt settings using override_params and override_config. This gives you runtime flexibility while keeping your base prompt template intact.

Override prompt messages

request_body = {
    "prompt": {
        "prompt_id": "042f5f",
        "override_config": {"messages_override_mode": "append"},
        "override_params": {"messages": [{"role": "user", "content": "Additional context"}]},
    }
}
This adds the new message to the end of your existing prompt messages.

Override other parameters

You can override any OpenAI parameter in your prompt:
request_body = {
    "prompt": {
        "prompt_id": "042f5f",
        "override_params": {
            "temperature": 0.8,      # Override temperature
            "max_tokens": 150,       # Override token limit
            "model": "gpt-4o"         # Override model
        }
    }
}

View the logs with the prompt

You can view the logs with the prompt by clicking a log on the Logs page or filtering the logs with the prompt name.
View prompt

Parameters Reference

prompt_id
string
required
The unique identifier of your saved prompt template.
variables
object
Variables to inject into your prompt template.
{
  "variables": {
    "user_name": "John",
    "task": "summarize"
  }
}
override
boolean
default:false
Mode 1: When true, your prompt configuration overrides OpenAI SDK parameters like model and messages.
{
  "override": true
}
override_params
object
Mode 2: Parameters that override your saved prompt configuration.
{
  "override_params": {
    "temperature": 0.5,
    "max_tokens": 100,
    "messages": [{"role": "user", "content": "New message"}]
  }
}
override_config
object
Mode 2: Controls how override parameters are applied.
  • append: Add new messages to existing prompt messages
  • override: Replace all existing messages with new ones
echo
boolean
default:false
When enabled, the response includes the final prompt messages used.
{
  "echo": true
}

Troubleshooting

Enable stream when you’re using OpenAI SDK

If you’re using OpenAI SDK and want to connect with the prompt you created, you have to specify stream=True in the call body.
from openai import OpenAI

client = OpenAI(
    base_url="https://api.keywordsai.co/api/",
    api_key="YOUR_KEYWORDSAI_API_KEY",
)

response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role":"user", "content":"Tell me a long story"}],
    stream=True,
    extra_body={
      "prompt": {
          "prompt_id": "prompt_id", # paste this from the prompt management page
          "variables": {
            "variable_name": "variable_value"
          },
          # "echo": true //optional parameter
        }
    }
)