Skip to main content

Chat & Completions

This page brings together the OpenAI Chat Completions, OpenAI Responses, native Anthropic Claude, and native Google Gemini chat endpoints.

Apifox Coverage Notes

  • OpenAI / ChatCompletions: basic chat, streaming, image understanding, function calling, logprobs, classic completions, web search, PDF analysis, Codex, response_format, N-test variants, token usage
  • OpenAI / Responses: basic text responses, image analysis, web search tool, file search tool, computer use, streaming, deep-research, reasoning controls, xAI web search
  • Anthropic Claude: native format, OpenAI-compatible format, forced thinking output, multi-turn tool use, web search
  • Google Gemini: native chat/media recognition plus OpenAI-compatible reasoning controls, web search, TTS, audio understanding, and video understanding

Model APIs / Chat / OpenAI / Chat Completions Format

POST Completions Legacy Format

POST /completions

Body Parameters

{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Write a tagline for an ice cream shop."
}

Request Parameters

NameInTypeRequiredDescription
Content-TypeheaderstringNonone
AcceptheaderstringNonone
AuthorizationheaderstringNonone
bodybodyobjectNonone
» messagesbody[object]YesMessages used to generate a chat completion in the chat format.
»» rolebodystringNonone
»» contentbodystringNonone
» modelbodystringYesModel ID to use. See the model endpoint compatibility table for details on which models work with the Chat API.
» storebodyboolean¦nullNoWhether to store the output of this chat-completion request for distillation or evaluation products.
» reasoning_effortbodystring¦nullNoAvailable only for o-series models.
» metadatabodyobject¦nullNoSet of 16 key-value pairs that can be attached to the object. Useful for storing additional structured metadata that can later be queried through the API or dashboard.
» modalitiesbody[string]¦nullNoOutput types you want the model to generate for this request. Most models produce text, so the default is ["text"].
» predictionbodyobjectNoPrediction-output configuration. This can greatly improve response time when most of the model response is already known in advance, such as when you are making only small edits to a file.
» audiobodyobject¦nullNoParameters for audio output. Required when requesting audio output with modalities: ["audio"].
» temperaturebodynumber¦nullNoSampling temperature between 0 and 2. Higher values such as 0.8 make output more random, while lower values such as 0.2 make it more focused and deterministic. In most cases, adjust this or top_p, but not both.
» top_pbodynumber¦nullNoAlternative to temperature sampling, known as nucleus sampling, where the model considers only token results that together make up the top_p probability mass. For example, 0.1 means only the top 10% probability mass is considered.
» nbodyinteger¦nullNoNumber of chat-completion choices to generate for each input message. You are billed for the tokens generated across all choices, so keeping n at 1 minimizes cost.
» stopbodystring¦nullNoNot supported by the latest reasoning models or by .o3 and o4-mini.
» max_tokensbodyinteger¦nullNoMaximum number of tokens that can be generated in the chat completion. Use this to control text-generation cost through the API.
» max_completion_tokensbodyinteger¦nullNoUpper bound on the number of tokens that can be generated in the completion, including visible output tokens and reasoning tokens.
» presence_penaltybodynumber¦nullNoA number between -2.0 and 2.0. Positive values penalize new tokens based on whether they have already appeared in the text so far, increasing the chance that the model moves to new topics.
» frequency_penaltybodynumber¦nullNoA number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, reducing the chance of repeated lines.
» logit_biasbodynullNoAdjusts the likelihood that specified tokens appear in the completion.
» logprobsbodyboolean¦nullNoWhether to return log probabilities for output tokens. If set to true, the response includes the log probability for each output token in message.content.
» userbodystringNoUnique identifier representing the end user. Helps OpenAI monitor and detect abuse.
» service_tierbodystring¦nullNoSpecifies the latency tier used to process the request. This parameter is relevant for customers subscribed to the scale-tier service:
» stream_optionsbodyobject¦nullNoOptions for streaming responses. Used only when stream: true.
»» include_usagebodybooleanNoIf set, the stream sends an additional block before the data: [DONE] message. The usage field on that block contains token-usage statistics for the whole request, while choices is always an empty array. All other blocks also include usage, but with a null value. If the stream is interrupted, you might not receive the final usage block.
» response_formatbodyobjectNoSpecifies the format the model must output.
» seedbodyinteger¦nullNoBeta feature. If provided, the system makes a best effort to sample deterministically so repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Use system_fingerprint in the response to monitor backend changes.
» toolsbody[string]NoList of tools the model may call. Only functions are currently supported as tools. Use this parameter to provide the list of functions for which the model may generate JSON inputs. Up to 128 functions are supported.
» functionsbody[string]NoNote: deprecated, recommend using tools
» tool_choicebodystringNoControls which tool the model calls, if any: none means the model generates a message without calling tools; auto lets the model choose between generating a message or calling one or more tools; required forces one or more tool calls; {"type": "function", "function": {"name": "my_function"}} forces a specific tool call.
» function_callbodystringNoNote: deprecated, recommend using tool_choice
» parallel_tool_callsbodybooleanNoWhether to enable parallel function calls while tools are being used.
» streambodybooleanNoIf set to true, model response data is streamed to the client as it is generated through server-sent events. See the streaming-response section below and the streaming guide for handling streamed events.
» top_logprobsbodyintegerNoInteger from 0 to 20 specifying how many of the most likely tokens to return at each token position, each with its associated log probability. Requires logprobs: true.
» web_search_optionsbodyobjectNoThis tool searches the web for relevant results to support the response. See the web-search tool documentation for more details.
Details

