Gemma 4 31B API
google/gemma-4-31bTextCall Gemma 4 31B through MartLLM’s OpenAI-compatible API, from $0.000912/M input and $0.00274/M output, served by third-party providers. Made by Google. 256,000 token context. No MartLLM fee on requests. Adding credit by card costs 5.5% + $0.50.
Model by Google. Also sold directly by: Amazon Bedrock. Here, sellers serve it through their own provider accounts. Why so cheap? · Where the capacity comes from
How much does the Gemma 4 31B API cost?
On November 20, 2026, Gemma 4 31B costs $0.000912 per million input tokens and $0.00274 per million output tokens through MartLLM, 99.2% below its list price of $0.12 and $0.36. 33 sellers on the market can serve it. It reads up to 256,000 tokens of context. Every request is listed with its cost in the Activity log. MartLLM adds no fee to these prices, and a request that fails is not billed.
Gemma 4 31B pricing
You save $0.1191 per 1M input tokens and $0.3573 per 1M output tokens against the official price of $0.12 / $0.36. Why so cheap?
- Input
- $0.000912
- Output
- $0.00274
- Cached input
- $0.000228
- Input
- $0.12
- Output
- $0.36
- Cached input
- $0.09
Prices as of 11:00 UTC.
Each request is sent to an available third-party provider for this model and retried if the provider fails before it starts answering. No MartLLM fee on requests. Adding credit by card costs 5.5% + $0.50.
How to use Gemma 4 31B with the OpenAI SDK
With the OpenAI SDK, set the base URL to MartLLM and call Gemma 4 31B with your existing code. Anthropic SDKs work against https://api.martllm.com/v1/messages.
from openai import OpenAI
client = OpenAI(
base_url="https://api.martllm.com/v1",
api_key="ull_your_key_here",
)
resp = client.chat.completions.create(
model="google/gemma-4-31b",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)Use Gemma 4 31B in your apps
By API, Gemma 4 31B answers on three addresses with the same MartLLM key and the model id google/gemma-4-31b: OpenAI chat completions at https://api.martllm.com/v1/chat/completions, the OpenAI Responses API at https://api.martllm.com/v1/responses and the Anthropic Messages API at https://api.martllm.com/v1/messages.
How do I use Gemma 4 31B in Claude Code?
Claude Code reaches Gemma 4 31B through the Anthropic-compatible address of MartLLM. Set ANTHROPIC_BASE_URL to https://api.martllm.com (with no /v1 at the end), ANTHROPIC_AUTH_TOKEN to your MartLLM key and ANTHROPIC_MODEL to google/gemma-4-31b, then start claude. Set the opus, sonnet, haiku and subagent model variables to google/gemma-4-31b as well: a slot left unset keeps asking for a Claude model at Claude prices. CLAUDE_CODE_MAX_CONTEXT_TOKENS is set to 256,000, the context size of Gemma 4 31B, because Claude Code assumes 200,000 tokens for a model it does not know.
export ANTHROPIC_BASE_URL=https://api.martllm.com
export ANTHROPIC_AUTH_TOKEN=ull_your_key
export ANTHROPIC_MODEL='google/gemma-4-31b'
export ANTHROPIC_DEFAULT_OPUS_MODEL='google/gemma-4-31b'
export ANTHROPIC_DEFAULT_SONNET_MODEL='google/gemma-4-31b'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='google/gemma-4-31b'
export CLAUDE_CODE_SUBAGENT_MODEL='google/gemma-4-31b'
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=256000
claudeClaude Code calls: Anthropic Messages API https://api.martllm.com/v1/messages · Full Claude Code guide
How do I use Gemma 4 31B in Codex CLI?
Codex CLI reaches Gemma 4 31B through the Responses API of MartLLM. In ~/.codex/config.toml, add a model provider with base_url set to https://api.martllm.com/v1 and wire_api = "responses", put your MartLLM key in the UBERLLM_API_KEY environment variable, and set model to google/gemma-4-31b. model_context_window is set to 256,000, the context size of Gemma 4 31B, because Codex assumes 272,000 tokens for models outside the list of OpenAI models it knows.
model = "google/gemma-4-31b"
model_provider = "uberllm"
model_context_window = 256000
web_search = "disabled"
[model_providers.uberllm]
name = "MartLLM"
base_url = "https://api.martllm.com/v1"
env_key = "UBERLLM_API_KEY"
wire_api = "responses"Codex CLI calls: OpenAI Responses API https://api.martllm.com/v1/responses · Full Codex CLI guide
How do I use Gemma 4 31B in OpenCode?
OpenCode reaches Gemma 4 31B through the OpenAI-compatible chat address of MartLLM. In ~/.config/opencode/opencode.json, add a provider named uberllm that uses the @ai-sdk/openai-compatible package with baseURL set to https://api.martllm.com/v1, list google/gemma-4-31b under its models, put your MartLLM key in the UBERLLM_API_KEY environment variable, then pick uberllm/google/gemma-4-31b with /models. The limit numbers are the context size and the largest reply of Gemma 4 31B; OpenCode uses them to know when to compact a long session.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"uberllm": {
"npm": "@ai-sdk/openai-compatible",
"name": "MartLLM",
"options": {
"baseURL": "https://api.martllm.com/v1",
"apiKey": "{env:UBERLLM_API_KEY}"
},
"models": {
"google/gemma-4-31b": {
"name": "Gemma 4 31B",
"limit": {
"context": 256000,
"output": 128000
}
}
}
}
},
"model": "uberllm/google/gemma-4-31b"
}OpenCode calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full OpenCode guide
How do I use Gemma 4 31B in Cursor?
In Cursor Settings → Models, paste your MartLLM key into the OpenAI API Key field, turn on the OpenAI base URL override and enter https://api.martllm.com/v1, turn on Use API Key, then add google/gemma-4-31b as a custom model and select it in the chat model picker. This is for chat in Cursor: Tab completion keeps using the models Cursor provides.
- OpenAI API Key
ull_your_key- OpenAI base URL override
https://api.martllm.com/v1- Custom model
google/gemma-4-31b
Cursor calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full Cursor guide
How do I use Gemma 4 31B in Cline?
In the settings of Cline, set API Provider to OpenAI Compatible, Base URL to https://api.martllm.com/v1, paste your MartLLM key into OpenAI Compatible API Key and set Model ID to google/gemma-4-31b. Under Model Configuration, set Context Window Size to 256,000: Cline does not read the limits of a model on its own. In the same place, set Max Output Tokens to 128,000.
- API Provider
OpenAI Compatible- Base URL
https://api.martllm.com/v1- OpenAI Compatible API Key
ull_your_key- Model ID
google/gemma-4-31b- Context Window Size
256000- Max Output Tokens
128000
Cline calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full Cline guide
How do I use Gemma 4 31B in SillyTavern?
In SillyTavern, open API Connections, set API to Chat Completion and Chat Completion Source to Custom (OpenAI-compatible), enter https://api.martllm.com/v1 in Custom Endpoint (Base URL), paste your MartLLM key into Custom API Key, click Connect, then type google/gemma-4-31b in Enter a Model ID.
- API
Chat Completion- Chat Completion Source
Custom (OpenAI-compatible)- Custom Endpoint (Base URL)
https://api.martllm.com/v1- Custom API Key
ull_your_key- Enter a Model ID
google/gemma-4-31b
SillyTavern calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full SillyTavern guide
How do I use Gemma 4 31B in Janitor AI?
In Janitor AI, open a chat, click the gear icon and open API Settings. Choose Proxy and add a configuration with Model Name set to google/gemma-4-31b, Proxy URL set to https://api.martllm.com/v1/chat/completions and your MartLLM key in API Key. Click Save Settings, then refresh the page.
- Config Name
MartLLM- Model Name
google/gemma-4-31b- Proxy URL
https://api.martllm.com/v1/chat/completions- API Key
ull_your_key
Janitor AI calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full Janitor AI guide
How do I use Gemma 4 31B in Open WebUI?
In Open WebUI, go to Settings → Admin → Connections and add an OpenAI API connection with URL set to https://api.martllm.com/v1 and your MartLLM key in API Key. Under Advanced, add google/gemma-4-31b to Model IDs, and leave API Type on Chat Completions.
- URL
https://api.martllm.com/v1- API Key
ull_your_key- Model IDs
google/gemma-4-31b- API Type
Chat Completions
Open WebUI calls: OpenAI chat completions https://api.martllm.com/v1/chat/completions · Full Open WebUI guide
Gemma 4 31B API FAQ
Can I cap what a Gemma 4 31B request costs?
Yes. A request costs what its provider charged; the listed price is $0.0265 input and $0.0794 output per million tokens, and a request can cost more when the cheaper providers are busy. Send provider.max_price with your most per million tokens: the request only goes to providers at or under it and is never billed above it. Each request is listed with its cost in Activity.
How do I call Gemma 4 31B via API?
Use any OpenAI-compatible SDK: set the base URL to https://api.martllm.com/v1, your MartLLM API key, and model "google/gemma-4-31b". Anthropic SDKs work via https://api.martllm.com/v1/messages.
Is Gemma 4 31B OpenAI-compatible on MartLLM?
Yes. Every model on MartLLM, including Gemma 4 31B, is served through one OpenAI-compatible endpoint. Set the base URL and key in your existing client.
Are there other fees?
MartLLM adds no fee to model prices. A card fee of 5.5% + $0.50 is added when you buy credit, and a request that fails is not billed.
Embed this price
Show these prices on your own site. The table reads the current prices from MartLLM, so it stays up to date.
Script: the table sets its own height
<script async src="https://martllm.com/embed.js" data-models="google/gemma-4-31b"></script>Plain iframe, for sites that allow no scripts
<iframe src="https://martllm.com/embed/prices?models=google/gemma-4-31b" title="AI model API prices" width="100%" height="127" loading="lazy" style="border:0;max-width:720px"></iframe>Price badge for a README (Markdown)
[](https://martllm.com/models/google/gemma-4-31b?utm_source=embed&utm_medium=referral&utm_campaign=price-badge)Every option is in the embed docs.
Compared with other providers: Best OpenRouter alternatives