OpenAI Compatible - Chat

Call the model through an OpenAI-compatible Chat API.
POST/v1/chat/completions

Authorization

AuthorizationstringheaderRequired
HTTP: Bearer Auth

Request Header

Content-Typeenum<string>Default: application/jsonRequired

The media type of the request body. Set it to application/json to ensure the request data is JSON.

Available option: application/json

Request Bodyapplication/json

modelstringRequired

Model code. Available values:

Unisound Series: u2-flash, u2, u2-med, u2-radimed

DeepSeek Series: deepseek-v4-flash-0731, deepseek-v4-pro

Kimi Series: kimi-k2.5, kimi-k2.6, kimi-k3

GLM Series: glm-5.3, glm-5.2, glm-5.1, glm-5

MiniMax Series: MiniMax-M3, MiniMax-M2.5

Qwen (Tongyi Qianwen) Series: qwen3.8-flash, qwen3.7-plus, qwen3.7-max, qwen3.8-max, qwen3.6-plus, qwen3.6-flash, qwen3.6-35b-a3b

messagesarrayRequired

Context passed to the model, ordered by conversation sequence.

System MessageobjectOptional

System message used to set the model role, tone, task objective, or constraint. It is usually placed at the first position of the messages array.

contentstring | arrayRequired

System instruction used to define the model role, behavior rules, response style, and task constraints.

typestringRequired

Content type. Only the fixed value text is supported.

textstringRequired

Specific text content.

rolestringRequired

Role of the system message, fixed to system.

User MessageobjectRequired

User message used to pass questions, instructions, or context to the model.

contentstring | arrayRequired

Message content. Use a string for text-only input; use an array when the input includes images or other multimodal data.

typestringRequired

Content type. Available values:

  • text: set to text when the input is text.
  • image_url: set to image_url when the input is an image.

textstringOptional

Input text. Required when type is text.

image_urlobjectOptional

Image information. Required when type is image_url.

urlstringRequired

Image URL or Base64 Data URL.

rolestringRequired

Role of the user message, fixed to user.

Assistant MessageobjectOptional

Reply from the model. It is usually sent back to the model as context in multi-turn conversations.

contentstring | arrayOptional

Text content of the model reply. When tool_calls is present, content can be empty; otherwise content is required.

typestringRequired

Content type. Only the fixed value text is supported.

textstringRequired

Specific text content.

reasoning_contentstringOptional

Reasoning chain content of the model.

rolestringRequired

Role of the assistant message, fixed to assistant.

tool_callsarrayOptional

Tool and argument information returned after Function Calling, containing one or more objects. It comes from the tool_calls field of the previous model response.

idstringRequired

ID of the tool response.

typestringRequired

Tool type. Currently only function is supported.

functionobjectRequired

Tool and argument information.

namestringRequired

Tool name.

argumentsstringRequired

Arguments in JSON string format.

indexintegerRequired

Index of the current tool information in the tool_calls array.

Tool MessageobjectOptional

Output information from the tool.

contentstring | arrayRequired

Output content of the tool function. If it is structured data, serialize it to a string.

typestringRequired

Content type. Only the fixed value text is supported.

textstringRequired

Specific text content.

rolestringRequired

Fixed to tool.

tool_call_idstringRequired

ID returned after Function Calling, obtained through completion.choices[0].message.tool_calls[$index].id, used to identify which tool the Tool Message corresponds to.

streambooleanOptionalDefault: false

Whether to reply in streaming mode.

  • false: return once after the model generates all content;
  • true: return incrementally while generating, and each partial result is returned as a data chunk. These chunks need to be read one by one in real time and concatenated into the full reply.

Setting it to true is recommended to improve reading experience and reduce timeout risk.

stream_optionsobjectOptional

Configuration items for streaming output. Effective only when stream is true.

include_usagebooleanOptionalDefault: false

Whether to include token usage information in the final data chunk of the response.

  • true: include it;
  • false: do not include it.
In streaming mode, token usage information can only appear in the last data chunk of the response.

temperaturefloatOptional

Sampling temperature, used to control output diversity. A higher temperature makes the generated text more diverse; a lower temperature makes it more deterministic.

Value range: [0,2).

Default value of temperature: 1.0.

top_pfloatOptional

Nucleus sampling threshold that controls output diversity. It is recommended to use either this or temperature, not both.

Value range: (0, 1.0].

The default value is determined by the model.

top_kintegerOptional

Specifies the number of candidate tokens used during sampling. A larger value makes the output more random; a smaller value makes it more deterministic. The value must be an integer greater than or equal to 1.

Default value of top_k: 40.

This is a non-standard OpenAI parameter. When using the Python SDK, put it in the extra_body object. Configuration example: extra_body={"top_k":xxx}.

