POST /openai/v1/chat/completions. The model returns the next assistant message.
Messages and roles
messages is the conversation so far, oldest first. Each message has a role and content.
content is a string, or an array of text parts that are joined in order:
Message
Multi-turn conversations
The API is stateless: it doesn’t keep a conversation between requests, so each request must include the full history you want the model to see. To continue a conversation, append the assistant’s reply and the next user message, then send the whole list again. Send each assistant message back with itsreasoning_content, which assistant messages require by default; see Reasoning.
Python
400 error with code context_length_exceeded.
Control generation
Upper bound on generated tokens, including reasoning tokens. The prompt plus this value must fit within the model’s context window, or the request returns a
400 error with code context_length_exceeded. Replaces the deprecated max_tokens; don’t set both. When you set neither, the model’s default output budget applies, without being reduced to fit the prompt, so send your own limit with a long prompt. Your plan’s per-request output limit applies if it’s lower.From
-2 to 2. Penalizes a token for each time it has already appeared. Positive values make verbatim repetition less likely; negative values make it more likely.From
-2 to 2. Penalizes a token that has already appeared at least once. Positive values steer the model toward new words and topics; negative values keep it on them.How much the model reasons before answering. See Reasoning.
temperature of 0.7 and a top_p of 0.99.
When a request omits temperature, top_p, frequency_penalty, presence_penalty, or the output limit, or sets it to null, the model’s default for that parameter applies, if it lists one.
stop and seed are accepted but have no effect: generation doesn’t stop at stop sequences, and sampling isn’t seeded. See OpenAI compatibility.
See Create a chat completion for every parameter.
Read the response
The reply is inchoices[0].message. Always check finish_reason to see why generation ended:
usage reports the tokens used by the request:
Usage
prompt_tokens_details can be omitted when no prompt tokens were cached.
Next steps
- Stream the response to show it as it is generated.
- Adjust reasoning to trade answer quality for latency.
- Get structured output when your code needs to parse the reply.