Skip to navigation

Create a chat completion

Sends a conversation to a chat model and returns its reply. Set stream: true to receive server-sent events; the last chunk before [DONE] carries usage.

Authentication

AuthorizationBearer

Your API key, sk-..., from Console → API keys.

Request

This endpoint expects an object.
modelstringRequired

The model id, lab/model.

messageslist of objectsRequired
The conversation so far.
streambooleanOptionalDefaults to false

Send the reply as server-sent events.

stream_optionsobjectOptional
Streaming options. Usage is always sent at the end of a stream.
max_tokensintegerOptional>=1
The most output tokens to produce. Keeps the hold on your balance small.
max_completion_tokensintegerOptional>=1

Same as max_tokens, including reasoning tokens.

temperaturedoubleOptional0-2
top_pdoubleOptional0-1
frequency_penaltydoubleOptional-2-2
presence_penaltydoubleOptional-2-2
stopstring or list of stringsOptional
Up to 4 sequences where the model stops.
seedintegerOptional
nintegerOptional1-8Defaults to 1
How many replies to make. Each is held for its full output.
logprobsbooleanOptional
top_logprobsintegerOptional0-20
logit_biasmap from strings to doublesOptional
toolslist of objectsOptional

Functions the model may call. Only function tools are kept.

tool_choiceenum or objectOptional

auto, none, required, or a specific function.

parallel_tool_callsbooleanOptional
response_formatobjectOptional

{"type": "json_object"} or {"type": "json_schema", "json_schema": {...}}.

reasoning_effortenumOptional
How much a reasoning model thinks, on models that support it.
Allowed values:
userstringOptional
Your own id for the end user.
metadatamap from strings to stringsOptional

Response

The model’s reply, or a stream of chunks when stream is true.

idstringOptional
objectenumOptional
Allowed values:
createdintegerOptional
modelstringOptional
choiceslist of objectsOptional
usageobjectOptional

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
429
Too Many Requests Error
502
Bad Gateway Error
503
Service Unavailable Error