Skip to content
Blog

Google ADK: Calculating Cost Savings from Cached Tokens on Gemini 3.8

Worked arithmetic for Gemini 3.8 Flash cache hits: 90% input discount, 4,096-token floor, storage fees, and a hit-rate-to-savings table you can apply to your own agent.

Published on • December 4, 2026

AI Assistant

An ADK agent that loads a 50,000-token policy handbook, a pile of tool schemas, and a system prompt is a very expensive way to ask a 40-token question. Every turn re-sends that static prefix, and at Standard-tier input rates the prefix — not the conversation — dominates your bill. Teams routinely discover that 80%+ of their input tokens are identical byte-for-byte across calls, which means 80%+ of their input spend is theoretically compressible to a fraction of the price.

The confusing part is that Google publishes at least three different “cache” numbers — a cached-token rate, a storage rate, and a discount percentage — plus separate tables for implicit and explicit caching and two different usage fields to read them from. Pick the wrong one and your savings model is off by an order of magnitude.

This article does the arithmetic for Gemini 3.8 Flash end to end: what a cache hit actually costs, what a miss costs, how storage fees eat into explicit caches, how to read the numbers out of a real response, and how to configure ADK’s ContextCacheConfig so the prefix you paid to build stays cacheable.

1. The three numbers you need

Everything below derives from three published figures for gemini-3.8-flash on the Standard tier:

QuantityThrough Dec 31, 2026From Jan 1, 2027
Input price (per 1M tokens)$0.75$1.50
Context caching price — cached reads (per 1M tokens)$0.075$0.15
Explicit cache storage (per 1M tokens per hour)$0.50$1.00

Two supporting facts from the caching docs:

  • Implicit caching is enabled by default on all Gemini 2.5 and newer models. For Gemini 3.8 Flash the minimum input size is 4,096 tokens, the cache discount is 90% across all tiers, and the storage fee is none.
  • Implicit caches are best-effort: up to 24 hours in memory (RAM), evicted by capacity and routing. No guaranteed retention, no write surcharge, no storage bill.

The 90% discount and the price table agree: $0.075 is exactly 10% of $0.75. That single relationship is what makes the whole model computable.

Savings rule of thumb: with a 90% discount, your percentage savings equals 0.9 × hit_rate. A 50% cache hit rate saves you 45% of input cost. An 83% hit rate saves 75%.

Batch tier halves both rates ($0.375 input, $0.0375 cached), so the ratio — and therefore the savings percentage — is unchanged.

2. Worked arithmetic: one agent, one month

Take a realistic support agent:

  • 50,000-token static prefix (handbook + tool declarations + system instruction)
  • 10,000 tokens of per-turn content (history delta, tool results, user message)
  • 60,000 input tokens per request
  • 1,000 requests/day × 30 days = 30,000 requests → 1.8B input tokens/month

Without caching (everything billed at the Standard input rate):

1,800,000,000 tokens ÷ 1,000,000 = 1,800 "per-1M" units
1,800 × $0.75 = $1,350.00 per month

With caching at a 90% hit rate on the 50K static prefix (the theoretical ceiling here is 50/60 = 83.3%, so 90% of those is close to ideal):

Cached: 1,500,000,000 ÷ 1,000,000 × $0.075 = $112.50
Uncached:   300,000,000 ÷ 1,000,000 × $0.75 = $225.00
                                                  -------
Monthly input cost                             $337.50
Savings vs. $1,350.00                        = $1,012.50 (75%)

Sensitivity table

The same workload at different hit rates — remember savings ≈ 0.9 × hit_rate:

Cache hit rateCached tokens/moUncached tokens/moMonthly input costSavings
0%01.80B$1,350.000%
25%450M1.35B$1,046.2522.5%
50%900M900M$742.5045%
75%1.35B450M$438.7567.5%
83.3% (prefix ceiling here)1.50B300M$337.5075.0%

Because the January 2027 price change doubles both the input and cached rates, these percentages are stable across the price change — the dollar figures simply double ($2,700 → $675 at 83.3%).

Output tokens are untouched by caching. If your agent writes long answers, re-run the model with output included before claiming savings on the total bill.

3. Reading the numbers from a real response

Do not estimate — read the meter. On the Interactions API, usage.total_cached_tokens over usage.total_input_tokens is your hit rate; on generateContent the equivalent field is usage_metadata.cached_content_token_count.

from google import genai

client = genai.Client()

# Static prefix well above the 4,096-token floor for Gemini 3.8 Flash.
handbook = "\n".join(
    f"Section {i}: Return window is 30 days for tier {i % 5 + 1} accounts."
    for i in range(1, 351)
)
system_instruction = "Answer policy questions using only the handbook."


def ask(question: str):
    return client.interactions.create(
        model="gemini-3.8-flash",
        system_instruction=system_instruction,
        input=f"{handbook}\n\nQuestion: {question}",
    )


ask("What is the standard return window?")          # first call primes the prefix
second = ask("Do damaged shipments qualify?")       # should hit the cache

usage = second.usage
cached = usage.total_cached_tokens or 0
total_in = usage.total_input_tokens or 1
print(f"hit rate: {cached / total_in:.1%}")

# Cost model from the measured hit rate (Standard tier, through 2026-12-31):
input_price, cached_price = 0.75, 0.075
cost = (
    (total_in - cached) / 1e6 * input_price
    + cached / 1e6 * cached_price
)
print(f"this call's input cost: ${cost:.6f}")

