Open-Source Models

View as Markdown

Alongside its own models, Sarvam serves a small set of open-source models. You reach them through the same chat completions API, with the same API key, credits, and rate limits — only the model field changes.

Available in beta. GLM-5.2 and Gemma 4 31B are rolling out gradually — your API key must be whitelisted for beta access before these models respond. A key without access is refused with 400 invalid_request_error before the model is called. Contact us to request access.

This page focuses on the open-source models on /v2. The same endpoint also serves sarvam-105b — see Sarvam-105B. sarvam-105b-conversations is on /v1 only. Call GET /v2/models to see which IDs your key can use.

These models are not tuned for Indian languages. For Indian languages, Indic scripts, or code-mixed input, use Sarvam’s own models — they are trained and evaluated for it. Reach for an open-source model when you need a capability Sarvam’s models do not offer, such as a very large context window or image input.

Available models

Capabilities at a glance

Model IDContext windowTool callingImage inputReasoning output
glm5.2524,288 tokens✅ always on — see Reasoning output
gemma4131,072 tokens❌ answers directly

For comparison, Sarvam’s flagship chat model sarvam-105b supports tool calling with 128K context and is tuned for 23 languages (22 Indian + English).

Using an open-source model

Open-source models are served on /v2/chat/completions. The same endpoint also accepts sarvam-105b. Sarvam chat models — including sarvam-105b-conversations — are on /v1; /v1 does not accept glm5.2 or gemma4.

Authentication uses the api-subscription-key header. A missing or invalid key is refused with 403 invalid_api_key_error. GET /v2/models and GET /v2/models/{model_id} are unauthenticated and list only the models available to you.

Use the Sarvam SDKclient.open_source_models.chat_completions_v2(...) in Python, or client.openSourceModels.chatCompletionsV2(...) in JavaScript.

1from sarvamai import SarvamAI
2
3client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
4
5response = client.open_source_models.chat_completions_v2(
6 model="glm5.2",
7 messages=[
8 {"role": "user", "content": "Summarise the causes of the 2008 financial crisis."}
9 ],
10 temperature=0.2,
11 max_tokens=1000,
12)
13
14print(response.choices[0].message.content)

Model selection

In most cases the answer is a Sarvam model — reach for an open-source model only when you need a capability Sarvam’s own models do not have.

If you need…UseWhy
Indian languages, Indic scripts, romanised or code-mixed inputsarvam-105bTrained and evaluated for it
Highest quality reasoning or agentic worksarvam-105bFlagship model, Sarvam-published benchmarks
Wikipedia-grounded factual answers (wiki_grounding)sarvam-105bSarvam models only — not available on the open-source models
More than 128K of context in one requestglm5.2512K context window — 4× the Sarvam chat models
Image input with a conversational answergemma4The only chat model here that accepts images
Document OCR or structured extractionSarvam VisionPurpose-built for documents — better than gemma4 for forms, invoices, PDFs
Visible chain-of-thought (reasoning_content)glm5.2Reasons before every answer and returns the trace — see Reasoning output

The two are not interchangeable. glm5.2 reasons before every answer but cannot see images; gemma4 sees images but never produces reasoning. Both support tool calling.

Supported parameters

These models accept the same OpenAI-compatible parameters as Sarvam’s chat models, with the exceptions called out below. Support differs per model where the model itself lacks the capability.

