Chat Completion V2

Beta
View as Markdown
Creates a model response for the given chat conversation, using an OpenAI-compatible request and response shape. Requires `api-subscription-key` with beta access to this endpoint. **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`, `deepseekv4-flash`):** set `reasoning_effort` to **`low`**, **`high`**, or **`max`**. Default when omitted is **`max`** — omit the field or pass **`max`** for maximum reasoning. The trace is in `choices[].message.reasoning_content` and counts toward `max_tokens`. `gemma4` does not use reasoning on this route. 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.

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.
  • 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.
  • gemma4 — image input (inline base64) and tool calling.
  • deepseekv4-flash — 1,048,576-token context window, tool calling, and reasoning.
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 (glm5.3, deepseekv4-flash): low, high, or max. Default when omitted is max — omit this field or set max for maximum reasoning. Trace in message.reasoning_content; billed as completion tokens and counts toward max_tokens. Ignored on non-reasoning models such as gemma4.

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 nullOptional1-128Defaults to 1

Number of chat completion choices to generate per request. You are billed for tokens across all choices. Default 1. On glm5.3, only n: 1 is accepted; higher values return 400 invalid_request_error.

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.

min_pdouble or nullOptional0-1

Minimum probability mass. Must be between 0 and 1 inclusive. Outside that range is 400.

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 is correctly enforced (a single tool call) on gemma4 and deepseekv4-flash. On glm5.3 and sarvam-105b, false is accepted without error but is not enforced — the model may still return multiple tool calls in one turn.

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 and gemma4. Not supported on glm5.3 (400 if enabled) or deepseekv4-flash (returns 503 model_overloaded instead of a clean rejection — omit this field for that model).

top_logprobsinteger or nullOptional

How many top token log probabilities to return at each position when logprobs is true (otherwise 400). Same model support as logprobs: works on sarvam-105b and gemma4; on glm5.3 and deepseekv4-flash, 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
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