API reference · Chat
Create a chat completion
POSThttps://api.useunbound.ai/v1/chat/completions
Generates a model response for a conversation. With stream: true the response is a server-sent event stream of chat.completion.chunk objects ending in data: [DONE]. Before the request is sent upstream, enough credit is held to cover the prompt plus max_tokens of output; the real usage is charged when it finishes. Closing the connection early stops generation and you are charged only for what was produced.
Headers
AuthorizationrequiredBearer <key>, with a key from Settings → API.
Body
application/json
modelrequiredAn id from
GET /v1/models.messagesrequiredThe conversation so far. Must not be empty.
rolerequireddeveloperis treated assystem.contentText, or an array of content parts.
nametool_callsTool calls made by the assistant in an earlier turn.
tool_call_idFor
toolmessages: the call this message answers.
streamSend the response as server-sent events.
stream_optionsStreaming options.
include_usageAdd a final chunk carrying token usage.
max_tokensCaps the output and the amount of credit held. Also accepted as
max_completion_tokens.temperatureSampling temperature.
top_pNucleus sampling.
stopOne or more sequences where generation stops. Forwarded when the model supports it.
seedForwarded when the model supports it.
toolsFunction definitions, for models that support tools.
tool_choiceHow the model may use tools.
response_formatJSON mode or a JSON schema, for models that support it.
reasoning_effortFor reasoning models.
Response
A chat completion, or an event stream when stream is true.
idrequiredobjectrequiredcreatedrequiredmodelrequiredchoicesrequiredindexmessagerolecontentreasoning_contentPresent when the model returned reasoning text.
tool_calls
finish_reasonWhy generation ended, for example
stop,lengthortool_calls.
usagerequiredprompt_tokenscompletion_tokenstotal_tokensprompt_tokens_detailscached_tokens
completion_tokens_detailsreasoning_tokens
Errors
- 400The request is malformed, or a parameter is not supported by the model.
- 401The API key is missing, revoked or expired.
- 402Not enough credit, or the key reached its spending limit. Nothing was charged.
- 403The key does not have the scope this endpoint needs.
- 404The model does not exist or is not available through the API.
- 413The request body is larger than 4 MB.
- 429Too many requests for this key. Retry after the number of seconds in the Retry-After header.
- 502The upstream provider failed. The hold was released; you were not charged.
All errors use the envelope described in the introduction. None of them result in a charge.