Gemma 4 31B vs GLM 5.4
Practical read: Gemma 4 31B costs under a tenth as much. GLM 5.4 reads four times more context and starts answering sooner. One API key runs both.Gemma 4 31B is over 10× cheaper. GLM 5.4 has 4× the context and answers sooner.
Side by side:
| Attribute | Gemma 4 31B | GLM 5.4 |
|---|---|---|
| Price, 1M in + 1M out | $0.46 Weights & Biases, cheapest route | $6.12 Alibaba Cloud Model Studio, cheapest route |
| Best for | Low cost | Long documents and speed |
| Input / output, 1M | $0.11 / $0.36 | $1.48 / $4.64 |
| Cached input | $0.060927/1M to $0.26375/1M | $0.1899/1M to $0.2743/1M |
| Context window | 262K 262,144 tokens | 1.05M 1,048,576 tokens |
| First token, p50 | 0.66 s via Tinfoil | 0.64 s via FriendliAI |
| Throughput | 365 tok/s via FriendliAI | Measuring |
| AI IQ | IQ 101 #131 on AI IQ | IQ 124 #37 on AI IQ |
| Provider routes | 12 with failover | 6 with failover |
| Privacy | Confidential E2EE and zero retention route | Zero retention route |
| Recent route uptime range | 0.00% to 100.00% | 100.00% |
| Publisher | Google AI Studio | Z.AI |
| Modes | chat | chat |
| More detail |
Price adds one million input and one million output tokens on the cheapest route. Prices and speed change: see the monthly reports and run a small eval before you choose a default.
Test both with your agent
Paste this into Claude Code, Cursor or any coding agent.
Compare Gemma 4 31B and GLM 5.4 in this project through TrustedRouter.
1. Read https://trustedrouter.com/docs/llms.txt
2. Point the OpenAI-compatible client at
https://api.trustedrouter.com/v1 and read the key from
TRUSTEDROUTER_API_KEY.
3. Run our eval prompts on google/gemma-4-31b-it, then on z-ai/glm-5.4.
4. Show me cost, latency and quality side by side before changing the default.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.trustedrouter.com/v1",
api_key=os.environ["TRUSTEDROUTER_API_KEY"],
)
for model in ("google/gemma-4-31b-it", "z-ai/glm-5.4"):
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(model, response.choices[0].message.content)
for model in google/gemma-4-31b-it z-ai/glm-5.4; do
curl https://api.trustedrouter.com/v1/chat/completions \
-H "Authorization: Bearer $TRUSTEDROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"model\": \"$model\", \"messages\": [{\"role\": \"user\", \"content\": \"What is the capital of France?\"}]}"
done
Questions
Which should I use, Google Gemma 4 31B or Z.AI GLM 5.4?
Google Gemma 4 31B has the lower price per 1M input + 1M output tokens and more providers to fall back on. Z.AI GLM 5.4 has the larger context window (1,048,576 vs 262,144 tokens) and the shorter median time to first token on its fastest sampled route.
Is Google Gemma 4 31B or Z.AI GLM 5.4 cheaper?
At the lowest listed TrustedRouter rates, 1M input + 1M output tokens cost about $0.46 for Google Gemma 4 31B and $6.12 for Z.AI GLM 5.4.
Is Google Gemma 4 31B or Z.AI GLM 5.4 faster?
Across recently sampled routes, the lowest median time to the first token was 660 ms for Google Gemma 4 31B and 644 ms for Z.AI GLM 5.4.
Can I test Google Gemma 4 31B and Z.AI GLM 5.4 with the same API?
Yes. Use the same OpenAI-compatible TrustedRouter base URL and API key, then change only the model id between google/gemma-4-31b-it and z-ai/glm-5.4. This makes side-by-side evals possible without maintaining two provider integrations.
More comparisons
All comparisonsTry Gemma 4 31B and GLM 5.4 with one key.
TrustedRouter is useful when you know the model you want, but still need provider rollover, budget limits, usage records, and a prompt path you can verify.
Up to 1 million free tokens. No card required.