Creates a model response for a chat conversation. Supply model and at least one item in messages; set stream to receive server-sent events instead of a single response object. The response contains completion choices and usage information when available.
IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.
37 body fields
Chat completion request containing a model and conversation messages, with optional generation, output, and tool configuration.
metadataobjectoptional
Optional metadata associated with the completion request.
top_logprobsintegeroptional
An integer between 0 and 20 specifying the maximum number of most likely
tokens to return at each token position, each with an associated log
probability. In some cases, the number of returned tokens may be fewer than
requested.
`logprobs` must be set to `true` if this parameter is used.
temperaturenumberoptional
Controls the randomness of the generated response.
Default:1
top_pnumberoptional
Controls token selection using nucleus sampling.
Default:1
userstringdeprecatedoptional
This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching optimizations.
A stable identifier for your end-users.
Used to boost cache hit rates by better bucketing similar requests and to help OpenAI detect and prevent abuse. [Learn more](https://developers.openai.com/api/docs/guides/safety-best-practices#implement-safety-identifiers).
safety_identifierstringoptional
An identifier used to help apply safety controls to the request.
prompt_cache_keystringoptional
A key used to group requests for prompt caching.
prompt_cache_retentionstringdeprecatedoptional
The prompt cache retention setting for the request.
Allowed:in_memory24h
prompt_cache_optionsobjectoptional
Options for prompt caching. Supported for `gpt-5.6` and later models. By default, OpenAI automatically chooses one implicit cache breakpoint. You can add explicit breakpoints to content blocks with `prompt_cache_breakpoint`. Each request can write up to four breakpoints. For cache matching, OpenAI considers up to the latest 80 breakpoints in the conversation, without a content-block lookback limit. Set `mode` to `explicit` to disable the implicit breakpoint. The `ttl` defaults to `30m`, which is currently the only supported value. See the [prompt caching guide](https://developers.openai.com/api/docs/guides/prompt-caching) for current details.
messagesarray<DeveloperMessage>required
A list of messages comprising the conversation so far. Depending on the
[model](https://developers.openai.com/api/docs/models) you use, different message types (modalities) are
supported, like [text](https://developers.openai.com/api/docs/guides/text),
[images](https://developers.openai.com/api/docs/guides/images-vision), and [audio](https://developers.openai.com/api/docs/guides/audio).
modelstringrequired
Model ID used to generate the response, like `gpt-6-astra` or `o3`. OpenAI
offers a wide range of models with different capabilities, performance
characteristics, and price points. Refer to the [model guide](https://developers.openai.com/api/docs/models)
to browse and compare available models.
An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and [reasoning tokens](https://developers.openai.com/api/docs/guides/reasoning).
frequency_penaltynumberoptional
Number between -2.0 and 2.0. Positive values penalize new tokens based on
their existing frequency in the text so far, decreasing the model's
likelihood to repeat the same line verbatim.
Default:0
presence_penaltynumberoptional
Number between -2.0 and 2.0. Positive values penalize new tokens based on
whether they appear in the text so far, increasing the model's likelihood
to talk about new topics.
Default:0
web_search_optionsobjectoptional
This tool searches the web for relevant results to use in a response.
Learn more about the [web search tool](https://developers.openai.com/api/docs/guides/tools-web-search).
response_formatobjectoptional
An object specifying the format that the model must output.
Setting to `{ "type": "json_schema", "json_schema": {...} }` enables
Structured Outputs which ensures the model will match your supplied JSON
schema. Learn more in the [Structured Outputs
guide](https://developers.openai.com/api/docs/guides/structured-outputs).
Setting to `{ "type": "json_object" }` enables the older JSON mode, which
ensures the message the model generates is valid JSON. Using `json_schema`
is preferred for models that support it.
audioobjectoptional
Parameters for audio output. Required when audio output is requested with
`modalities: ["audio"]`. [Learn more](https://developers.openai.com/api/docs/guides/audio).
storebooleanoptional
Whether or not to store the output of this chat completion request for
use in our [model distillation](https://developers.openai.com/api/docs/guides/supervised-fine-tuning#distilling-from-a-larger-model) or
[evals](https://developers.openai.com/api/docs/guides/evals) products.
Supports text and image inputs. Note: image inputs over 8MB will be dropped.
Default:false
moderationobjectoptional
Moderation settings for the request.
streambooleanoptional
If set to true, the model response data will be streamed to the client
as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
See the [Streaming section below](https://developers.openai.com/api/reference/resources/chat/subresources/completions/streaming-events)
for more information, along with the [streaming responses](https://developers.openai.com/api/docs/guides/streaming-responses)
guide for more information on how to handle the streaming events.
Default:false
stopstringoptional
Not supported with latest reasoning models `o3` and `o4-mini`.
Up to 4 sequences where the API will stop generating further tokens. The
returned text will not contain the stop sequence.
Default:null
logit_biasobjectoptional
Modify the likelihood of specified tokens appearing in the completion.
Accepts a JSON object that maps tokens (specified by their token ID in the
tokenizer) to an associated bias value from -100 to 100. Mathematically,
the bias is added to the logits generated by the model prior to sampling.
The exact effect will vary per model, but values between -1 and 1 should
decrease or increase likelihood of selection; values like -100 or 100
should result in a ban or exclusive selection of the relevant token.
Default:null
logprobsbooleanoptional
Whether to return log probabilities of the output tokens or not. If true,
returns the log probabilities of each output token returned in the
`content` of `message`.
Default:false
max_tokensintegerdeprecatedoptional
The maximum number of [tokens](https://platform.openai.com/tokenizer) that can be generated in the
chat completion. This value can be used to control
[costs](https://openai.com/api/pricing/) for text generated via API.
This value is now deprecated in favor of `max_completion_tokens`, and is
not compatible with [o-series models](https://developers.openai.com/api/docs/guides/reasoning).
nintegeroptional
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
Default:1
predictionobjectoptional
Configuration for a [Predicted Output](https://developers.openai.com/api/docs/guides/predicted-outputs),
which can greatly improve response times when large parts of the model
response are known ahead of time. This is most common when you are
regenerating a file with only minor changes to most of the content.
seedintegerdeprecatedoptional
This feature is in Beta.
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
stream_optionsobjectoptional
Options for streaming response. Only set this when you set `stream: true`.
toolsarray<FunctionTool>optional
A list of tools the model may call. You can provide either
[custom tools](https://developers.openai.com/api/docs/guides/function-calling#custom-tools) or
[function tools](https://developers.openai.com/api/docs/guides/function-calling).
tool_choicestringoptional
Controls which (if any) tool is called by the model.
`none` means the model will not call any tool and instead generates a message.
`auto` means the model can pick between generating a message or calling one or more tools.
`required` means the model must call one or more tools.
Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
`none` is the default when no tools are present. `auto` is the default if tools are present.
Allowed:noneautorequired
parallel_tool_callsbooleanoptional
Whether to enable [parallel function calling](https://developers.openai.com/api/docs/guides/function-calling#parallel-function-calling) during tool use.
Default:true
function_callstringdeprecatedoptional
Deprecated in favor of `tool_choice`.
Controls which (if any) function is called by the model.
`none` means the model will not call a function and instead generates a
message.
`auto` means the model can pick between generating a message or calling a
function.
Specifying a particular function via `{"name": "my_function"}` forces the
model to call that function.
`none` is the default when no functions are present. `auto` is the default
if functions are present.
Allowed:noneauto
functionsarray<object>deprecatedoptional
Deprecated in favor of `tools`.
A list of functions the model may generate JSON inputs for.
8 status codes
200Returns a chat completion object containing the generated choices, model, creation timestamp, and usage information when available. When streaming is enabled, returns server-sent event chunks and ends with a `[DONE]` frame on normal completion.
idstringrequired
A unique identifier for the chat completion.
choicesarray<object>required
A list of chat completion choices. Can be more than one if `n` is greater than 1.
createdintegerrequired
The Unix timestamp (in seconds) of when the chat completion was created.
modelstringrequired
The model used for the chat completion.
metadataobjectoptional
Set of 16 key-value pairs that can be attached to an object. This can be
useful for storing additional information about the object in a structured
format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings
with a maximum length of 512 characters.
service_tierstringoptional
Specifies the processing type used for serving the request.
- If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
- If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
- If set to '[flex](https://developers.openai.com/api/docs/guides/flex-processing)', then the request will be processed with the Flex Processing service tier.
- To opt-in to [Fast mode](https://developers.openai.com/api/docs/guides/fast-mode) at the request level, include the `service_tier=fast` or `service_tier=priority` parameter for Responses or Chat Completions. The response will show `service_tier=priority` regardless of if you specify `service_tier=fast` or `priority` in your request.
- When not set, the default behavior is 'auto'.
When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
This fingerprint represents the backend configuration that the model runs with.
Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
objectstringrequired
The object type, which is always `chat.completion`.
Allowed:chat.completion
usageobjectoptional
Usage statistics for the completion request.
moderationobjectoptional
Moderation results for the request input and generated output, if moderated
completions were requested.
400Returned when the chat completion request is invalid or request parameters are incompatible.
errorobjectrequired
401Returned when authentication fails because the API key is missing or revoked, or the client IP is not authorized.
errorobjectrequired
403Returned when organization policy blocks access to a personal API organization.
404Returned when the requested model or a referenced resource is not found or is unavailable to the caller.
errorobjectrequired
429Returned when the request is rejected because a rate limit was exceeded.
One documented failure
slow_down
Your request rate increased too quickly. Please reduce the request rate and gradually increase it again.
Traffic increased too quickly
errorobjectrequired
500Returned when an internal error prevents the chat completion from being processed.
errorobjectrequired
503Returned when the service is temporarily unavailable, including when the requested model is temporarily overloaded.
One documented failure
server_is_overloaded
The model is temporarily overloaded. Please retry your request after a brief delay.
The requested model is temporarily overloaded
errorobjectrequired
Error handling
A 400 is returned when the request is invalid or parameters are incompatible; a 401 is returned when the API key is missing or revoked, or the client IP is unauthorized. A 403 is returned when organization policy blocks access, a 404 when the model or a referenced resource is unavailable, and a 429 when a rate limit is exceeded; a 500 indicates an internal processing error, and a 503 indicates temporary service unavailability. model and messages are required, messages must contain at least one item, and top_logprobs must be between 0 and 20 and can be used only when logprobs is set to true.