max_tokensintegerOptional

Used to limit the maximum number of output tokens. If the generated content exceeds this value, generation stops early and the returned finish_reason becomes length.

Useful when output length must be controlled, such as generating summaries or keywords, or for reducing cost and response time.

When max_tokens is triggered, the finish_reason field in the response becomes length.

max_tokens does not limit the length of the reasoning chain of thinking models.

thinkingobjectOptional

Whether to enable thinking mode. u2, kimi-k3, glm-5.3, and MiniMax-M2.5 enable thinking by default and do not support disabling it. MiniMax-M3 defaults to adaptive and can be disabled with thinking.type=disabled. u2-radimed disables thinking by default and does not support enabling it.

typestringRequired

Available values: enabled (thinking mode on), disabled (thinking mode off). MiniMax-M3 also supports adaptive (default): the model decides whether to think.

This is a non-standard OpenAI parameter. When using the Python SDK, put it in the extra_body object. Configuration example: extra_body={"thinking": "{"type":xxx}"}.

preserve_thinkingbooleanOptionalDefault: false

Whether to append historical reasoning_content from assistant messages to the model input.

Supported models: Qwen Series: qwen3.7-plus, qwen3.7-max, qwen3.8-max, qwen3.8-flash, qwen3.6-plus; Kimi Series: kimi-k2.6. qwen3.8-max and qwen3.8-flash default to true.

This is a non-standard OpenAI parameter. When using the Python SDK, put it in the extra_body object. Configuration example: extra_body={"preserve_thinking": true}.

reasoning_effortstringOptional

Controls the model's reasoning effort. Supported values and defaults vary by model.

ModelDefaultSupported levelsMapping of other levels
deepseek-v4-pro, glm-5.2, glm-5.1, glm-5highhigh, maxlow and medium map to high; xhigh maps to max
deepseek-v4-flash-0731highmax, high, lowmedium maps to high; xhigh maps to high
kimi-k3, glm-5.3, glm-5.3-flashmaxmax, high, low—
qwen3.8-max, qwen3.8-flashxhighxhigh, medium, lowmax and high map to xhigh; minimal maps to low; none disables thinking
u2-med—none, low, medium, highminimal maps to low; xhigh and max map to high

kimi-k3, glm-5.3, and glm-5.3-flash always enable thinking. thinking.type only supports enabled; passing disabled causes the API request to fail.

Values other than the supported options and mapped values above will cause an error.

reasoning_effort is a standard OpenAI parameter. When using the Python SDK, pass reasoning_effort="high" directly; do not put it in extra_body.

presence_penaltyfloatOptional

Controls content repetition. Positive values reduce repetition and increase lexical diversity; negative values increase repetition.

Value range: [-2.0, 2.0].

The default value is determined by the model.

frequency_penaltyfloatOptional

Penalizes tokens based on how often they have already appeared. Positive values reduce the probability of frequent tokens reappearing.

Value range: [-2.0, 2.0].

The default value is determined by the model.

repetition_penaltyfloatOptional

Penalty for consecutive sequence repetition.

Value range: (0, 2.0].

The default value is determined by the model.

stopstring | arrayOptional

Stop sequences; generation terminates immediately when a string or token_id is matched.

Array elements must not mix strings and token_id values.

response_formatobjectOptionalDefault: {"type": "text"}

Format of the returned content.

typestringRequired

Format of the returned content. Available values:

  • text: return plain text;
  • json_object: return a standard JSON string.
If set to json_object, the System Message or User Message must contain the keyword "JSON" (case-insensitive), otherwise the API returns an error.
For models that support structured output only in non-thinking mode, do not set response_format to {"type": "json_object"} when thinking mode is enabled (thinking.type=enabled), otherwise the API returns an error.

Qwen Series: qwen3.7-plus, qwen3.7-max, qwen3.8-max, qwen3.8-flash

Qwen Series (non-thinking mode): qwen3.6-plus, qwen3.6-flash, qwen3.6-35b-a3b

DeepSeek Series: deepseek-v4-flash-0731, deepseek-v4-pro

Kimi Series: kimi-k2.5, kimi-k2.6, kimi-k3

GLM Series: glm-5.1

GLM Series (non-thinking mode): glm-5

toolsarrayOptional

Array containing one or more tool objects for the model to call in Function Calling.

If tools is set and the model decides a tool call is needed, the response returns tool information through tool_calls.

typestringRequired

Tool type. Currently only function is supported.

functionobjectRequired

namestringRequired

Tool name. Only letters, digits, underscores (_), and hyphens (-) are allowed, with a maximum of 64 tokens.

descriptionstringRequired

Tool description that helps the model decide when and how to call the tool.

parametersobjectOptionalDefault: {}

Parameter description of the tool. It must be valid JSON Schema.

