Skip to article
API429 / Field notes

Gemini context caching: supported APIs, usage and cost checks

Choose the supported Gemini API method, inspect cache usage and reconcile costs before making cached context an application dependency.

Camera lens, microphone and photographic contact sheets on a desk
Editorial photo illustration: Camera lens, microphone and photographic contact sheets on a desk. Topic: Gemini context caching: supported APIs, usage and cost checks.

Gemini context caching reuses repeated input, but support depends on the model and API method. Check the method first, then inspect usage and the applicable prices. A cache hit does not prove that a request avoided every rate limit, and a provider cache feature is not automatically available through an OpenAI-compatible endpoint.

Reviewed on 24 October 2026. Google's current context-caching guide distinguishes implicit caching from explicit cache resources. Implicit caching is enabled by default for Gemini 2.5 and newer models. Explicit caching is not supported by the Interactions API or Gemini 4 Argon and later models. For supported Gemini 3 and 2.5 models, Google directs explicit-cache users to generateContent. Verify the exact model and method rather than applying an older example to every Gemini release.

Start with the interface your application uses

Record the request hostname, method, exact model ID and SDK version. These four fields make a useful starting point for a support question or a reproducible test. Keep the configuration with the application version that produced the observation, so a later change does not erase the comparison.

Your connection First check Evidence to retain
Google Interactions API Current implicit-cache behavior for that model The documented usage fields returned by that method
Google generateContent API Whether that exact model supports the desired caching mode Relevant model documentation and a redacted response
API429 The published contract for the selected model and endpoint Exact model ID, supported request fields and actual response usage

For API429, use the model catalog, setup guide and API reference. Google's cache resource name, SDK option or usage-field name should not be copied into another interface without documented support. Cache hits, effective limits and charges must be checked for the connection you actually use. The public catalog is a selection aid; access for a specific key is checked separately through its model list.

Decide whether repeated context is worth testing

A useful candidate has a stable shared prefix and several real questions that reuse it. A frequently revised document or a small one-off prompt may be a poor starting point. Choose a task with a clear correctness check, such as answering questions against one approved document version. Avoid sensitive production documents in an initial experiment.

Write down the acceptance criteria before sending requests. Decide what makes an answer correct, how you will recognize an outdated answer, and what latency or spend would make the approach unsuitable. Keep the criteria separate from a hoped-for saving. A cheaper response that uses the wrong document version is not an improvement.

Make the application responsible for selecting the intended document version. When a policy changes, update the version you send and test a question whose answer changed. Do not infer freshness from a fast response. The purpose of this check is to catch mistakes in your own input selection before they appear in customer-facing output.

Collect usage without turning logs into another document store

Google's current Interactions documentation identifies usage.total_cached_tokens as its cache-hit usage field. That spelling belongs to that documented interface. Other methods or services can expose different fields; an absent field means the observation is unavailable, not that cached usage was zero.

For your own test report, a small record is enough:

  • Test identifier and UTC time.
  • Exact model, method and application version.
  • Non-sensitive document version label.
  • HTTP status, completion outcome and measured client duration.
  • Available input, output and cached-usage fields, preserving their actual names.
  • Recorded charge or the explicit statement that it has not yet been reconciled.

Store credentials outside the report. Keep prompts, complete documents and raw error metadata out of a shared spreadsheet. If the response lacks enough evidence, mark the result as unknown and identify what further observation would resolve it. Do not substitute a catalogue feature label for the outcome of the test.

Compare costs using the relevant billing units

Use the maintained Gemini API pricing comparison for current source dates, units and conditions. Google's direct-API pricing and API429's customer prices are separate observations. A cache feature described by one service does not establish a discount or billing behavior in another.

Choose a representative workload and keep the intended task consistent when comparing configurations. Record the actual number of successful operations as well as total attempted requests. Include failed or repeated operations when reconciling the bill. A result based only on the cheapest successful response can understate the cost of completing the task.

Avoid a fixed percentage-saving claim before measurement. Your report can instead show the observed usage and charge for each tested configuration, the sample size and the conditions under which it was collected. If the workload changes, review the estimate before using it as a production budget.

Keep access errors and rate limits separate

Google's rate-limit documentation describes request, input-token and daily limits, with model-dependent dimensions and additional spend-based limits. Direct Gemini limits are applied per project. These rules do not establish the effective limits for an API429 key.

In your application, bound the number of attempts and the time allowed for the whole task. Inspect the response before deciding to retry. When an operation's outcome is uncertain, resolve that uncertainty before submitting another paid generation. A caching experiment should not also become an uncontrolled retry experiment.

FAQ

Does caching prevent every 429?

No. Inspect the actual error and applicable limit. A reused prefix is not evidence that every request or spending constraint has been removed.

Can I reuse a Google cache object with any endpoint?

Use it only with the documented method and model. Matching model names or a familiar request format are insufficient evidence of cache-resource compatibility.

What proves that the experiment helped?

Correct output, an understood usage record and reconciled charges for a representative task provide useful evidence. A fast response alone does not prove a cache hit or a saving. Keep an unmeasured outcome explicitly unmeasured.

Where should an API429 user start?

Choose an exact ID from the catalog, follow the documented connection workflow, and consult the FAQ for key handling and usage-cost boundaries. Confirm any required cache behavior separately before making it a dependency of the application.

Runnable offline Python 3.10+ break-even cost check

