Skip to main content
To generate text, send a conversation to 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
Only text input is supported.

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 its reasoning_content, which assistant messages require by default; see Reasoning.
Python
Longer histories use more input tokens, which count toward rate limits and usage. The API doesn’t truncate a history that’s too long: a request longer than the model accepts returns a 400 error with code context_length_exceeded.

Control generation

integer
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.
number
Sampling randomness from 0 to 2. Lower values are more focused and repeatable.
number
Nucleus sampling, from 0 to 1.
number
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.
number
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.
string
How much the model reasons before answering. See Reasoning.
Beam’s recommended settings are a 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 in choices[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

Last modified on November 18, 2026