If the parameters field is empty, the tool has no arguments, such as a time query tool. For better tool-calling accuracy, passing parameters is recommended.

tool_choicestring | objectOptionalDefault: auto

Tool selection strategy. Set this parameter to force a specific tool-calling behavior.

  • auto: the model decides whether to call tools;
  • none: disable tool calling;
  • {"type": "function", "function": {"name": "<tool_name>"}}: force calling the specified tool.
Thinking-mode models do not support forcing a specific tool call.

parallel_tool_callsbooleanOptionalDefault: false

Whether to enable parallel tool calls.

  • true: enable;
  • false: disable.

tool_streambooleanOptionalDefault: false

Whether to stream tool arguments in streaming output.

Supported models: Qwen Series: qwen3.7-plus, qwen3.8-max, qwen3.8-flash, qwen3.6-plus, qwen3.6-flash; GLM Series: glm-5, glm-5.1, glm-5.2.

Effective only when stream=true. This is a non-standard OpenAI parameter. When using the Python SDK, put it in the extra_body object. Configuration example: extra_body={"tool_stream": true}.

Chat response object (non-streaming)

idstring

Unique identifier for this request.

choicesarray

Array of model-generated content.

finish_reasonstring

Reason why the model stopped generating. There are three cases:

  • stop when the input stop parameter is triggered or the model stops naturally;
  • length when generation ends because the output is too long;
  • tool_calls when the model needs to call a tool.

indexinteger

Index of the current object in the choices array.

messageobject

Message output by the model.

contentstring

Reply content from the model.

When response_format.type=json_object, content is a JSON string.

reasoning_contentstring

Reasoning chain content of the model.

For models that do not support preserve_thinking, do not pass historical reasoning_content back in multi-turn conversations.

rolestring

Role of the message, fixed to assistant.

tool_callsarray

Tool and argument information generated by the model after Function Calling.

idstring

Unique identifier of this tool response.

typestring

Tool type. Currently only function is supported.

functionobject

Tool information.

namestring

Tool name.

argumentsstring

Arguments in JSON string format.

Because model responses are somewhat random, the generated arguments may not match the function signature. Validate argument validity before invocation.

createdinteger

Unix timestamp in seconds when the request was created.

modelstring

Model used for this request.

objectstring

Always chat.completion.

service_tierstring

This field is currently fixed to null.

system_fingerprintstring

This field is currently fixed to null.

usageobject

Token usage information for this request.

completion_tokensinteger

Number of output tokens.

prompt_tokensinteger

Number of input tokens.

total_tokensinteger

Total number of consumed tokens, equal to prompt_tokens plus completion_tokens.

prompt_tokens_detailsobject

Fine-grained breakdown of input tokens.

cached_tokensinteger

Number of tokens served from cache.

Chat response chunk object (streaming)

idstring

Unique identifier of this request. Every chunk object has the same id.

choicesarray

Array of model-generated content, which may contain one or more objects. If include_usage is set to true, choices is an empty array in the last chunk.

deltaobject

Incremental object of the request.

contentstring

Incremental message content.

reasoning_contentstring

Incremental reasoning chain content.

rolestring

Role of the incremental message object. It only has a value in the first chunk.

tool_callsarray

Tool and argument information generated by the model after Function Calling.

indexinteger

Index of the current tool in the tool_calls array.

idstring

Unique identifier of this tool response.

functionobject

Information about the called tool.

argumentsstring

Incremental argument information. After concatenating arguments across all chunks, you get the complete arguments.

Because model responses are somewhat random, the generated arguments may not match the function signature. Validate argument validity before invocation.

namestring

Tool name, only present in the first chunk.

typestring

Tool type. Currently only function is supported.

finish_reasonstring

Reason why the model stopped generating. There are four cases:

  • stop when the input stop parameter is triggered or the model stops naturally;
  • null while generation has not finished;
  • length when generation ends because the output is too long;
  • tool_calls when the model needs to call a tool.

indexinteger

Index of the current response in the choices array. When the input parameter n is greater than 1, this value is required to merge the complete content of each different response.

createdinteger

Timestamp when this request was created. Each chunk has the same timestamp.

modelstring

Model used for this request.

objectstring

Always chat.completion.chunk.

service_tierstring

This field is currently fixed to null.

system_fingerprintstring

This field is currently fixed to null.

usageobject

Token usage of this request. It is shown only in the last chunk when include_usage is true.

completion_tokensinteger

Number of output tokens.

prompt_tokensinteger

Number of input tokens.

total_tokensinteger

Total number of consumed tokens, equal to prompt_tokens plus completion_tokens.

prompt_tokens_detailsobject

Fine-grained breakdown of input tokens.

cached_tokensinteger

Number of tokens served from cache.