ParameterTypeDefaultglm5.2gemma4Notes
messagesarray— (required)The conversation so far. At least one message.
modelstring— (required)glm5.2 or gemma4. Must be an id returned by GET /v2/models.
max_tokensinteger2048Must be ≤ the model’s context window. Estimated prompt tokens + max_tokens must fit inside the window, or the request is rejected with 422. On glm5.2 this budget also covers reasoning — see Reasoning output.
temperaturenumber0.5 if reasoning_effort is set, else 0.202. Prefer altering this or top_p, not both.
top_pnumber1>01 (0 is rejected). Prefer altering this or temperature, not both.
streambooleanfalseServer-sent events. Errors after the stream starts arrive as an SSE error frame before [DONE].
stopstring or arraynullUp to 4 stop sequences; not included in the output.
ninteger11128. You are billed for tokens across all choices — keep at 1 unless you need multiple completions.
seedintegernull⚠️Beta, best-effort determinism. In current serving gemma4 returns identical output for an identical seed and parameters; glm5.2 does not.
frequency_penaltynumber0-22. Penalises tokens by existing frequency, reducing verbatim repetition.
presence_penaltynumber0-22. Penalises tokens already present, encouraging new topics.
reasoning_effortstringnulllow, medium, or high. glm5.2 reasons even when this is unset; gemma4 accepts the parameter but never produces reasoning. See Reasoning output.
response_formatobjectnull{type: "text"}, {type: "json_object"}, or {type: "json_schema", json_schema: {...}}. On glm5.2, turn thinking off — see Structured Outputs.
toolsarraynullOpenAI-compatible function calling. Max 128 tools; the model must support tools.
tool_choicestring or objectnullnone, auto, required, or a named function. Requires tools when set to required or a function name — otherwise 422.
extra_bodyobject{}Model-specific options forwarded unchanged. Must not repeat any field in this table or carry stream_options; a collision is rejected with 400. Carries chat_template_kwargs, e.g. the thinking switch below.
image_url content partobjectglm5.2 returns 400. gemma4 accepts base64 data URIs only — remote URLs are rejected. See Image input.

Full request and response schema: Open-Source Models API Reference.

OpenAI-compatible fields not listed above — logprobs, logit_bias, user, and similar — are accepted but ignored. Unknown fields inside extra_body that the model backend does not recognise are rejected.

wiki_grounding is not part of the /v2 schema. For Wikipedia grounding, use sarvam-105b on /v1.

Reasoning output

glm5.2 is a reasoning model: it thinks before every answer, whether or not reasoning_effort is set. The chain-of-thought arrives in a separate reasoning_content field on the message — content holds only the final answer — and in streaming responses it arrives as delta.reasoning_content chunks before the answer starts. Reasoning tokens are billed as completion tokens and count against max_tokens, so a budget that is too small is consumed entirely by reasoning and the request returns content: null with finish_reason: "length".

To turn reasoning off — faster, cheaper, and the whole budget goes to the answer — send the thinking switch through extra_body:

1{
2 "extra_body": {
3 "chat_template_kwargs": { "enable_thinking": false }
4 }
5}

gemma4 is not a reasoning model. It answers directly, never returns reasoning_content, and setting reasoning_effort on it has no effect.

Structured Outputs

response_format works on both models. Use {"type": "json_schema", "json_schema": {...}} to constrain output to a JSON Schema, or {"type": "json_object"} for the older JSON mode, which guarantees valid JSON but not a specific shape.

On glm5.2, turn thinking off whenever you set response_format (as in the example below). With reasoning active, a JSON-constrained request returns content: null — the reasoning trace and the JSON grammar conflict, and no answer is produced. With enable_thinking: false the same request returns clean JSON reliably.

1import json
2
3from sarvamai import SarvamAI
4
5client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
6
7response = client.open_source_models.chat_completions_v2(
8 model="glm5.2",
9 messages=[
10 {"role": "user", "content": "List two Indian cities with their populations."}
11 ],
12 max_tokens=500,
13 extra_body={
14 "chat_template_kwargs": {"enable_thinking": False}
15 },
16 response_format={
17 "type": "json_schema",
18 "json_schema": {
19 "name": "city_list",
20 "strict": True,
21 "schema": {
22 "type": "object",
23 "properties": {
24 "cities": {
25 "type": "array",
26 "items": {
27 "type": "object",
28 "properties": {
29 "name": {"type": "string"},
30 "population": {"type": "integer"},
31 },
32 "required": ["name", "population"],
33 "additionalProperties": False,
34 },
35 }
36 },
37 "required": ["cities"],
38 "additionalProperties": False,
39 },
40 },
41 },
42)
43
44cities = json.loads(response.choices[0].message.content)
45print(cities)

On the Python SDK, pass extra_body and response_format as direct keyword arguments to chat_completions_v2 (as above). On /v1/chat/completions, the chat client does not expose response_format as a typed parameter — use request_options={"additional_body_parameters": {"response_format": ...}} instead; see Structured Outputs.

