Skip to navigation

Chat Completion V2

View as Markdown

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

api-subscription-keystring
API Key authentication via header
OR
AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.

Headers

x-session-affinitystringOptional

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

This endpoint expects an object.
messageslist of objectsRequired

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.

modelenumRequired

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 in reasoning_content (billed as completion tokens); tool calling; max request size 10,485,760 bytes; n must be 1.
  • 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 as deepseekv4.1-flash-1017.
  • deepseekv4-pro (Provisioned Throughput) — 1,000,000-token context window; text input only; tool calling; reasoning (default high; none turns 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 (default max).
  • qwen38-27b (Provisioned Throughput) — 262,144-token context window; image input (inline base64); tool calling; reasoning on by default (none turns it off).
temperaturedouble or nullOptional0-2Defaults to 1

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.

top_pdouble or nullOptional<=1Defaults to 0.95

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.

reasoning_effortenum or nullOptional

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).

Allowed values:
max_tokensinteger or nullOptional>=1Defaults to 2048

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.

streamboolean or nullOptionalDefaults to false

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.

stopstring or list of strings or nullOptional

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.

ninteger or nullOptional=1Defaults to 1

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.

seedinteger or nullOptional-9223372036854776000-9223372036854776000
Optional integer seed for OpenAI SDK compatibility.
frequency_penaltydouble or nullOptional-2-2Defaults to 0

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.

presence_penaltydouble or nullOptional-2-2Defaults to 0

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.

toolslist of objects or nullOptional
A list of tools the model may call. Currently, only functions are supported as a tool.
tool_choiceenum or object or nullOptional

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.

response_formatobject or nullOptional

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.

extra_bodymap from strings to anyOptionalDefaults to {}

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_kinteger or nullOptional>=-1

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_penaltydouble or nullOptional<=2

Repetition penalty. Must be greater than 0 and at most 2. 0 and values above 2 are 400.

parallel_tool_callsboolean or nullOptional

false limits a turn to a single tool call on every model.

stream_optionsobject or nullOptional

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.

logprobsboolean or nullOptional

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).

top_logprobsinteger or nullOptional

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

Successful Response
idstring
A unique identifier for the chat completion.
choiceslist of objects

A list of chat completion choices. Can be more than one if n is greater than 1.

createdinteger

The Unix timestamp (in seconds) of when the chat completion was created.

modelstring
The model used for the chat completion.
object"chat.completion"

The object type, which is always chat.completion.

service_tierstring or nullOptional
system_fingerprintstring or nullOptional

OpenAI-compatible backend fingerprint when available. Always null on glm5.3.

usageobject or nullOptional

Errors

400
Bad Request Error
401
Unauthorized Error
402
Payment Required Error
403
Forbidden Error
404
Not Found Error
413
Content Too Large Error
429
Too Many Requests Error
502
Bad Gateway Error
503
Service Unavailable Error