Chat Completion API
Use the Chat Completion API to build conversational AI experiences with native support for Indian languages and deep contextual reasoning. Sarvam provides two versions: V1 for Sarvam models and beta V2 for Sarvam and open-weight models.
Use the Sarvam chat skill to generate correct chat completion code from your AI coding assistant:
See Agent Skills for the full list.
Our Chat Completion APIs support the following chat models:
Simply pass the model name as the model parameter (e.g., model="sarvam-105b" or model="sarvam-105b-conversations").
Endpoints: POST /v1/chat/completions serves sarvam-105b and
sarvam-105b-conversations. POST /v2/chat/completions serves sarvam-105b,
glm5.3, gemma4, and deepseekv4-flash. See Open-Weight Models.
Token budgeting: the context length covers everything, your messages, any reasoning_content the model produces in think mode, and the generated reply (capped by max_tokens, default 2048). Reasoning tokens are billed as completion tokens, so high reasoning_effort increases both latency and cost. For long conversations, trim or summarize older turns instead of resending the full history.
Authentication: like every Sarvam API, this endpoint uses the api-subscription-key header. It additionally accepts Authorization: Bearer <key> for OpenAI-compatible tooling. See Authentication for details.
Sarvam-M (24B) has been deprecated and is no longer available through the Chat Completions API. Please migrate to Sarvam-105B for improved performance.
V1 Chat Completion
POST /v1/chat/completions supports sarvam-105b and
sarvam-105b-conversations. Use V1 for Sarvam’s flagship and conversational
models. See the Chat Completion V1 API Reference
for the complete request and response schema.
V2 Chat Completion (Beta)
POST /v2/chat/completions supports sarvam-105b, glm5.3, gemma4, and
deepseekv4-flash. Use V2 for the OpenAI-compatible beta API and open-weight
models. See the Chat Completion V2 API Reference
for the complete request and response schema.
Beta access: V2 requires whitelisting per API key. Without access you get
400 invalid_request_error before the model runs. See
Beta APIs.
V2 behavior (all models)
- Model IDs are case-sensitive. An unknown ID returns
404 not_found_error. - Auth failures return
403, not401, withinvalid_api_key_error. - Structured output is available on both V1 and V2 through
response_format; on V2, useclient.chat.completions_v2. See the Chat Completion V2 API Reference. - Parallel tool calls behave differently by model and route. On Chat Completions,
parallel_tool_calls: falseis correctly enforced ongemma4anddeepseekv4-flash, but not onglm5.3orsarvam-105b, those two may still return more than one tool call even withfalseset. On the Responses API,falseisn’t currently enforced for any model that supports tool calling there. - Reasoning (
glm5.3,deepseekv4-flash) has three modes:low,high, andmax. Chat Completions accepts all three directly for both models. On the Responses API, DeepSeek V4 Flash also accepts all three directly, but GLM-5.3 only acceptsloworhigh, to getmax-level reasoning from GLM-5.3 there, omit thereasoningfield entirely, since the literal string"max"returns400. See Open-Weight Models, Reasoning. - Streaming is optional on both V2 Chat Completions and Responses. Omit
streamor set it tofalsefor a single JSON response (the default), ortruefor server-sent events. - Log probabilities (
logprobs/top_logprobs) on Chat Completions V2 are supported onsarvam-105bandgemma4. They aren’t supported onglm5.3, which returns a clean400, or ondeepseekv4-flash, which returns a503 model_overloadedinstead of a clean rejection, omit the field for that model.
GLM-5.3 and other open-weight models
Open-weight models on V2 have model-specific limits around context size, n, log
probabilities, tool-call flags, and stop-sequence behavior. See
GLM-5.3, Known limitations
and the other Open-Weight model guides.
V2 limits (summary)
The Limits table at the bottom of this page applies to V1
(sarvam-105b / sarvam-105b-conversations), not V2 open-weight models.
Features
V1 features and examples
Basic Chat Completion
Multi-turn Conversation
Hindi (Indic Script)
Because thinking mode is on by default, a low max_tokens (e.g. under a few hundred) can be consumed entirely by reasoning, you’ll get finish_reason: "length" with an empty content and only reasoning_content populated. Either keep max_tokens generous or disable reasoning with reasoning_effort=None for short replies.
Streaming
Set stream: true to receive the response incrementally over server-sent events instead of waiting for the full completion. This is essential for responsive chat UIs and voice-agent pipelines, where you want to start rendering (or speaking) the reply as soon as the first tokens arrive.
Both SDKs return an iterator of chat.completion.chunk objects. Each chunk carries a delta with the new portion of the message, delta.content for the reply text and, when reasoning is enabled, delta.reasoning_content for thinking tokens.
Over raw HTTP, each event is a data: line containing a chat.completion.chunk JSON object. The final data chunk carries usage (with an empty choices array), and the stream ends with data: [DONE]:
When reasoning_effort is set, thinking tokens stream first via delta.reasoning_content, followed by the reply via delta.content. Check both fields if you display reasoning to users.
Tool Calling (Function Calling)
Describe functions your application exposes with the tools parameter, and the model will decide when to call them, returning the function name and JSON arguments instead of (or alongside) a text reply. You execute the function yourself, append the result as a tool message, and call the API again so the model can produce its final answer.
The flow is:
- Send the conversation plus
toolsdefinitions. - If the model wants a tool, the response has
finish_reason: "tool_calls"andmessage.tool_callswith the function name and stringified JSONarguments. - Run the function, append the assistant message and a
{"role": "tool", "tool_call_id": ..., "content": ...}message with the result. - Call the API again, the model answers using the tool output.
A tool-call response looks like:
Controlling tool use with tool_choice
function.arguments is a JSON string, not an object, always parse it (and validate against your schema) before executing the function.
Structured Outputs (JSON)
The Chat Completions API supports the OpenAI-compatible response_format parameter for getting reliably structured JSON:
Structured Outputs with json_schema
Pass a JSON Schema under json_schema.schema, and set "strict": true to enforce adherence. The structured reply arrives as a JSON string in message.content, parse it before use.
Both /v1/chat/completions and /v2/chat/completions expose response_format
as a typed SDK parameter. On V2, call client.chat.completions_v2; see the
Chat Completion V2 API Reference.
The json_schema object accepts:
JSON mode with json_object
When you only need valid JSON without enforcing a specific structure, use {"type": "json_object"} and describe the desired shape in your prompt:
Even with Structured Outputs, validate the parsed JSON against your expected schema (e.g. with pydantic or zod) before acting on it, the schema constrains the model’s output shape, but your application logic may have stricter requirements (value ranges, business rules, etc.).
Alternative: Tool calling as a JSON schema
If your workflow is already built around tool calling, you can also get structured output by defining a single tool whose parameters schema describes the structure you want, and forcing it with tool_choice. The model’s arguments are then constrained to the schema.
Alternative: Prompt-based JSON
For simple cases, you can also instruct the model to reply with JSON only, set a low temperature, and validate the output before using it (consider JSON mode instead, which guarantees valid JSON):
Always validate model-produced JSON against your expected schema (e.g. with pydantic or zod) and add a retry path, prompt-based JSON is good, but not guaranteed.
API Response Format
Success Response Structure
Response Fields
Error Responses
All errors return a JSON object with an error field (message, code, request_id). The full error-code table, retry guidance, and SDK exception reference live on the central Errors & Troubleshooting page.
Errors specific to this endpoint:
Error Handling Code Example
Limits
Check out the Chat Completion V1 API Reference to explore Chat Completion and all available options.