Gemma 4 is Google DeepMind's fourth-generation open model family, built on the same research foundation that powers Gemini 3. The 31B variant is the flagship dense model in the lineup: all 31 billion parameters activate on every token, giving you consistent, high-quality output with no sparsity tradeoffs.
On the LMArena text leaderboard, the 31B model scores 1452, competitive with models many times its size. For development teams that care about the cost-per-quality tradeoff, this is one of the most efficient paths to frontier-class performance available today.
| Model name | Gemma 4 31B |
|---|---|
| Architecture | Dense transformer |
| Parameters | 31B (fully dense) |
| Context window | 256,000 tokens |
| Input modalities | Text · Images (variable res.) · Video (up to 60s @ 1fps) |
| Output | Text |
| Attention mechanism | Hybrid sliding-window + global full-context |
| Multilingual | 35+ natively, pre-trained on 140+ |
| Function calling | Native (structured tool use) |
| Thinking mode | Configurable via <|think|> token |
| Training data cutoff | January 2025 |
| License | Apache 2.0 — commercial OK |
Gemma 4 31B uses a hybrid attention design that alternates between local sliding-window layers and global full-context layers, the final layer is always global. This combination means the model retains the low-memory characteristics of lightweight attention for most tokens while still building deep cross-document awareness where it counts. It's what makes the 256K context window practically usable rather than just theoretically possible.
Global attention layers apply Proportional RoPE (p-RoPE) and unified Keys and Values to keep memory consumption manageable on long inputs. Per-Layer Embeddings (PLE) give each decoder layer its own token-specific signal, a lightweight residual that lets the model specialize layer-by-layer without ballooning the parameter count. Shared KV caching at the tail layers eliminates redundant projections, reducing both memory pressure and latency for long-context generation.
Hybrid attentionAlternating local and global layers keep memory low while retaining deep contextual awareness across very long inputs.
Per-Layer EmbeddingsEach decoder layer receives its own token-specific residual signal for deeper specialization at minimal extra cost.
Shared KV cacheTail layers reuse key-value states, cutting memory and compute overhead on long-context generation without hurting quality.
Proportional RoPEp-RoPE handles position encoding in global attention layers, enabling accurate retrieval across the full 256K context.
Benchmarks don't tell the whole story, but they do give a useful reference point. The 31B dense model consistently competes with much larger closed-source models on reasoning and coding — particularly impressive given its fully open licensing and inference efficiency.

