Completions
Create a chat completion
The OpenAI Chat Completions format. With "stream": true the answer arrives as Server-Sent Events (data: {...} lines that end with data: [DONE]).
/ v1 / chat / completionsAuthorizations
AuthorizationstringheaderrequiredBearer authentication header of the form Bearer <token>, where <token> is your API key.
Body
application/jsonmodelstringrequiredA Libremodel model ID, from Models or
GET /v1/models.messagesobject[]requiredThe conversation, oldest first.
Show child attributesHide child attributes
rolestringrequiredWho says it.
Allowed values:
"system""user""assistant""tool"contentstring | object[]requiredText, or a list of parts:
text,image_url(Vision) andfile(Files).tool_callsobject[]In an
assistantmessage: the calls it made. Send them back as they came.tool_call_idstringIn a
toolmessage: the call it answers.
max_completion_tokensintegerCap on output tokens, reasoning included.
max_tokensalso works; if you send both, this one wins. See Output limit.streambooleandefault: falseSend the answer as Server-Sent Events, as it is generated. See Streaming.
stream_optionsobjectWith
stream,{"include_usage": true}adds a last chunk with the token count and the cost.reasoning_effortstringHow much the model thinks before answering. Each model has its own levels and default: see Reasoning.
Allowed values:
"low""high""max""off"toolsobject[]Functions the model can call. See Tool calling.
tool_choicestring | objectauto,none,required, or one function.requiredand a function are only always followed on models that listtool_choiceinsupported_parameters.temperaturenumberSampling temperature.
top_pnumberNucleus sampling.
stopstring | string[]Text that ends the answer.
Response
The answer. With stream, a text/event-stream instead.
idstringrequiredThe ID of the answer.
Example:
"chatcmpl-01a22df8502973a9957575e4c07311be"objectstringrequiredAlways
"chat.completion".createdintegerrequiredUnix time, in seconds.
modelstringrequiredThe model you asked for.
choicesobject[]requiredOne answer.
Show child attributesHide child attributes
messageobjectrequiredrole,content, andreasoning_contentandtool_callswhen there are any.finish_reasonstringrequiredWhy it stopped.
Allowed values:
"stop""length""tool_calls"
usageobjectrequiredTokens and cost.
Show child attributesHide child attributes
prompt_tokensintegerrequiredInput tokens, cached ones included.
completion_tokensintegerrequiredOutput tokens, reasoning included.
prompt_tokens_detailsobjectrequiredcached_tokens: input read from cache, billed at the cached price.completion_tokens_detailsobjectrequiredreasoning_tokens: the part of the output spent thinking.costnumberrequiredWhat the request cost, in dollars.
Example:
0.0001605
The body is not valid: a required field is missing or one has the wrong type.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
The key is missing, wrong, revoked or expired.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
The balance does not cover the request.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
The key is valid but cannot do this: the model is not among the ones the key allows, its spending limit is reached or the account is suspended.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
The model ID does not exist. The valid ones come from GET /v1/models.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
Too many requests at once. Wait for the seconds in the Retry-After header and retry.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.
Temporarily unavailable. Retry after a short wait.
errorobjectrequiredThe error.
Show child attributesHide child attributes
messagestringrequiredWhat went wrong, for a person to read.
typestringrequiredThe error family, as in the OpenAI API.
Example:
"authentication_error"codestringrequiredThe exact cause. Branch on this one. All codes: Limits and errors.
Example:
"invalid_api_key"paramnullrequiredAlways
null.