The following self-contained Python 3.10+ standard-library script compares break-even explicit-cache token and TTL storage costs against standard POST /v1/chat/completions input and output billing, including repeated or failed attempts:

from __future__ import annotations

from dataclasses import dataclass
import json


@dataclass(frozen=True)
class WorkloadSample:
    shared_prefix_tokens: int
    question_input_tokens: int
    output_tokens_per_call: int
    successful_calls: int
    retried_or_failed_calls: int


def evaluate_chat_completions_cost_usd(
    sample: WorkloadSample,
    input_per_1m_usd: float,
    output_per_1m_usd: float,
) -> float:
    """Computes standard POST /v1/chat/completions cost including repeated attempts."""
    total_attempts = sample.successful_calls + sample.retried_or_failed_calls
    input_tokens_per_call = sample.shared_prefix_tokens + sample.question_input_tokens
    total_input_tokens = total_attempts * input_tokens_per_call
    total_output_tokens = total_attempts * sample.output_tokens_per_call
    return (
        (total_input_tokens / 1_000_000) * input_per_1m_usd
        + (total_output_tokens / 1_000_000) * output_per_1m_usd
    )


def evaluate_explicit_cache_cost_usd(
    sample: WorkloadSample,
    uncached_input_per_1m_usd: float,
    cached_input_per_1m_usd: float,
    output_per_1m_usd: float,
    storage_per_1m_token_hour_usd: float,
    ttl_hours: float,
) -> float:
    """Computes explicit cache write + storage + cached prefix reads across attempts."""
    total_attempts = sample.successful_calls + sample.retried_or_failed_calls
    initial_write_usd = (sample.shared_prefix_tokens / 1_000_000) * uncached_input_per_1m_usd
    storage_usd = (sample.shared_prefix_tokens / 1_000_000) * storage_per_1m_token_hour_usd * ttl_hours
    per_call_input_usd = (
        (sample.shared_prefix_tokens / 1_000_000) * cached_input_per_1m_usd
        + (sample.question_input_tokens / 1_000_000) * uncached_input_per_1m_usd
    )
    per_call_output_usd = (sample.output_tokens_per_call / 1_000_000) * output_per_1m_usd
    return initial_write_usd + storage_usd + total_attempts * (per_call_input_usd + per_call_output_usd)


def break_even_calls_for_prefix(
    shared_prefix_tokens: int,
    uncached_input_per_1m_usd: float,
    cached_input_per_1m_usd: float,
    storage_per_1m_token_hour_usd: float,
    ttl_hours: float,
) -> int:
    """Returns minimum calls required for cached prefix savings to exceed write + TTL storage overhead."""
    savings_per_call_per_1m = uncached_input_per_1m_usd - cached_input_per_1m_usd
    if savings_per_call_per_1m <= 0:
        raise ValueError("Cached input rate must be lower than uncached input rate")
    overhead_per_1m = uncached_input_per_1m_usd + (storage_per_1m_token_hour_usd * ttl_hours)
    # Scale-invariant in shared_prefix_tokens once prefix > 0
    _ = shared_prefix_tokens
    calls = int(overhead_per_1m // savings_per_call_per_1m) + 1
    return calls


if __name__ == "__main__":
    workload = WorkloadSample(
        shared_prefix_tokens=50_000,
        question_input_tokens=500,
        output_tokens_per_call=400,
        successful_calls=10,
        retried_or_failed_calls=1,
    )

    # Standard API429 POST /v1/chat/completions billing for gemini-3.8-flash ($0.06 / $0.36 per 1M)
    api429_standard_usd = evaluate_chat_completions_cost_usd(
        workload, input_per_1m_usd=0.06, output_per_1m_usd=0.36
    )

    # Direct Google uncached baseline ($0.30 / $1.80 per 1M) vs illustrative explicit-cache parameters
    google_uncached_usd = evaluate_chat_completions_cost_usd(
        workload, input_per_1m_usd=0.30, output_per_1m_usd=1.80
    )
    google_explicit_cache_usd = evaluate_explicit_cache_cost_usd(
        workload,
        uncached_input_per_1m_usd=0.30,
        cached_input_per_1m_usd=0.075,
        output_per_1m_usd=1.80,
        storage_per_1m_token_hour_usd=1.00,
        ttl_hours=2.0,
    )
    min_calls = break_even_calls_for_prefix(
        shared_prefix_tokens=50_000,
        uncached_input_per_1m_usd=0.30,
        cached_input_per_1m_usd=0.075,
        storage_per_1m_token_hour_usd=1.00,
        ttl_hours=2.0,
    )

    assert api429_standard_usd < google_uncached_usd
    assert min_calls == 11
    print(
        json.dumps(
            {
                "api429_standard_chat_completions_usd": round(api429_standard_usd, 6),
                "google_direct_uncached_usd": round(google_uncached_usd, 6),
                "google_explicit_cache_2h_ttl_usd": round(google_explicit_cache_usd, 6),
                "explicit_cache_break_even_calls": min_calls,
            }
        )
    )

Sources & further reading

  1. Google — context caching, reviewed 24 October 2026
  2. Google — Gemini API rate limits
  3. API429 — public API reference
  4. API429 — Gemini pricing comparison
  5. API429 — client documentation

Put the next step into practice.

Check model IDs, current pricing and request formats before integrating. Availability can depend on the model and provider route.

Telegram