Gemma 4 31B API
gemma-4-31b
Gemma 4 31B from Google, served through RouterHub on the OpenAI-compatible Chat Completions API. $0.06 input / $0.18 output per million tokens.
Gemma 4 31B pricing
- Input
- $0.06
- Cached input
- $0.06
- Output
- $0.18
- Typical message
- ≈ 0.015¢
8,000 input + 2,000 output tokens ≈ $0.0008 before caching.
USD per 1 million tokens. A typical message is about 1,000 input and 500 output tokens. Cached input uses the cache-read rate when a cache hit is reported. Billed from your prepaid balance.
API compatibility and context
- Exact model ID
gemma-4-31b- Provider
- Variant
- Standard
- Supported API
- OpenAI-compatible Chat Completions API (
/v1/chat/completions) - Availability
- Preview
- Context window
- 256,000 tokens
- Maximum input
- Not published
- Maximum output
- 128,000 tokens
Use Gemma 4 31B through the API
Create a RouterHub account, add prepaid credits and create an API key. Set ROUTERHUB_API_KEY locally, then send a first request with the exact model ID.
curl --connect-timeout 30 --max-time 600 https://routerhub.si/v1/chat/completions \
-H "Authorization: Bearer $ROUTERHUB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gemma-4-31b","messages":[{"role":"user","content":"Write a short noir scene set in a lighthouse."}],"max_tokens":256}'Python: install openai with pip. The example requests 256 output tokens and disables automatic retries, so check Usage before resending a paid request.
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ROUTERHUB_API_KEY"],
base_url="https://routerhub.si/v1",
timeout=600.0,
max_retries=0,
)
response = client.chat.completions.create(
model="gemma-4-31b",
messages=[{"role": "user", "content": "Write a short noir scene set in a lighthouse."}],
max_tokens=256,
)
print(response.choices[0].message.content)Compatible with the tools you already use
One key, one base URL.
Common questions
What is Gemma 4 31B?
Gemma 4 31B is a Google language model served through RouterHub using the OpenAI-compatible Chat Completions API. Its exact API model ID is gemma-4-31b.
How much does Gemma 4 31B cost?
RouterHub charges $0.06 input, $0.06 cached input and $0.18 output per million tokens. A typical chat message of about 1,000 input and 500 output tokens costs about 0.015¢. Usage is billed against your prepaid balance.
What is the Gemma 4 31B context window?
Context window: 256,000 tokens. Maximum input: Not published. Maximum output: 128,000 tokens.
Which API does Gemma 4 31B support?
Use the OpenAI-compatible Chat Completions API at https://routerhub.si/v1/chat/completions with the exact model ID gemma-4-31b and your RouterHub API key (Authorization: Bearer header).
Which coding tools work with Gemma 4 31B?
OpenCode, VS Code + Continue, VS Code + Cline, Hermes Agent. Each setup guide lists only compatible model IDs.
Can I try Gemma 4 31B for free?
Gemma 4 31B needs a free RouterHub account with prepaid credits. New accounts get $5 free on their first top-up of $20 or more.