Skip to main content
The /v1/chat/completions endpoint accepts a conversation history as an ordered list of messages and returns a model-generated response. Use it to build chatbots, virtual assistants, multi-turn reasoning flows, or any application where you need a model to respond in context.

Endpoint

Request Parameters

string
required
The ID of the model to use. Call GET /v1/models to retrieve the list of models available to your account.
array
required
An ordered array of message objects that make up the conversation history. Each object must include a role and content.
integer
The maximum number of tokens to generate in the response. When omitted, the model uses its default context limit. Setting this value helps control costs and response length.
number
Sampling temperature between 0 and 2. Higher values (e.g., 1.4) produce more varied and creative output; lower values (e.g., 0.2) produce more deterministic output. Defaults to 1. Avoid setting both temperature and top_p at the same time.
number
Nucleus sampling threshold between 0 and 1. The model considers only the smallest set of tokens whose cumulative probability exceeds top_p. Defaults to 1. Avoid setting both top_p and temperature at the same time.
boolean
When true, the API streams partial message deltas as server-sent events (SSE) and sends a final [DONE] message. Defaults to false.
string | array
One or more sequences at which the model stops generating further tokens. Pass a single string or an array of up to four strings.
array
A list of tool definitions the model may call during generation. Each tool must conform to the JSON Schema function definition format.
string | object
Controls which tool (if any) the model calls. Pass "none" to disable tool calls, "auto" to let the model decide, or an object {"type": "function", "function": {"name": "your_function"}} to force a specific tool.

Request Examples

Response Fields

string
A unique identifier for this completion, prefixed with chatcmpl-.
string
Always "chat.completion".
integer
Unix timestamp (seconds) of when the completion was created.
string
The model ID that was used to generate this response.
array
An array of generated response objects. Contains one element unless you request multiple completions.
object
Token usage statistics for the request.

Example Response