Speed
Output tokens / second
Custom pricing for production workloads
Google DeepMind's Gemma 4 31B is the most capable open-weight model in its class, delivering frontier-level reasoning, native multimodal understanding, and a 256K-token context window under a fully commercial Apache 2.0 license.
Whether you’re building real-time coding assistants, enterprise-grade document analyzers, or multilingual applications, Gemma 4 31B provides reliable, high-quality output with fast inference, unified billing, and high rate limits.
google/gemma-4-31b-ithttps://api.aimlapi.com/v1Gemma 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.
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.
See how Gemma 4 31B compares in generation speed and latency. Data retrieved Nov 3, 2026.
Output tokens / second
Compare 6 models available on AI/ML API across 5 independent benchmarks.
Expert-written questions across academic subjects.
Graduate-level science questions written to resist web search.
Agentic tasks completed in a command-line environment.
Reasoning across long documents of about 100k tokens.
Python coding tasks drawn from scientific research.
| Usage | Price | Unit |
|---|---|---|
| Input | $1.05 | 1M tokens |
| Output | $1.58 | 1M tokens |
| Cached input | $1.05 | 1M tokens |
Prices from the AI/ML API price list, checked on Nov 4, 2026.
AI/ML API input and output rates for 5 models, per million tokens.
| Model | Input | Output |
|---|---|---|
| $1.05 | $1.58 | |
| $0.3 | $2.5 | |
| $0.75 | $3.75 | |
| $0.75 | $3.75 | |
| $2 | $10 |
Give your agent the model details, code and documentation.
export AIMLAPI_KEY="8f2b4c7d9a1e6b3f…"curl '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": "Write a haiku about the ocean."
}
]
}'import os
import requests
headers = {
"Authorization": f"Bearer {os.environ['AIMLAPI_KEY']}",
"Content-Type": "application/json",
}
payload = {
"model": "google/gemma-4-31b-it",
"messages": [
{
"role": "user",
"content": "Write a haiku about the ocean."
}
]
}
response = requests.post("https://api.aimlapi.com/v1/chat/completions", headers=headers, json=payload, timeout=120)
response.raise_for_status()
print(response.json())const response = 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": "Write a haiku about the ocean."
}
]
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());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 costs $1.05 input and $1.58 output per 1M tokens on AI/ML API, billed as you go with no subscription.
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.