Skip to navigation

Gemma 4 31B

View as Markdown

Gemma 4 31B is a 31B-parameter instruction-tuned model for text and image understanding. It accepts text and inline images with a 262,144-token context window. It answers directly by default and can reason first when you set reasoning_effort (see Reasoning).

Gemma 4 31B is not specifically tuned for Indian languages.

At a glance

Model IDgemma4
Best forImage captioning, classification, and visual question answering
Context window262,144 tokens
Input → outputText and images → text
ReasoningOff by default; turn it on with reasoning_effort. See Reasoning
Tool callingSupported
Log probabilitiesSupported on Chat Completion V2 (logprobs / top_logprobs)
APIsPOST /v2/chat/completions and POST /v2/responses
Pricing₹35 input · ₹10 cached input · ₹90 output per 1M tokens (Pricing)

Key capabilities

Image understanding

Caption, classify, and answer questions about images supplied as base64 data URIs.

Direct answers by default

Answers directly unless you ask it to reason first with reasoning_effort.

Tool calling

Use OpenAI-compatible tools and tool_choice for agentic workflows.

Streaming

Receive answer deltas as server-sent events.

Moving from OpenRouter, Fireworks AI, or Together AI? The migration guides map model IDs and request fields to Sarvam.

Quickstart

The examples send a local image as a base64 data URI. Remote image URLs are not supported.

import base64
from sarvamai import SarvamAI
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
with open("chart.png", "rb") as image:
encoded = base64.b64encode(image.read()).decode("utf-8")
response = client.chat.completions_v2(
model="gemma4",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What trend does this chart show?"},
{
"type": "image_url",
"image_url": {"url": f"data:image/png;base64,{encoded}"},
},
],
}
],
temperature=1,
top_p=0.95,
max_tokens=500,
)
print(response.choices[0].message.content)

Reasoning

Gemma 4 answers directly by default. To have it reason before answering, set an effort level:

RouteFieldAccepted values
Chat Completion V2reasoning_effort"low", "high", or "max". Omitting the field (or "none") means no reasoning
Responsesreasoning.effort"low" or "high". Omitting the field means no reasoning

On chat, read the reasoning trace from choices[].message.reasoning_content. Reasoning tokens are billed as output tokens and count against max_tokens / max_output_tokens.

Supported parameters

model: "gemma4" on Chat Completion V2 and Responses. Full request/response schemas live on those API reference pages; this table covers what’s actually accepted for this model.

ParameterChat Completion V2Responses
Streaming (stream)
Tool calling (tools, tool_choice)
parallel_tool_calls: false enforced
Structured output (response_format / text.format)
Log probabilities (logprobs, top_logprobs) 400
Multiple choices (n > 1) 400
Reasoning controlreasoning_effort: low, high, or max; off when omittedreasoning.effort: low or high; off when omitted

400 is invalid_request_error. Images must be base64 data URIs in image_url content parts (remote URLs are rejected).

Limits and errors

AreaLimit or conditionAPI responseRecommended action
ContextPrompt tokens plus max_tokens exceed 262,144400 invalid_request_errorShorten the prompt, send fewer images, or reduce max_tokens.
Outputmax_tokens exceeds 262,144400 invalid_request_errorSet max_tokens within the context window.
Request sizeRequest body exceeds 10 MiB (10,485,760 bytes)413 invalid_request_error, with the limit in the messageReduce the request body; base64 images count toward the limit.
Image URLAn image_url uses an http(s) URL400 invalid_request_errorInline the image as a base64 data URI.
ToolsThe tool schema is invalid400 invalid_request_errorCheck the schema requirements in Chat Completion V2.
AuthenticationAPI key is missing or invalid403 invalid_api_key_errorCheck the api-subscription-key header.
ModelModel ID is unknown or unavailable404 not_found_errorConfirm the ID with GET /v2/models.
QuotaNo credits remain402 insufficient_quota_errorAdd credits in the dashboard.
Rate limitRequest or concurrency limit is exceeded429 rate_limit_exceeded_errorBack off and retry.
AvailabilityModel remains overloaded after retries503 model_overloadedRetry later.