Chat Completion V2
Creates a model response for the given chat conversation, using an OpenAI-compatible request and response shape.
Requires api-subscription-key.
Streaming is optional. Default is one JSON response (stream omitted or false). Set stream: true for server-sent events; the stream ends with a [DONE] line.
Reasoning (glm5.3, glm5.3-flash, gemma4, deepseekv4.1-flash-1017, deepseekv4-pro, kimi-k3.1-pro): set reasoning_effort to low, high, or max. Default when omitted is max, except high on glm5.3-flash, deepseekv4.1-flash-1017, and deepseekv4-pro, and no reasoning on gemma4. none turns thinking off on deepseekv4.1-flash-1017 and deepseekv4-pro. kimi-k3.1-pro always thinks. The trace is in choices[].message.reasoning_content and counts toward max_tokens. gemma4 reasons only when reasoning_effort is set.
Request fields documented on this operation are validated by the API. Other OpenAI-compatible fields may be forwarded to the model when sent.
Legacy functions / function_call are rejected — use tools and tool_choice.
Authentication
Bearer authentication of the form Bearer <token>, where token is your auth token.
Headers
Optional session ID for a multi-turn conversation. Send the same value on every turn of a conversation so the turns are routed together and can reuse cached prompt context, which lowers latency on later turns. Use a new value for each conversation. The ID is scoped to your API subscription and is never shared with other customers. Use an opaque value such as a UUID, and do not put personal data in it. Requests without this header are unaffected.
Request
Non-empty conversation history. Roles: system, developer, user, assistant, tool. Content is a string or an array of parts (text, image_url). Images must use inline data:image/…;base64,… URLs — remote HTTP(S) image URLs are rejected.
Model IDs accepted by POST /v2/chat/completions (case-sensitive; unknown ids return 404):
sarvam-105b— Sarvam flagship chat model.sarvam-105b-conversations— Sarvam 105B tuned for real-time dialogue and voice agents; 32,000-token context window.glm5.3— 1,048,576-token context window; visible reasoning inreasoning_content(billed as completion tokens); tool calling; max request size 10,485,760 bytes;nmust be1.glm5.3-flash— 1,048,576-token context window, image input (inline base64), tool calling, and reasoning (on by default).gemma4— 262,144-token context window, image input (inline base64), tool calling, and optional reasoning (reasoning_effort).deepseekv4.1-flash-1017— 1,048,576-token context window, image input (inline base64), tool calling, and reasoning.deepseekv4.1-flash-1017-interactive— the same model on a high-throughput deployment: more than 200 output tokens per second, against about 80; same capabilities asdeepseekv4.1-flash-1017.deepseekv4-pro(Provisioned Throughput) — 1,000,000-token context window; text input only; tool calling; reasoning (defaulthigh;noneturns it off).kimi-k3.1-pro(Provisioned Throughput) — 1,048,576-token context window; image and video input (inline base64); tool calling; reasoning is always on (defaultmax).qwen38-27b(Provisioned Throughput) — 262,144-token context window; image input (inline base64); tool calling; reasoning on by default (noneturns it off).
Sampling temperature from 0 to 2. Higher values increase variation; lower values focus the output. Output is not guaranteed to be identical across requests, even at 0. Prefer changing either temperature or top_p, not both.
Nucleus sampling: greater than 0 and at most 1. On glm5.3, top_p: 0 is rejected. Prefer changing either top_p or temperature, not both.
On reasoning models: low, high, or max on every reasoning model, and medium on sarvam-105b, deepseekv4.1-flash-1017, deepseekv4.1-flash-1017-interactive, deepseekv4-pro, kimi-k3.1-pro, and qwen38-27b (kimi-k3.1-pro runs medium as high). Default when omitted is max on glm5.3 and kimi-k3.1-pro, high on glm5.3-flash, deepseekv4.1-flash-1017, deepseekv4.1-flash-1017-interactive, and deepseekv4-pro, and no reasoning on gemma4; qwen38-27b thinks by default. none turns thinking off on deepseekv4.1-flash-1017, deepseekv4.1-flash-1017-interactive, deepseekv4-pro, and qwen38-27b. kimi-k3.1-pro always thinks: none, minimal, and xhigh return 400. Trace in message.reasoning_content; billed as completion tokens and counts toward max_tokens. On gemma4, reasoning is off unless this is set (low, high, or max).
Maximum tokens to generate in the completion, including reasoning tokens on reasoning models. Default 2048. Set explicitly when you need longer answers — a low limit can yield finish_reason: "length" with little or no visible content if reasoning consumes the budget.
Optional. Default false — omit or false for one JSON response. If true, the response is streamed as server-sent events and ends with a [DONE] line. Use stream_options.include_usage: true to receive a final usage chunk (including reasoning_tokens). That chunk has an empty choices array — do not assume choices[0] is present on every event.
Up to 4 stop sequences (string or array). Generated text excludes the matched sequence. On glm5.3, more than four entries may return 503 model_overloaded rather than 400.
Number of chat completion choices. Only 1 is supported (the default); values above 1 return 400 invalid_request_error. Send separate requests for more completions.
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.
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.
Controls tool calling: auto, none, required, or a named function object. required with an empty tools array returns 400. A named function that is not listed in tools returns 400.
An object specifying the format that the model must output. Setting { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which guarantees the model generates output matching the supplied JSON Schema. Setting { "type": "json_object" } enables the older JSON mode, which guarantees valid JSON but not a specific schema.
Additional model-specific options merged into the request. Must not duplicate a top-level field documented on this endpoint; duplicates return 400 invalid_request_error.
Top-k sampling. Omit or set to -1 to disable. Values >= 1 enable top-k; 0 is rejected. There is no documented upper bound.
Repetition penalty. Must be greater than 0 and at most 2. 0 and values above 2 are 400.
false limits a turn to a single tool call on every model.
Only valid with stream: true (otherwise 400). Must be a top-level field, not inside extra_body. Use {"include_usage": true} to receive token usage in the final SSE chunk.
If true, return log probabilities for output tokens (use with top_logprobs). Supported on sarvam-105b, gemma4, glm5.3-flash, deepseekv4.1-flash-1017, deepseekv4.1-flash-1017-interactive, deepseekv4-pro, and qwen38-27b. Not supported on glm5.3 or kimi-k3.1-pro (400 if enabled).
How many top token log probabilities to return at each position. Takes effect only when logprobs is true; without it, some models ignore the field and others return 400. Same model support as logprobs: works on sarvam-105b, gemma4, glm5.3-flash, deepseekv4.1-flash-1017, deepseekv4.1-flash-1017-interactive, deepseekv4-pro, and qwen38-27b; on glm5.3 and kimi-k3.1-pro, omit entirely — do not send 0, since many SDKs add it by default.
Response
A list of chat completion choices. Can be more than one if n is greater than 1.
The Unix timestamp (in seconds) of when the chat completion was created.
The object type, which is always chat.completion.
OpenAI-compatible backend fingerprint when available. Always null on glm5.3.