» reasoning_effort: Available only for o-series models. Constrains the amount of reasoning effort used by reasoning models. Supported values are low, medium, and high. Lower reasoning effort can improve response latency and reduce the number of reasoning tokens in the response.

» metadata: Set of 16 key-value pairs that can be attached to the object. Useful for storing additional structured metadata that can later be queried through the API or dashboard.

Keys must be strings up to 64 characters long. Values must be strings up to 512 characters long.

» modalities: Output types you want the model to generate for this request. Most models produce text, so the default is ["text"].

This model can also generate audio. To request both text and audio in the same response, use ["text", "audio"].

» top_p: Alternative to temperature sampling, known as nucleus sampling, where the model considers only token results that together make up the top_p probability mass. For example, 0.1 means only the top 10% probability mass is considered.

In most cases, adjust this value or temperature, but not both.

» stop: Not supported by the latest reasoning models or by .o3 and o4-mini. Up to four sequences where the API should stop generating more tokens. The returned text does not include the stop sequence.

» max_tokens: Maximum number of tokens that can be generated in the chat completion. Use this to control text-generation cost through the API.

This field is now deprecated in favor of max_completion_tokens and is incompatible with the o1 model family.

» logit_bias: Adjusts the likelihood that specified tokens appear in the completion.

Accepts a JSON object that maps token IDs to bias values from -100 to 100. Mathematically, the bias is added to the logits generated by the model before sampling. The exact effect varies by model, but values between -1 and 1 should slightly decrease or increase selection likelihood, while values like -100 or 100 should effectively ban or force the relevant token.

» service_tier: Specifies the latency tier used to process the request. This parameter is relevant for customers subscribed to the scale-tier service:

If set to 'auto' and the project has Scale tier enabled, the system uses Scale-tier credits until they are exhausted. If set to 'auto' and the project does not have Scale tier enabled, the request is processed on the default service tier with a lower uptime SLA and no latency guarantee. If set to 'default', the request is processed on the default service tier with a lower uptime SLA and no latency guarantee. If set to 'flex', the request is processed on the Flex Processing service tier. See the vendor documentation for details. If not set, the default behavior is auto. When this parameter is set, the response body includes the service_tier that was used.

» response_format: Specifies the format the model must output.

Set to { "type": "json_schema", "json_schema": {...} } to enable structured output and require the model to match the JSON schema you provide. Set to { "type": "json_object" } to enable JSON mode and require the model to produce valid JSON. Important: when using JSON mode, you must still explicitly instruct the model through a system or user message to produce JSON. Otherwise, the model may emit endless whitespace until the token limit is reached.

» tool_choice: Controls which tool the model calls, if any: none means the model generates a message without calling tools; auto lets the model choose between generating a message or calling one or more tools; required forces one or more tool calls; {"type": "function", "function": {"name": "my_function"}} forces a specific tool call.