Don’t also ask for JSON in the prompt. When response_format is set, an instruction like “Return JSON” in the message makes gemma4 emit whitespace until it exhausts max_tokens — you are billed for the full budget and get no usable output. State the task in the prompt and let response_format handle the shape.

Image input

Only gemma4 accepts images, and only as base64 data URIs. A remote http:// or https:// URL is rejected — the API does not fetch images on your behalf. Full example on the Gemma 4 31B page.

1{
2 "type": "image_url",
3 "image_url": { "url": "data:image/png;base64,<encoded bytes>" }
4}

Each image counts against the request-size cap once encoded. Prompt and request-size checks use estimates — text at roughly 4 bytes per token, plus a flat per-image allowance — rather than an exact tokenizer count.

Tool schemas

function.parameters must be a JSON Schema object; a property defined as a bare string is rejected. When tool_choice forces a call (required or a named function), schemas must be self-contained: non-local $ref, unresolved $ref, recursive schemas, or a combined expansion above 20,000 nodes across all tools in the request are rejected with 400.

Errors

Every error uses the same envelope — error.message, error.code, and error.request_id (empty when the error is raised before a request id is assigned):

1{
2 "error": {
3 "message": "Model 'gpt-4' not found.",
4 "code": "not_found_error",
5 "request_id": "20260729_0f1e2d3c-…"
6 }
7}
StatusCodeRaised when
400invalid_request_errorBody fails validation, the model lacks a requested capability, the key lacks beta access to this endpoint, or extra_body collides with a validated field
402insufficient_quota_errorNo credits available
403invalid_api_key_errorMissing or invalid API key
404not_found_errorUnknown model id, or a model not available to your key
413invalid_request_errorRequest size exceeds the model’s cap
422unprocessable_entity_errorPrompt + max_tokens exceeds the context window, tool_choice forced without tools, or the model rejected the request
429rate_limit_exceeded_errorRate or concurrency limit; may carry Retry-After
500internal_server_errorUnhandled failure
502model_call_failedThe model call failed and could not be retried
503model_overloadedTimeout, connection failure, or overload after automatic retries

Timeouts, connection failures, and overload are retried automatically before a 503 is returned. A request the model itself rejects is not retried and comes back as 422.

Support and expectations

Sarvam supports the serving layer: availability, authentication, billing, rate limits, and API compatibility. If a request fails with a Sarvam error — an auth failure, a rate limit, a credits problem, a malformed response from our gateway — contact us.

Sarvam does not tune, evaluate, or publish benchmarks for these models, and does not guarantee their output quality. A model’s reasoning, factual accuracy, language coverage, and refusals are properties of the model itself rather than of Sarvam’s serving.

These models may be updated, versioned, or withdrawn on a different schedule from Sarvam’s own models. Do not assume one of these model IDs is a long-term stable contract — check the changelog before depending on one in production.

Each model carries its own open-source licence and acceptable-use terms, which apply to you as the end user in addition to Sarvam’s terms. Review the model’s licence before using it in a commercial product.

Shared behaviour

Everything below applies to both models:

  • EndpointPOST https://api.sarvam.ai/v2/chat/completions. Full parameter reference: Open-Source Models API Reference.
  • Model discoveryGET https://api.sarvam.ai/v2/models lists the model IDs the endpoint currently serves.
  • Authenticationapi-subscription-key: sk_xxx. Invalid keys return 403 invalid_api_key_error. See Authentication.
  • Beta access — granted per key. Without access, the endpoint returns 400 invalid_request_error before calling the model. See Access to Beta APIs.
  • Streaming — set "stream": true for server-sent events.
  • Billing — metered per token against your Sarvam credits, reasoning tokens included. Per 1M tokens (input / cached input / output): gemma4 ₹36.6 / ₹13.73 / ₹91.5, glm5.2 ₹128.1 / ₹23.79 / ₹402.6. The two are not priced alike — glm5.2 costs roughly 3.5× gemma4, and it reasons before every answer, so budget max_tokens deliberately. See Pricing.
  • Rate limits — applied per API key. See Credits & Rate Limits.