Google GenAI SDK: prompt compression in one line
The static prefix is formatted for the provider cache (Anthropic breakpoints, OpenAI prompt_cache_key or 12h retention) and tool schemas are minified losslessly before they are sent. Here is the change for Google GenAI SDK, the switch that turns it on, and the arithmetic on gemini-3.8-flash.
Google GenAI SDK reaches TokenZero with one base-URL argument and keeps your gemini key. On gemini-3.8-flash a cached input token costs $0.075 per million instead of $0.75, so 100,000 calls with a 1,500-token static prefix drop from $263 to $161 a month, 39% less, before any routing.
· Source: pricing table 2026-10-26; overhead from the published benchmark on /benchmarks
At a glance
- Framework
- Google GenAI SDK (Python)
- Capability
- prompt compression
- Change
- client.py: base URL argument
- Request shape
- Gemini native generateContent
- Turn it on
- X-TokenZero-Cache-Strategy: static
- Workspace setting
- cache_strategy: static, prompt_cache_ttl: 1h
- Reference model
- gemini-3.8-flash ($0.75 in / $3.75 out per 1M, table 2026-10-26)
- Cache-formatting saving on the reference workload
- $101/month (39%) (computed)
- Gateway overhead (measured)
- 1.52 ms p50, 3.42 ms p95
- Parity floor
- 99.8%
- Free tier
- $500/month routed spend
Reference workload on gemini-3.8-flash: 2,000 input (1,500 static) / 300 output tokens, 100,000 calls per month, table 2026-10-26
| Scenario | Per call | Per month | Delta |
|---|---|---|---|
| List price, no gateway | $0.00262 | $263 | — |
| Static prefix cached (prompt compression) | $0.00161 | $161 | $101 (39%) |
| 20% exact-cache repeats | $0.00210 | $210 | $53 (20%) |
| All calls cascaded to gemini-3.5-flash-lite | $0.00135 | $135 | $128 (49%) |
| Budget guardrail at $500/month | — | capped at $500.00 | 402 after 190,476 calls |
The change
1. Point Google GenAI SDK at the gateway (client.py):
-client = genai.Client()
+client = genai.Client(http_options={"base_url": "https://tokenzero.sh"})
r = client.models.generate_content(model="gemini-3.8-flash", contents=prompt)The native /v1beta generateContent and streamGenerateContent paths are proxied; x-goog-api-key passes through.
2. Turn on prompt compression. Per request: X-TokenZero-Cache-Strategy: static (default) · X-TokenZero-Prompt-Cache-TTL: 1h or 12h. Per workspace (applies to every call without touching code): PATCH /v1/workspaces/settings {cache_strategy: static, prompt_cache_ttl: 1h} or the dashboard toggle.
3. Prove it. npx -y @tokenzero/cli doctor checks the gateway, the signer, the pricing table and your key; then watch input_tokens_cached_pct and compaction tokens saved on the scorecard.
Questions people ask
How do I point Google GenAI SDK at TokenZero?
Pass base_url / baseURL = https://tokenzero.sh where Google GenAI SDK builds its client (client.py) and keep your gemini key; nothing else changes.
What does prompt compression save on gemini-3.8-flash?
On gemini-3.8-flash a cached input token costs $0.075 per million instead of $0.75, so 100,000 calls with a 1,500-token static prefix drop from $263 to $161 a month, 39% less, before any routing.
Does prompt compression change the model's output?
No. Cache formatting only marks or keys the static prefix and tool minification only collapses whitespace in descriptions; names, enums, defaults and examples are never touched.
What does TokenZero cost?
Free up to $500 per month of routed spend; then 15% of verified savings with a 3x-ROI-or-$0 rule, capped plans available. Gateway overhead measured at 1.52 ms p50.