Prompt caching
Cached input tokens and discounted pricing on repeated context.
Providers cache repeated prompt prefixes. When a request hits a provider-side prompt cache, the cached portion of your input tokens is billed at the model's lower cached-input rate.
- Pricing:
GET /v1/modelsexposes a cached input price per model where providers offer one. Cached tokens cost less than fresh input tokens. - Usage detail: responses report
usage.prompt_tokens_details.cached_tokens, andcost_details.cached_input_costshows what the cached share cost. - No code changes are required: caching is automatic where the provider supports it. Longer shared prefixes (system prompts, few-shot examples) hit more often.
Cache behavior and granularity depend on the underlying provider; treat it as a discount opportunity, not a correctness mechanism.
How is this guide?