If total_cached_tokens comes back as 0, check in this order: input below the 4,096-token floor, a changed thinking_level, mutated or reordered tools, a timestamp/UUID embedded in system_instruction, or omitted tools/system_instruction/generation_config on a chained follow-up. Each of these breaks the prefix from the first differing token onward.

4. Implicit vs. explicit caching on 3.8

Gemini 3.8 models support both: implicit caching by default, and explicit cachedContents objects created through the generateContent API with a custom TTL. The cost shape differs mainly because of storage:

# Explicit caching (generateContent path) — you manage the lifecycle.
from google.genai import types

uploaded = client.files.upload(file="handbook.pdf")

cache = client.caches.create(
    model="gemini-3.8-flash",
    config=types.CreateCachedContentConfig(
        system_instruction="Answer questions using the uploaded manual.",
        contents=[uploaded],
        ttl="300s",
    ),
)

response = client.models.generate_content(
    model="gemini-3.8-flash",
    contents="Summarize the refund policy.",
    config=types.GenerateContentConfig(cached_content=cache.name),
)
print("cached:", response.usage_metadata.cached_content_token_count or 0)

Storage arithmetic for that explicit 50K-token cache (Standard tier, through Dec 31, 2026):

50,000 tokens = 0.05 "per-1M" units
0.05 × $0.50/hour = $0.025/hour = $0.60/day = $18.00/month per cache

Holding ten such caches continuously costs $180/month before a single token is read. Implicit caching has no storage fee at all, so the default choice for ADK agents is:

ConcernImplicit (default)Explicit cachedContents
Storage feeNone$0.50/1M tokens/hour (2026 rates)
RetentionBest-effort, up to 24h in RAMDeterministic TTL you set
SetupNone — matches request prefixescaches.create + cached_content=
Read rate$0.075/1M (90% off)$0.075/1M (90% off)
ADK integrationWorks through ContextCacheConfigManual, outside ADK’s app config

Pick explicit only when you need a guaranteed window and are willing to pay storage for it; otherwise let implicit caching do the work.

5. Getting ADK to hold the prefix still

ADK exposes caching at the App level via ContextCacheConfig (experimental, Python v1.15.0+):

from google.adk import Agent
from google.adk.agents.context_cache_config import ContextCacheConfig
from google.adk.apps.app import App

root_agent = Agent(
    name="policy_agent",
    model="gemini-3.8-flash",
    instruction="Answer policy questions concisely using only the handbook.",
    tools=[lookup_order],
)

app = App(
    name="policy-agent-app",
    root_agent=root_agent,
    context_cache_config=ContextCacheConfig(
        min_tokens=4096,    # match Gemini's own floor; first request is never cached
        ttl_seconds=600,    # refresh the cache after 10 minutes
        cache_intervals=5,  # reuse at most 5 times before refresh
    ),
)

What each knob costs you: min_tokens (default 0) is compared against the previous request’s prompt token count, so tiny prompts never pay for cache churn. ttl_seconds defaults to 1800 and cache_intervals defaults to 10 (allowed range 1–100). create_http_options bounds the cache-creation call — on timeout ADK simply proceeds uncached rather than failing the turn.

Then follow the prefix discipline the docs prescribe, because ADK cannot fix a prefix you keep mutating:

  1. Keep thinking_level, tool declarations, and system_instruction byte-identical across turns.
  2. Put timestamps, request IDs, and session IDs in the final user message, never in the instruction.
  3. Keep JSON key order and uploaded-file order stable.
  4. Resend identical tools/system_instruction/generation_config on every chained turn.
  5. Log total_cached_tokens / total_input_tokens per turn so a prompt edit that drops hit rate shows up the same day.

Checklist

  • Confirm your model’s floor: 4,096 input tokens for Gemini 3.8 Flash before caching activates.
  • Measure the theoretical ceiling: static prefix ÷ total input tokens is your maximum hit rate.
  • Multiply by 0.9 to convert hit rate into percentage savings at the published 90% discount.
  • Read total_cached_tokens and total_input_tokens (or cached_content_token_count) from live responses instead of estimating.
  • Prefer implicit caching for ADK agents; price explicit cachedContents storage ($0.50/1M tokens/hour) before adopting it.
  • Set ContextCacheConfig(min_tokens=..., ttl_seconds=..., cache_intervals=...) on your App.
  • Audit system_instruction and tool schemas for timestamps, UUIDs, and unstable key ordering.
  • Re-check the arithmetic against the Jan 1, 2027 rates ($1.50 input / $0.15 cached).
  • Report output-token cost separately — caching never discounts what the model writes.

Conclusion

The savings model for Gemini 3.8 Flash is deliberately simple: cached input costs one-tenth of standard input, the floor is 4,096 tokens, and implicit caching charges no storage. Everything else — hit rate, prefix discipline, TTL choices — decides which part of that 90% you actually collect. On a prefix-heavy agent the difference between a careless 25% hit rate and a disciplined 83% is $700+ per month on the workload above, and nothing about it requires a code change beyond keeping your prefix still.

Treat cache hit rate as a production metric, not a hope. Instrument it per turn, alert on regressions the way you would on error rates, and the discount stops being a marketing number and starts being a line item you can forecast.

References