Gemma 4 31B API

google/gemma-4-31b-it
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.
Context
256K tokens
Input
$1.04742 / 1M tokens
Output
$1.57642 / 1M tokens
Released
Apr 3, 2026

Overview

What is Gemma 4 31B?

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 specs at a glance

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

API Pricing

  • Input: $0.156 per 1MTok
  • Output: $0.481 per 1MTok

What powers the performance

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 attention

Alternating local and global layers keep memory low while retaining deep contextual awareness across very long inputs.

Per-Layer Embeddings

Each decoder layer receives its own token-specific residual signal for deeper specialization at minimal extra cost.

Shared KV cache

Tail layers reuse key-value states, cutting memory and compute overhead on long-context generation without hurting quality.

Proportional RoPE

p-RoPE handles position encoding in global attention layers, enabling accurate retrieval across the full 256K context.

Gemma 4 31B Benchmark Results

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.

__wf_reserved_inherit
Benchmarks show relative performance within the Gemma 4 family and general competitive range. LMArena score is the estimated text-only score reported at launch.

Performance Architecture: Why It’s Fast and Efficient

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.

What Developers Are Building With Gemma 4 31B

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.

Agentic Workflows and Tool Use

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.

Long-Document Understanding

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.

Multimodal Document Processing

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.

Multilingual Applications

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.

Code Generation and Review

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 31B vs. the 26B MoE — Which Should You Use?

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

Uptime and performance

  • Uptime (24h): 100%
  • Uptime (7d): 100%
  • Availability (24h): 50.0%
  • Error rate (24h): 50.0%

Measured on the AI/ML API gateway across live traffic. Figures are medians unless stated. Last updated 2026-10-12.

Use cases

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.

How to use Gemma 4 31B API

Install any OpenAI-compatible SDK, point it at api.aimlapi.com/v1, and set the model to google/gemma-4-31b-it.
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.

Gemma 4 31B API Pricing

TypePrice
Input
$1.04742 / 1M tokens
Output
$1.57642 / 1M tokens
Cached input
$1.04742 / 1M tokens

Gemma 4 31B Benchmarks

BenchmarkScoreWhat it measuresSourceRetrieved
MMLU-Pro
85.2%
Multi-discipline knowledge + reasoning (harder MMLU)SourceJuly 13, 2026
LiveCodeBench
80.0%
Contamination-free competitive programming problemsSourceJuly 13, 2026
GPQA Diamond
84.3%
Google-proof graduate science questions (hardest subset)SourceJuly 13, 2026
Intelligence
15.4
Composite score across standardised reasoning, knowledge and problem-solving evaluations, measured independently by Artificial AnalysisSourceSeptember 12, 2026
Coding
43.4
Composite score across standardised coding evaluations, measured independently by Artificial AnalysisSourceSeptember 12, 2026

Gemma 4 31B vs other models

ModelInputOutputContextBest for
Gemma 4 31B
This page
$1.04742 / 1M tokens
$1.57642 / 1M tokens
256K tokens
Reasoning + agents
$5 / 1M tokens
$30 / 1M tokens
1M tokens
Reasoning + agents
$2 / 1M tokens
$10 / 1M tokens
1M tokens
Balanced coding + agents
$3 / 1M tokens
$15 / 1M tokens
1M tokens
Long-context, multimodal & agentic workflows
$1.5 / 1M tokens
$9 / 1M tokens
1M tokens
Reasoning + agents

Frequently asked questions

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.

Start building with Gemma 4 31B

Get API Key
1000+ models, one API.