Defaults to none when no tools are present, and auto when tools are available.

» function_call: Note: deprecated, recommend using tool_choice Controls which function the model calls, if any:

none: the model will not call a function and will generate a message instead auto: the model can choose between generating a message and calling a function {"name": "my_function"}: forces the model to call a specific function

Response Example

200 Response

{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone

GET Token Usage Query

GET /api/usage/token

Queries the currently authenticated Bearer token for granted quota, used quota, remaining quota, unlimited status, model limits, and expiration time.

Field description (data) object: always token_usage name: token name total_granted: Total granted quota (= used + remaining) total_used: Used quota total_available: Remaining available quota unlimited_quota: Whether quota is unlimited model_limits: Allowed model list model_limits_enabled: Whether model limits are enabled expires_at: Expiration time as a Unix timestamp in seconds. Returns 0 if it never expires (the backend normalizes -1 to 0).

Request Parameters

NameInTypeRequiredDescription
AuthorizationheaderstringNonone

Response Example

200 Response

{
"data": [
{
"id": "string",
"object": "string",
"owned_by": "string",
"permission": [
"string"
]
}
],
"object": "string"
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» data[object]truenonenone
»» idstringtruenonenone
»» objectstringtruenonenone
»» owned_bystringtruenonenone
»» permission[oneOf]truenonenone

oneOf

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousstringfalsenonenone

xor

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousintegerfalsenonenone

xor

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousbooleanfalsenonenone

xor

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousarrayfalsenonenone

xor

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousobjectfalsenonenone

xor

NameTypeRequiredConstraintsChinese NameDescription
»»» anonymousnumberfalsenonenone

continued

NameTypeRequiredConstraintsChinese NameDescription
» objectstringtruenonenone

Model APIs / Chat / OpenAI / Responses Format

POST xAI Web Search

POST /responses

Body Parameters

{
"model": "grok-4-1-fast-reasoning",
"input": [
{
"role": "user",
"content": "最近 xAI 有哪些最新动态?"
}
],
"tools": [
{
"type": "web_search"
},
{
"type": "x_search"
}
]
}

Request Parameters

NameInTypeRequiredDescription
Content-TypeheaderstringYesnone
AcceptheaderstringYesnone
AuthorizationheaderstringNonone
bodybodyobjectNonone
» modelbodystringYesID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API.
» messagesbody[object]YesMessages used to generate a chat completion in the chat format.
»» rolebodystringNonone
»» contentbodystringNonone
» temperaturebodyintegerNoSampling temperature between 0 and 2. Higher values such as 0.8 make output more random, while lower values such as 0.2 make it more focused and deterministic. In most cases, adjust this or top_p, but not both.
» top_pbodyintegerNoAlternative to temperature sampling, known as nucleus sampling, where the model considers only tokens that together make up the top_p probability mass. For example, 0.1 means only the top 10% probability mass is considered. In most cases, adjust this or temperature, but not both.
» nbodyintegerNoNumber of chat-completion choices to generate for each input message.
» streambodybooleanNoIf set, partial message deltas are streamed the same way they are in ChatGPT. As tokens become available, they are sent as data-only server-sent events, with the stream terminated by data: [DONE]. See the OpenAI Cookbook example code.
» stopbodystringNoUp to four sequences where the API should stop generating additional tokens.
» max_tokensbodyintegerNoMaximum number of tokens to generate for the chat completion. The combined length of input and generated tokens is still limited by the model context window.
» presence_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize new tokens based on whether they have already appeared in the text so far, increasing the chance that the model discusses new topics. Read more about frequency and presence penalties.
» frequency_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize tokens based on how often they already appear in the text, reducing the chance that the model repeats the same line verbatim. Read more about frequency and presence penalties.
» logit_biasbodynullNoAdjusts the likelihood that specified tokens appear in the completion. Accepts a JSON object that maps token IDs to bias values from -100 to 100. Mathematically, the bias is added to the logits produced by the model before sampling. The exact effect varies by model, but values between -1 and 1 should slightly decrease or increase selection likelihood, while values like -100 or 100 should effectively ban or force the relevant token.
» userbodystringNoUnique identifier representing your end user. Helps OpenAI monitor and detect abuse. Learn more.

Response Example

200 Response

{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone

POST Web Search

POST /messages

Supports the official native format, using the same model names as the upstream provider

Body Parameters

{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "今天几号?用一句话总结今天北京的天气,并给出信息来源"
}
],
"tools": [
{
"type": "web_search_20250305",
"name": "web_search",
"max_uses": 3
}
],
"tool_choice": {
"type": "auto"
}
}

Request Parameters

NameInTypeRequiredDescription
Content-TypeheaderstringYesnone
AcceptheaderstringYesnone
x-api-keyheaderstringNonone
bodybodyobjectNonone
» modelbodystringYesID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API.
» messagesbody[object]YesMessages used to generate a chat completion in the chat format.
»» rolebodystringNonone
»» contentbodystringNonone
» temperaturebodyintegerNoSampling temperature between 0 and 2. Higher values such as 0.8 make output more random, while lower values such as 0.2 make it more focused and deterministic. In most cases, adjust this or top_p, but not both.
» top_pbodyintegerNoAlternative to temperature sampling, known as nucleus sampling, where the model considers only tokens that together make up the top_p probability mass. For example, 0.1 means only the top 10% probability mass is considered. In most cases, adjust this or temperature, but not both.
» nbodyintegerNoNumber of chat-completion choices to generate for each input message.
» streambodybooleanNoIf set, partial message deltas are streamed the same way they are in ChatGPT. As tokens become available, they are sent as data-only server-sent events, with the stream terminated by data: [DONE]. See the OpenAI Cookbook example code.
» stopbodystringNoUp to four sequences where the API should stop generating additional tokens.
» max_tokensbodyintegerNoMaximum number of tokens to generate for the chat completion. The combined length of input and generated tokens is still limited by the model context window.
» presence_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize new tokens based on whether they have already appeared in the text so far, increasing the chance that the model discusses new topics. Read more about frequency and presence penalties.
» frequency_penaltybodynumberNoA number between -2.0 and 2.0. Positive values penalize tokens based on how often they already appear in the text, reducing the chance that the model repeats the same line verbatim. Read more about frequency and presence penalties.
» logit_biasbodynullNoAdjusts the likelihood that specified tokens appear in the completion. Accepts a JSON object that maps token IDs to bias values from -100 to 100. Mathematically, the bias is added to the logits produced by the model before sampling. The exact effect varies by model, but values between -1 and 1 should slightly decrease or increase selection likelihood, while values like -100 or 100 should effectively ban or force the relevant token.
» userbodystringNoUnique identifier representing your end user. Helps OpenAI monitor and detect abuse. Learn more.

Response Example

200 Response

{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone

Model APIs / Chat / Google Gemini / Native Gemini Format

POST Gemini Text Chat

POST /v1beta/models/gemini-3-flash-preview:generateContent

Proxies Gemini API requests. Path format: /v1beta/models/{model_name}:{action} For example: /v1beta/models/gemini-2.5-pro:generateContent /v1beta/models/gemini-2.5-pro:streamGenerateContent?alt=sse

Body Parameters

{
"contents": [
{
"parts": [
{
"text": "Hello"
}
]
}
]
}

Request Parameters

NameInTypeRequiredDescription
keyquerystringYesnone
Content-TypeheaderstringYesnone
bodybodyobjectNonone
» contentsbody[object]Yesnone
»» partsbody[object]Nonone
»»» textbodystringNonone

Response Example

200 Response

{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Responses

StatusMeaningDescriptionModel
200OKnoneInline

Response Schema

Status 200

NameTypeRequiredConstraintsChinese NameDescription
» idstringtruenonenone
» objectstringtruenonenone
» createdintegertruenonenone
» choices[object]truenonenone
»» indexintegerfalsenonenone
»» messageobjectfalsenonenone
»»» rolestringtruenonenone
»»» contentstringtruenonenone
»» finish_reasonstringfalsenonenone
» usageobjecttruenonenone
»» prompt_tokensintegertruenonenone
»» completion_tokensintegertruenonenone
»» total_tokensintegertruenonenone