Skip to content
Browse the docs

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

  • Authorizationstringrequired

    Bearer <key>, with a key from Settings → API.

Body

application/json

  • modelstringrequired

    An id from GET /v1/models.

  • messagesobject[]required

    The conversation so far. Must not be empty.

    • rolestringrequired

      developer is treated as system.

      One ofsystemdeveloperuserassistanttool

    • contentstring | object[] | null

      Text, or an array of content parts.

    • namestring

    • tool_callsobject[]

      Tool calls made by the assistant in an earlier turn.

    • tool_call_idstring

      For tool messages: the call this message answers.

  • streambooleandefault false

    Send the response as server-sent events.

  • stream_optionsobject

    Streaming options.

    • include_usageboolean

      Add a final chunk carrying token usage.

  • max_tokensinteger

    Caps the output and the amount of credit held. Also accepted as max_completion_tokens.

    Minimum 1

  • temperaturenumber

    Sampling temperature.

    Minimum 0 · Maximum 2

  • top_pnumber

    Nucleus sampling.

    Minimum 0 · Maximum 1

  • stopstring | string[]

    One or more sequences where generation stops. Forwarded when the model supports it.

  • seedinteger

    Forwarded when the model supports it.

  • toolsobject[]

    Function definitions, for models that support tools.

  • tool_choicestring | object

    How the model may use tools.

  • response_formatobject

    JSON mode or a JSON schema, for models that support it.

  • reasoning_effortstring

    For reasoning models.

    One ofminimallowmediumhigh

Response

A chat completion, or an event stream when stream is true.

  • idstringrequired

  • objectstringrequired

    One ofchat.completion

  • createdintegerrequired

  • modelstringrequired

  • choicesobject[]required

    • indexinteger

    • messageobject

      • rolestring

        One ofassistant

      • contentstring | null

      • reasoning_contentstring

        Present when the model returned reasoning text.

      • tool_callsobject[]

    • finish_reasonstring

      Why generation ended, for example stop, length or tool_calls.

  • usageobjectrequired

    • prompt_tokensinteger

    • completion_tokensinteger

    • total_tokensinteger

    • prompt_tokens_detailsobject

      • cached_tokensinteger

    • completion_tokens_detailsobject

      • reasoning_tokensinteger

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.