Chat Completion V2
Authentication
Bearer authentication of the form Bearer <token>, where token is your auth token.
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.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.gemma4— image input (inline base64) and tool calling.deepseekv4-flash— 1,048,576-token context window, tool calling, and reasoning.
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 (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.
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 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.
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.
Minimum probability mass. Must be between 0 and 1 inclusive. Outside that range is 400.
Repetition penalty. Must be greater than 0 and at most 2. 0 and values above 2 are 400.
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.
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 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).
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
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.