Chat completions
Every field a chat call takes and returns, streamed or not.
Create a chat completion
/v1/projects/{project}/chat/completionsNeeds Call models. The request and answer have the same shape as OpenAI’s Chat Completions.
{
"model": "openai/gpt-oss-120b",
"messages": [
{ "role": "system", "content": "Answer in one short paragraph." },
{ "role": "user", "content": "Habari? Tell me about Zanzibar." }
],
"max_tokens": 500
}Request
modelstringA model’s name, such as
openai/gpt-oss-120b. See Models.fallbacksarray1 to 3 other models to try, in order, when
modelcannot answer right now, such as["openai/gpt-oss-20b"]. Each is checked against the request before it is sent: a fallback that does not take the tools, images,max_tokens, or other settings you sent is refused withvalidation_failed. A request the model refuses as invalid is not tried on the others. A stream falls back only before its first chunk. The answer’smodelnames the model that answered, and its AI units are that model’s.messagesarrayThe conversation, 1 to 1,000 messages. Each has a
role:system,developer,user,assistant, ortool. Itscontentis a string, or a list oftextandimage_urlparts. Only user messages can hold images; see Send images. An assistant message can holdtool_calls, and atoolmessage needs thetool_call_idit answers; see Call tools.max_tokensintegerThe most tokens the answer may have, from 1 to the model’s most output. Without it, the model’s default output applies, not its most.
max_completion_tokensis taken as the same thing.temperaturenumber0 to 2. Higher is more varied.
top_pnumber0 to 1.
presence_penaltynumber-2 to 2.
frequency_penaltynumber-2 to 2.
stopstring or arrayUp to 4 sequences that end the answer.
seedintegerAsk for the same answer to the same request, where the model can.
nintegerOnly 1. One answer is returned.
response_formatobjectAsk for JSON:
{"type": "json_object"}for any object, or{"type": "json_schema", "json_schema": {"name": "...", "schema": {...}}}for one that matches your JSON schema, which needs"type": "object"at its top. The answer is always JSON that matches. When the model cannot give one, the call fails withanswer_invalid, or withanswer_cut_offwhen it reachedmax_tokensfirst. A call that does not stream gets a second try, and both count toward your AI units.toolsarrayFunctions the model may ask your code to run. Only for models marked for tools.
tool_choicestring or objectWhether the model must, may, or may not call a tool. Needs
tools.parallel_tool_callsbooleanWhether the model may ask for several tools at once.
promptobjectA stored prompt to put first in the conversation, as its system message:
id(its name),version(to pin one; without it, the newest), andvariables(a string for each{{name}}in it). See Use stored prompts.reasoning_effortstringHow much a reasoning model thinks before it answers:
low,medium(its default), orhigh. More thinking uses more output tokens. Only for models marked for reasoning in Models.streambooleanSend the answer as server-sent events as it is written. See Stream answers.
stream_options.include_usagebooleanWith
stream, end with a chunk that holdsusage.userstringYour own ID for the person using your app, up to 256 characters. It is never sent to the model.
Answer
{
"id": "chatcmpl-a1b2c3",
"object": "chat.completion",
"created": 1790000000,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Zanzibar is an island…" },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 1000,
"completion_tokens": 500,
"total_tokens": 1500,
"units": 60
}
}modelstringThe model that answered, by the name you sent:
model, or one of itsfallbacks.choices[0].message.contentstringThe answer. Empty when the model wants a tool instead.
choices[0].message.reasoningstringWhat a reasoning model thought before it answered, kept apart from
content. Left out when the model did not reason. In a stream, it arrives indelta.reasoning.choices[0].message.tool_callsarrayThe tools the model wants run, each with an
id,typefunction, andfunctionwith itsnameandargumentsas a JSON string. See Call tools.choices[0].finish_reasonstringWhy it stopped:
stopwhen it finished,lengthwhen it reachedmax_tokens,tool_callswhen it wants a tool,content_filterwhen it would not answer.usage.prompt_tokensintegerThe tokens the model read.
usage.completion_tokensintegerThe tokens the model wrote.
usage.unitsintegerThe AI units the call used. See AI units.
Headers
| Header | Holds |
|---|---|
X-Request-Id | The call’s ID. Quote it when you contact us. |
X-Ai-Processed-In | The country where the model ran, such as Germany or United States. |
Retry-After | On 429 and 503, the seconds to wait before sending again. |
A call can take up to 10 minutes.
Last updated