> For clean Markdown of any page, append `.md` to the page URL. > For a complete documentation index, see https://docs.sarvam.ai/llms.txt. > For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server. # Gemma 4 31B > Gemma 4 31B is a 31B-parameter instruction-tuned model for text and image understanding. It supports a 131,072-token context window and tool calling. 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**. > **Note** > > Gemma 4 31B is available in **beta** and is not specifically tuned for Indian > languages. Access is granted per API key, [contact us](/api/getting-started/help) to request access. ## At a glance | | | | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | | **Model ID** | `gemma4` | | **Best for** | Image captioning, classification, and visual question answering | | **Context window** | 131,072 tokens | | **Input → output** | Text and images → text | | **Reasoning** | No; answers are returned directly | | **Tool calling** | Supported | | **Log probabilities** | Supported on [Chat Completion V2](/api-reference/chat/chat-completions-v2) (`logprobs` / `top_logprobs`) | | **APIs** | [`POST /v2/chat/completions`](/api-reference/chat/chat-completions-v2) and [`POST /v2/responses`](/api-reference/responses/create) | | **Pricing** | ₹36.6 input · ₹13.73 cached input · ₹91.5 output per 1M tokens ([Pricing](/api/getting-started/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. #### Python ```python 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) ``` #### JavaScript ```javascript import { readFileSync } from "fs"; import { SarvamAIClient } from "sarvamai"; const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY", }); async function main() { const encoded = readFileSync("chart.png").toString("base64"); const response = await client.chat.completionsV2({ model: "gemma4", messages: [ { role: "user", content: [ { type: "text", text: "What trend does this chart show?" }, { type: "image_url", image_url: { url: `data:image/png;base64,${encoded}`, }, }, ], }, ], temperature: 1, top_p: 0.95, max_tokens: 500, }); console.log(response.choices[0].message.content); } main(); ``` #### cURL ```bash IMAGE_BASE64=$(base64 < chart.png | tr -d '\n') curl -X POST https://api.sarvam.ai/v2/chat/completions \ -H "api-subscription-key: $SARVAM_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @- < Gemma 4 31B is a 31B-parameter instruction-tuned model for text and image understanding. It supports a 131,072-token context window and tool calling.