Run a prompt
/v1/prompts/{slug}/completionsRun a prompt.
Renders a version of the prompt with the given variables and sends it to the model as a chat completion, with the version's model (or model_override), temperature, max_tokens, top_p and stop. The answer is a chat completion, as from POST /v1/chat/completions; with stream: true it is a stream of server-sent events, each a chat.completion.chunk, ending with data: [DONE]. The request is logged and billed like any chat completion on the key, and attributed to the prompt and version for its analytics.
Authenticate with a virtual key (Authorization: Bearer <api_key> or x-virtual-key); the prompt is looked up in the key's organization. A key bound to a workspace runs that workspace's prompts and the organization-level ones; another workspace's prompt is a 404. The response cache, guardrails and routing configs apply through their headers; the x-retry-* and x-fallback-* headers are not read. Response headers: x-cache-status, x-retry-count, x-virtual-key-slug, x-fallback-provider when a fallback answered, and x-guardrail-status when a guardrail applied.
Errors: 400 for an invalid version_ref, or when the version has no model and no model_override is given; 401 for a missing or invalid virtual key; 404 when the prompt, version or label does not exist, or the prompt has no default version and none is named; 422 when a guardrail blocks the request (x-guardrail-status: BLOCK). Provider errors are returned as on /v1/chat/completions.
Authorization
AuthorizationBearer <slug>.<secret>A virtual key's API key (
vk-....<secret>), asAuthorization: Bearer. What the OpenAI SDK sends from itsapi_key. Used by the inference endpoints.- or
x-virtual-keyheaderA virtual key's API key in the
x-virtual-keyheader, for clients that keepAuthorizationfor something else. - or
x-api-keyheaderDirect credentials: the provider's own API key in
x-api-key, with the provider named inx-provider(for exampleopenai). On/v1/messagesa virtual key is accepted inx-api-keytoo, which is what the Claude SDK sends.
Path parameters
slugstringrequiredthe prompt's slug
Headers
x-cache-modestringTurns on the response cache for this request:
simple(exact match) orsemantic(a similar earlier request). Without it nothing is read from or written to the cache. The outcome is in thex-cache-statusresponse header.x-cache-ttlinteger<int32>How long, in seconds, a response stored by this request stays in the cache. When the organization has a cache TTL set, this can shorten it but not extend it.
x-cache-force-refreshbooleantrueskips the cache lookup, calls the provider and replaces the stored response (x-cache-status: REFRESH).x-guardrailstringA guardrail slug (
gr-...) to apply to this request, in addition to any the virtual key carries. A BLOCK is a 422 withx-guardrail-status: BLOCK.x-configstringA routing config slug: the config chooses the provider, model and key (load balancing, fallback or conditional routing). Without a virtual key, send
x-organizationwith it to name the config's organization.
Request body application/json
the variables, the version and the streaming option
variablesmap<string, string>requiredValues for the template's
{{name}} placeholders, as a JSON object of strings. A placeholder with no value is sent to the model as written.version_refstringWhich version to use: a version number (for example
3),latest(the highest version number, whatever its status) or@followed by a label (for example@staging). Omit it for the default version: the one theproductionlabel points at, else the PUBLISHED version. An unknown version or label is a 404, any other value a 400.streambooleantruestreams the answer as server-sent events. Defaultfalse.model_overridestringA model to use instead of the version's
model. Required when the version has no model (400 otherwise).
Responses
The model's answer, as a chat completion or, with stream: true, a stream of chat completion chunks.
idstringThe completion's id, as the provider assigned it.
objectstringThe object type,
chat.completion.createdinteger<int64>When the completion was created, in Unix seconds.
modelstringThe model that produced the answer, as the provider reports it (it may carry a version suffix).
choicesobject[]The answers, one per requested choice (
n, default 1).Child attributes
indexinteger<int32>The choice's position in
choices, from 0.messageobjectOne message of a conversation, in OpenAI's format: in a request, a turn of the conversation so far; in a response, the model's answer.
Child attributes
roleenum<string>requiredWho wrote the message:
system(instructions),user,assistant(the model) ortool(a tool call's result). Required.One of
"system","user","assistant","tool"contentobjectThe message's content: a string, or an array of content parts (
text,image_url,input_audio,file), each an object with atype. Any other shape is a 400 naming the message. May be null on an assistant message that only calls tools.namestringAn optional name for the author, to tell participants with the same role apart.
tool_callsobject[]On an assistant message: the tool calls the model made. Empty when it made none.
Child attributes
idstringThe tool call id, sent back as
tool_call_idon thetoolmessage with the result.typestringAlways
function.functionobjectThe function a tool call invokes: its name and the arguments the model chose.
Child attributes
namestringThe name of the function the model calls.
argumentsstringThe arguments, as a JSON string the model generated. Validate it before use: the model may produce invalid JSON or arguments the schema does not allow.
tool_call_idstringOn a
toolmessage: the id of the tool call this message answers.thinking_blocksmap<string, object>[]Claude models with extended thinking: the assistant turn's reasoning blocks,
{"type":"thinking","thinking":"...","signature":"..."} or{"type":"redacted_thinking","data":"..."}, each with apositionamong the message's other blocks. Send them back unchanged on the next request: Anthropic checks the signature and treats a dropped, edited or reordered block as an edited history. Absent when there are none.is_errorbooleanOn a
toolmessage:truewhen the tool call failed. Sent to Claude models as the tool result's error flag. Absent otherwise.
finish_reasonenum<string>Why the model stopped:
stop(a natural end or a stop sequence),length(the token limit),tool_callsorcontent_filter.One of
"stop","length","content_filter","tool_calls"stop_sequencestringThe stop sequence that ended the turn, when one did (Anthropic's
stop_sequence). OpenAI'sfinish_reasonreports a stop sequence and a natural end alike asstop, so this is what lets/v1/messagesanswerstop_reason: stop_sequence. Set only by the Anthropic adapters; omitted from the body otherwise.
usageobjectThe tokens a request used, in OpenAI's format.
prompt_tokenscounts every input token, including those read from or written to the provider's prompt cache.Child attributes
prompt_tokensinteger<int32>Input tokens, cached or not.
completion_tokensinteger<int32>Output tokens the model generated.
total_tokensinteger<int32>prompt_tokenspluscompletion_tokens.prompt_tokens_detailsobjectOpenAI's
usage.prompt_tokens_details. Onlycached_tokensis carried: the input tokens read from the provider's prompt cache (OpenAI's automatic caching, Anthropic'scache_read_input_tokens). Other fields OpenAI adds (audio_tokens) are ignored.Child attributes
cached_tokensinteger<int32>Input tokens read from the provider's prompt cache.
cache_creation_input_tokensinteger<int32>Input tokens written to the provider's prompt cache (Claude), part of
prompt_tokens. Absent when none were reported.cache_creation_1h_input_tokensinteger<int32>Of
cache_creation_input_tokens, those written with the 1-hour cache lifetime, which costs more than the 5-minute one. Absent when none were reported.