/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
The ID of the model to use. Call
GET /v1/models to retrieve the list of models available to your account.An ordered array of message objects that make up the conversation history. Each object must include a
role and content.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.
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.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.When
true, the API streams partial message deltas as server-sent events (SSE) and sends a final [DONE] message. Defaults to false.One or more sequences at which the model stops generating further tokens. Pass a single string or an array of up to four strings.
A list of tool definitions the model may call during generation. Each tool must conform to the JSON Schema function definition format.
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
An array of generated response objects. Contains one element unless you request multiple completions.