59API

← Back to all guides

Prompt Caching: A 15-Minute Guide to Lower API Bills

Pricing · EN · 2026-10-21

Cache the context you keep sending

If your application sends the same instructions, tool definitions, or reference documents on every request, prompt caching can reduce input costs and time to first token. The provider reuses a previously processed prompt prefix instead of processing that entire prefix from scratch.

It does not shorten your prompt or increase the context window. Cached tokens still occupy context, and generated output is billed normally. This is also different from response caching: the model still generates a fresh answer.

Here is a quick-start workflow for Claude and GPT applications, including those running through 59API.

1. Put stable content first

Caching generally depends on matching the beginning of a request. Structure your prompt so reusable material comes before anything that changes:

For a documentation assistant, place the shared handbook before the user's question. Do not prepend a timestamp, random request ID, or personalized greeting: an early change can prevent reuse of everything after it.

Keep serialization deterministic. Preserve document order, whitespace, tool ordering, and schema formatting. Treat the reusable prefix as a versioned application asset rather than rebuilding it unpredictably on each request.

2. Enable the right caching mechanism

For OpenAI models: supported models generally cache eligible repeated prefixes automatically. You normally do not add Claude-style cache markers. Check your exact model's minimum prompt length; many supported models start at 1,024 input tokens. A short greeting will not qualify simply because you repeat it.

For Claude models: use Anthropic's prompt-caching controls where supported. A typical text block at the end of reusable content includes this field: {"cache_control":{"type":"ephemeral"}}. For example, a system text block can be {"type":"text","text":"Your stable instructions and reference material...","cache_control":{"type":"ephemeral"}}.

Claude's default ephemeral cache lifetime is typically five minutes, with hits refreshing that lifetime. Longer-lived options exist for supported configurations, but have different write pricing. Minimum cacheable lengths also vary by model, so verify eligibility before troubleshooting a small test prompt.

Do not assume these controls translate between API formats. An OpenAI-compatible endpoint may not expose every Anthropic-specific field. Confirm that your endpoint, model, and relay route preserve the caching mechanism you intend to use.

3. Connect through 59API without losing visibility

59API provides low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without model downgrades. Its compatibility with Claude Code, Codex, and OpenAI SDKs makes it convenient for existing developer workflows.

Use https://api.59api.com as the service base, following its documentation for your SDK's endpoint path and authentication. Keep your API key in an environment variable, not in source control.

Before budgeting around caching, verify the selected route's cache support, usage reporting, and billing rules. A low token price and a cache discount are separate benefits; confirm how they combine rather than assuming official-provider discounts automatically apply.

4. Prove that the cache is working

For OpenAI Chat Completions, look for usage.prompt_tokens_details.cached_tokens when exposed. For Anthropic Messages, inspect usage.cache_creation_input_tokens and usage.cache_read_input_tokens. Other API surfaces can report equivalent information differently.

Run several sequential requests before testing concurrency. Simultaneous cold requests may arrive before a reusable cache entry is ready.

5. Calculate savings on the whole workload

Estimate cost as uncached input charges plus cache-write charges, cache-read charges, and output charges. Some providers charge extra to create cache entries, so one-off requests may not benefit.

For example, a 12,000-token shared handbook followed by a 500-token question offers substantial reusable input. Repeating it frequently can help; rewriting the handbook every turn or waiting beyond expiry undermines the benefit.

Track cache-hit tokens, total billed cost, and latency across a representative session. If you want an inexpensive place to test, consider signing up for 59API; its pay-as-you-go access and referral rebate offer additional ways to manage spending. Let measured results determine your production setup.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free