Gemma 4 31B API

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.

Modalities
TextText
In / Out price
$1.05/$1.58per 1M
Context window
250K tokens
Released
Apr 3, 2026

Gemma 4 31B overview

The pelican test: one prompt, every text model, unedited SVG output from Nov 3, 2026.

SVG of a pelican riding a bicycle, written by Gemma 4 31B through AI/ML API

Gemma 4 31B by Google

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.

Gemma 4 31B specs

Model ID
google/gemma-4-31b-it
Developer
Google
Context window
256,000 tokens
Max output
16,384 tokens
Input
Text
Output
Text
API
OpenAI-compatible, base URL https://api.aimlapi.com/v1

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

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.

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.

Capabilities

  • Function calling
  • Streaming
  • Structured outputs

Gemma 4 31B benchmarks by Artificial Analysis

See how Gemma 4 31B compares in generation speed and latency. Data retrieved Nov 3, 2026.

Speed

Output tokens / second

Benchmark results

Compare 6 models available on AI/ML API across 5 independent benchmarks.

Humanity's Last Exam

Expert-written questions across academic subjects.

Gemma 4 31B API pricing

Gemma 4 31B pricing in US dollars
UsagePriceUnit
Input$1.051M tokens
Output$1.581M tokens
Cached input$1.051M tokens

Prices from the AI/ML API price list, checked on Nov 4, 2026.

Gemma 4 31B vs other models: token prices

AI/ML API input and output rates for 5 models, per million tokens.

AI/ML API model prices in USD per million tokens
ModelInputOutput
Gemma 4 31B$1.05$1.58
Gemini 3.5 Flash Lite$0.3$2.5
Gemini 3.8 Flash$0.75$3.75
Gemini 3.7 Flash$0.75$3.75
Gemini 4 Argon$2$10

How to use the Gemma 4 31B API

View docs

Build with your agent

Give your agent the model details, code and documentation.

1Get your API key

Create API key
export AIMLAPI_KEY="8f2b4c7d9a1e6b3f…"

2Make your first request

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."
    }
  ]
}'

Related articles

All posts

Gemma 4 31B FAQ

What is the context window of Gemma 4 31B?

Gemma 4 31B has a 256,000 tokens context window and can return up to 262,144 tokens.

What inputs and outputs does Gemma 4 31B support?

Gemma 4 31B takes image, text as input and returns text.

What is the model ID for Gemma 4 31B?

Use google/gemma-4-31b-it as the model id. Requests go to https://api.aimlapi.com/v1/chat/completions.

When was Gemma 4 31B released?

Gemma 4 31B became available on April 3, 2026.

How much does Gemma 4 31B cost?

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.

Does Gemma 4 31B support streaming?

Yes, Gemma 4 31B can stream responses as they are generated.

Can Gemma 4 31B read images?

Yes, Gemma 4 31B accepts image input alongside text.

Who created Gemma 4 31B?

Gemma 4 31B was built by Google.

Start building with Gemma 4 31B

Gemma 4 31B API

google/gemma-4-31b-it

Build with your agent

Give your agent the model details, code and documentation.

1Get your API key

Create API key
export AIMLAPI_KEY="8f2b4c7d9a1e6b3f…"

2Make your first request

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."
    }
  ]
}'