Chat va completion
This page brings together the OpenAI Chat Completions, OpenAI Responses, native Anthropic Claude, and native Google Gemini chat endpoints.
Pham vi Apifox
- 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
API model / Chat / OpenAI / Dinh dang Chat Completions
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Content-Type | header | string | No | none |
| Accept | header | string | No | none |
| Authorization | header | string | No | none |
| body | body | object | No | none |
| » messages | body | [object] | Yes | Messages used to generate a chat completion in the chat format. |
| »» role | body | string | No | none |
| »» content | body | string | No | none |
| » model | body | string | Yes | Model ID to use. See the model endpoint compatibility table for details on which models work with the Chat API. |
| » store | body | boolean¦null | No | Whether to store the output of this chat-completion request for distillation or evaluation products. |
| » reasoning_effort | body | string¦null | No | Available only for o-series models. |
| » metadata | body | object¦null | No | 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. |
| » modalities | body | [string]¦null | No | Output types you want the model to generate for this request. Most models produce text, so the default is ["text"]. |
| » prediction | body | object | No | Prediction-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. |
| » audio | body | object¦null | No | Parameters for audio output. Required when requesting audio output with modalities: ["audio"]. |
| » temperature | body | number¦null | No | Sampling 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_p | body | number¦null | No | 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. |
| » n | body | integer¦null | No | Number 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. |
| » stop | body | string¦null | No | Not supported by the latest reasoning models or by .o3 and o4-mini. |
| » max_tokens | body | integer¦null | No | Maximum number of tokens that can be generated in the chat completion. Use this to control text-generation cost through the API. |
| » max_completion_tokens | body | integer¦null | No | Upper bound on the number of tokens that can be generated in the completion, including visible output tokens and reasoning tokens. |
| » presence_penalty | body | number¦null | No | A 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_penalty | body | number¦null | No | A 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_bias | body | null | No | Adjusts the likelihood that specified tokens appear in the completion. |
| » logprobs | body | boolean¦null | No | Whether to return log probabilities for output tokens. If set to true, the response includes the log probability for each output token in message.content. |
| » user | body | string | No | Unique identifier representing the end user. Helps OpenAI monitor and detect abuse. |
| » service_tier | body | string¦null | No | Specifies the latency tier used to process the request. This parameter is relevant for customers subscribed to the scale-tier service: |
| » stream_options | body | object¦null | No | Options for streaming responses. Used only when stream: true. |
| »» include_usage | body | boolean | No | If 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_format | body | object | No | Specifies the format the model must output. |
| » seed | body | integer¦null | No | Beta 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. |
| » tools | body | [string] | No | List 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. |
| » functions | body | [string] | No | Note: deprecated, recommend using tools |
| » tool_choice | body | string | No | 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. |
| » function_call | body | string | No | Note: deprecated, recommend using tool_choice |
| » parallel_tool_calls | body | boolean | No | Whether to enable parallel function calls while tools are being used. |
| » stream | body | boolean | No | If 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_logprobs | body | integer | No | Integer 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_options | body | object | No | This 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
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Authorization | header | string | No | none |
Response Example
200 Response
{
"data": [
{
"id": "string",
"object": "string",
"owned_by": "string",
"permission": [
"string"
]
}
],
"object": "string"
}
Responses
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » data | [object] | true | none | none | |
| »» id | string | true | none | none | |
| »» object | string | true | none | none | |
| »» owned_by | string | true | none | none | |
| »» permission | [oneOf] | true | none | none |
oneOf
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | string | false | none | none |
xor
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | integer | false | none | none |
xor
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | boolean | false | none | none |
xor
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | array | false | none | none |
xor
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | object | false | none | none |
xor
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| »»» anonymous | number | false | none | none |
continued
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » object | string | true | none | none |
API model / Chat / OpenAI / Dinh dang Responses
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Content-Type | header | string | Yes | none |
| Accept | header | string | Yes | none |
| Authorization | header | string | No | none |
| body | body | object | No | none |
| » model | body | string | Yes | ID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API. |
| » messages | body | [object] | Yes | Messages used to generate a chat completion in the chat format. |
| »» role | body | string | No | none |
| »» content | body | string | No | none |
| » temperature | body | integer | No | Sampling 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_p | body | integer | No | Alternative 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. |
| » n | body | integer | No | Number of chat-completion choices to generate for each input message. |
| » stream | body | boolean | No | If 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. |
| » stop | body | string | No | Up to four sequences where the API should stop generating additional tokens. |
| » max_tokens | body | integer | No | Maximum 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_penalty | body | number | No | A 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_penalty | body | number | No | A 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_bias | body | null | No | 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 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. |
| » user | body | string | No | Unique 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
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |
API model / Chat / Anthropic Claude / Dinh dang Claude goc (khuyen dung)
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| Content-Type | header | string | Yes | none |
| Accept | header | string | Yes | none |
| x-api-key | header | string | No | none |
| body | body | object | No | none |
| » model | body | string | Yes | ID of the model to use. See the model endpoint compatibility table for which models are compatible with the Chat API. |
| » messages | body | [object] | Yes | Messages used to generate a chat completion in the chat format. |
| »» role | body | string | No | none |
| »» content | body | string | No | none |
| » temperature | body | integer | No | Sampling 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_p | body | integer | No | Alternative 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. |
| » n | body | integer | No | Number of chat-completion choices to generate for each input message. |
| » stream | body | boolean | No | If 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. |
| » stop | body | string | No | Up to four sequences where the API should stop generating additional tokens. |
| » max_tokens | body | integer | No | Maximum 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_penalty | body | number | No | A 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_penalty | body | number | No | A 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_bias | body | null | No | 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 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. |
| » user | body | string | No | Unique 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
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |
API model / Chat / Google Gemini / Dinh dang Gemini goc
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
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| key | query | string | Yes | none |
| Content-Type | header | string | Yes | none |
| body | body | object | No | none |
| » contents | body | [object] | Yes | none |
| »» parts | body | [object] | No | none |
| »»» text | body | string | No | none |
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
| Status | Meaning | Description | Model |
|---|---|---|---|
| 200 | OK | none | Inline |
Response Schema
Status 200
| Name | Type | Required | Constraints | Chinese Name | Description |
|---|---|---|---|---|---|
| » id | string | true | none | none | |
| » object | string | true | none | none | |
| » created | integer | true | none | none | |
| » choices | [object] | true | none | none | |
| »» index | integer | false | none | none | |
| »» message | object | false | none | none | |
| »»» role | string | true | none | none | |
| »»» content | string | true | none | none | |
| »» finish_reason | string | false | none | none | |
| » usage | object | true | none | none | |
| »» prompt_tokens | integer | true | none | none | |
| »» completion_tokens | integer | true | none | none | |
| »» total_tokens | integer | true | none | none |