Gemma 4 31B combines hybrid attention, per-layer embeddings, and shared KV caching for efficiency on long inputs:
| Feature | Benefit |
|---|---|
| Hybrid attention | Alternates between sliding-window local layers and global full-context layers, keeping memory low while maintaining deep context awareness. |
| Per-Layer Embeddings (PLE) | Each decoder layer receives its own token-specific residual signal, enhancing layer specialization with minimal extra cost. |
| Shared KV cache | Tail layers reuse key-value states, reducing compute and memory overhead for long-context generation. |
| Proportional RoPE (p-RoPE) | Accurate position encoding across the full 256K context without excessive memory use. |
The combination of a 256K context window, native function calling, and multimodal input opens up a wide range of production use cases, from document-heavy enterprise tools to real-time coding assistants to multilingual consumer apps.
Gemma 4 31B supports native function calling and structured JSON output. You can define tools in the standard format and the model handles multi-step planning, tool invocation, and result interpretation. It can also output bounding boxes, making it unusually capable for browser automation, UI element detection, and screen-parsing agents.
At 256K tokens, you can feed the model an entire codebase, a full legal contract stack, a multi-year financial report, or a lengthy product specification, and ask coherent questions across the full body of text. The hybrid attention mechanism keeps this practical rather than just theoretical.
Gemma 4 31B processes images at variable resolution and aspect ratio. This makes it well-suited for OCR pipelines, form data extraction, invoice parsing, and any workflow where the model needs to read visual documents rather than just text files. Video input up to 60 seconds at 1 fps extends this to recorded demos, walkthroughs, and surveillance analysis.
Pre-trained on 140+ languages with native support for 35+, Gemma 4 31B handles multilingual customer support, content localization, cross-language document summarization, and translation workflows without requiring separate language-specific fine-tunes.
Google's training mix included substantial code data. The model handles code generation, completion, debugging, and review well and the configurable extended thinking mode (triggered via the <|think|> token) gives it space to reason through complex logic before producing output.
Gemma 4 ships in two workstation-class sizes. The 31B is a dense model; the 26B A4B is a Mixture-of-Experts (MoE) architecture with only 4B parameters active per token. Here's how to think about the choice:
| Model | Type | Active Parameters | Best For |
|---|---|---|---|
| 31B Dense | Fully dense | 31B | Reasoning-heavy tasks, long-document synthesis, code review |
| 26B MoE (A4B) | Mixture-of-Experts | 4B per token | High-volume, cost-sensitive inference, low-latency workflows |
Measured on the AI/ML API gateway across live traffic. Figures are medians unless stated. Last updated 2026-10-12.
Gemma 4 31B Instruct is documented as suited for chatbots and conversational AI, including customer service, virtual assistants, and interactive applications. It is also suited for text summarization, such as producing concise summaries of text corpora, research papers, and reports. Another documented use case is image data extraction, where it can extract, interpret, and summarize visual data into text communications. It is also documented for reasoning, coding, multimodal understanding, and agentic workflows.
import requests r = requests.post( "https://api.aimlapi.com/v1/chat/completions", headers={"Authorization": "Bearer " + AIMLAPI_KEY}, json={ "model": "google/gemma-4-31b-it", "messages": [ { "role": "user", "content": "Hello!" } ] }, ) print(r.json())
const r = await fetch("https://api.aimlapi.com/v1/chat/completions", { method: "POST", headers: { Authorization: `Bearer ${process.env.AIMLAPI_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify({ "model": "google/gemma-4-31b-it", "messages": [ { "role": "user", "content": "Hello!" } ] }), }); console.log(await r.json());
curl -X POST https://api.aimlapi.com/v1/chat/completions \ -H "Authorization: Bearer $AIMLAPI_KEY" \ -H "Content-Type: application/json" \ -d '{"model":"google/gemma-4-31b-it","messages":[{"role":"user","content":"Hello!"}]}'
OpenAI-compatible — swap the base URL and it works with your existing SDK.
| Type | Price |
|---|---|
| Input | |
| Output | |
| Cached input |
| Benchmark | Score | What it measures | Source | Retrieved |
|---|---|---|---|---|
| MMLU-Pro | 85.2% | Multi-discipline knowledge + reasoning (harder MMLU) | Source | July 13, 2026 |
| LiveCodeBench | 80.0% | Contamination-free competitive programming problems | Source | July 13, 2026 |
| GPQA Diamond | 84.3% | Google-proof graduate science questions (hardest subset) | Source | July 13, 2026 |
| Intelligence | 15.4 | Composite score across standardised reasoning, knowledge and problem-solving evaluations, measured independently by Artificial Analysis | Source | September 12, 2026 |
| Coding | 43.4 | Composite score across standardised coding evaluations, measured independently by Artificial Analysis | Source | September 12, 2026 |
| Model | Input | Output | Context | Best for |
|---|---|---|---|---|
Gemma 4 31B This page | Reasoning + agents | |||
| Reasoning + agents | ||||
| Balanced coding + agents | ||||
| Long-context, multimodal & agentic workflows | ||||
| Reasoning + agents |
Gemma 4 31B has a 256,000 tokens context window and can return up to 262,144 tokens.
Gemma 4 31B takes image, text as input and returns text.
Use google/gemma-4-31b-it as the model id. Requests go to https://api.aimlapi.com/v1/chat/completions.
Gemma 4 31B became available on April 3, 2026.
Gemma 4 31B is priced at input $1.361646 / 1M tokens, output $2.049346 / 1M tokens, cached input $1.361646 / 1M tokens.
Yes, Gemma 4 31B can stream responses as they are generated.
Yes, Gemma 4 31B accepts image input alongside text.
Gemma 4 31B was built by Google.