Deploy a prompt to your codebase and understand override modes.
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.
from openai import OpenAIclient = 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.
In OpenAI TypeScript SDK, you should add a // @ts-expect-error before the prompt field.
Copy
import { OpenAI } from "openai";const client = new OpenAI({ baseURL: "https://api.keywordsai.co/api", apiKey: "YOUR_KEYWORDSAI_API_KEY",});const response = await client.chat.completions .create({ messages: [{ role: "user", content: "Say this is a test" }], model: "gpt-4o-mini", // @ts-expect-error prompt: { prompt_id: "042f5f", variables: { task_description: "Square a number", specific_library: "math" }, override: true, } }) .asResponse();console.log(await response.json());
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.
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.
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.