Gemma 4 31B

Beta
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 131,072-token context window.

Gemma 4 31B is available in beta and is not specifically tuned for Indian languages. Access is granted per API key — contact us to request access.

At a glance

Model IDgemma4
Best forImage captioning, classification, and visual question answering
Context window131,072 tokens
Input → outputText and images → text
ReasoningNo; answers are returned directly
Tool callingSupported
Log probabilitiesSupported on Chat Completion V2 (logprobs / top_logprobs)
APIsPOST /v2/chat/completions and POST /v2/responses
Pricing₹36.6 input · ₹13.73 cached input · ₹91.5 output per 1M tokens (Pricing)

Key capabilities

Image understanding

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

Direct answers

Receive the answer without a separate reasoning pass.

Tool calling

Use OpenAI-compatible tools and tool_choice for agentic workflows.

Streaming

Receive answer deltas as server-sent events.

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)

API reference

Call POST /v2/chat/completions or POST /v2/responses with model: "gemma4". Request fields (logprobs, stream, tools, image parts, and the rest) are defined in those API references — not duplicated on this model page.

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 131,072422 unprocessable_entity_errorShorten the prompt, send fewer images, or reduce max_tokens.
Outputmax_tokens exceeds 131,072400 invalid_request_errorSet max_tokens within the context window.
Request sizeRequest body exceeds 10 MB413 invalid_request_errorReduce the request body; base64-encoded images count toward the limit.
Image URLAn image_url uses an http(s) URL400 invalid_request_errorInline the image as a base64 data URI.
Structured outputresponse_format is combined with a JSON instruction in the prompt200 with whitespace output and finish_reason: "length"Remove the duplicate JSON instruction from the prompt.
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.
AccessAPI key does not have beta access400 invalid_request_errorRequest beta access.
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.