Gemma 4 31B

View as Markdown

Gemma 4 31B is an open-source model served by Sarvam in beta, and is not tuned for Indian languages. Beta access is granted per API key — contact us to request whitelisting. For Indian language workloads use Sarvam-105B; for document and image understanding in Indian languages, use Sarvam Vision.

A 31B-parameter instruction-tuned model. Its distinguishing feature on Sarvam is image input — it is the only chat model here that accepts images alongside text in the chat completions format.

At a Glance

Model IDgemma4
What it doesChat LLM with image understanding
LanguagesNot tuned for Indian languages by Sarvam
APIsOpen-Source Models API Reference (POST /v2/chat/completions, OpenAI-compatible, streaming supported) — also see using an open-source model
Input limits131,072-token context window; images as base64 data URIs only; 10 MB request cap — all limits
BenchmarksNone published by Sarvam
Pricing₹36.6 input · ₹13.73 cached input · ₹91.5 output — per 1M tokens (Pricing)
Best forImage captioning, classification, and visual question answering
Not forIndian language workloads or document OCR — use Sarvam-105B or Sarvam Vision

Why you might use it

Image understanding

Accepts images inline as base64 data URIs in the standard image_url content part, so you can caption, classify, or answer questions about images.

Direct answers

Not a reasoning model — it replies without a chain-of-thought pass, so the whole token budget goes to the answer.

Model Specifications

Key Considerations
  • Model ID: gemma4
  • Context window: 131,072 tokens (128K)
  • Image input: supported — base64 data URIs only
  • Tool calling: supported
  • Reasoning: none — answers directly, never returns reasoning_content, and reasoning_effort has no effect
  • Maximum request size: 10 MB (inclusive of encoded images)
  • Temperature range: 0 to 2 (unset uses the model’s own default)
  • Top-p range: greater than 0, up to 1
  • Supports streaming and non-streaming responses
  • OpenAI-compatible chat completions format

Each image is estimated at roughly 1,024 tokens when Sarvam checks your request against the context window. Budget for this when sending several images with a long prompt.

Gemma 4 31B vs other options

FeatureGemma 4 31BGLM-5.2Sarvam-105BSarvam Vision
Context window131,072524,288128,000
Image input✅ (documents)
Tool calling
Indian language tuningNoneNone23 languages23 languages
Best forImage + text tasksVery long-context tasksIndian-language chat & agentic workDocument OCR & extraction

For document understanding — scanned forms, invoices, PDFs, especially in Indian languages — use Sarvam Vision, which is purpose-built for OCR and structured extraction. Use gemma4 for general images where you want a conversational answer rather than structured document output.

Key Capabilities

A text-only single-turn request. Only the model field differs from a Sarvam chat completion call.

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="gemma4",
7 messages=[
8 {"role": "user", "content": "Classify this support ticket as billing, technical, or other: 'My invoice shows twice the usage I expected.'"}
9 ],
10 temperature=0.1,
11 max_tokens=100,
12)
13
14print(response.choices[0].message.content)

Parameters

Gemma 4 31B accepts the standard OpenAI-compatible parameter set — temperature, top_p, max_tokens, stream, stop, n, seed, frequency_penalty, presence_penalty, response_format (Structured Outputs), tools, and tool_choice. See the full parameter table for types, defaults, and ranges.

Model-specific notes:

  • Images must be base64 data URIs — remote http(s) URLs are rejected.
  • No reasoning — the model answers directly, never returns reasoning_content, and reasoning_effort is accepted but has no effect.
  • seed is reproducible — identical seed and parameters return identical output in current serving.
  • Don’t ask for JSON in the prompt when response_format is set — an instruction like “Return JSON” alongside a JSON response format makes the model emit whitespace until it exhausts max_tokens, billing the full budget for no usable output. Let response_format handle the shape.

Limits and errors

Common errors for every model on /v2/chat/completions are documented on the Open-Source Models overview. Gemma-4-specific cases:

ConditionStatusCodeWhat it means
API key lacks beta access400invalid_request_errorRequest whitelisting — see Beta APIs.
Missing or invalid API key403invalid_api_key_errorCheck the api-subscription-key header.
No credits remaining402insufficient_quota_errorTop up on the dashboard.
Unknown or unavailable model id404not_found_errorConfirm the id with GET /v2/models.
image_url pointing at an http(s) URL400invalid_request_errorInline the image as a base64 data URI instead.
max_tokens above 131,072400invalid_request_errormax_tokens cannot exceed the context window.
Estimated prompt tokens + max_tokens above 131,072422unprocessable_entity_errorShorten the prompt, send fewer images, or lower max_tokens.
Request body above the model’s size cap413invalid_request_errorEncoded images count toward this cap.
Invalid tool schema400invalid_request_errorSee Tool schemas.
Whitespace-only reply with finish_reason: "length"200response_format was combined with a “return JSON” instruction in the prompt — remove the instruction.

Support

Sarvam supports the serving layer — auth, billing, rate limits, availability. Sarvam does not tune or evaluate this model, so its output quality, reasoning, and language coverage are properties of the model itself. See Open-Source Models for the full support boundary, and Talk to us for serving issues.