Claude API costs scale with token usage. For applications that call the API frequently, understanding token efficiency and prompt caching can reduce costs by 60–80% for the right workloads. Here is the technical detail.
How Prompt Caching Works
Prompt caching (available on Claude 3.5 Sonnet and Haiku) allows repeated sections of your prompt to be cached server-side. When the same prefix appears in multiple API calls, the cached version is read at approximately 10% of the cost of re-processing the full tokens. For applications where a long system prompt or reference document is used across many requests, caching that section reduces input token costs substantially. The cache TTL is 5 minutes — API calls within 5 minutes reuse the cached prefix.
When Caching Provides Maximum Value
Best candidates for caching: long system prompts (instructions, role definitions, output formats), reference documents loaded into context (codebases, documentation, policies), few-shot examples that don’t change across requests. Least valuable: short system prompts, highly variable content, single-use API calls. The calculation: a 10,000 token system prompt used in 100 API calls costs 10,000 × 100 = 1,000,000 input tokens without caching. With caching, it costs 10,000 (first call) + 1,000 × 99 (cached reads) = 109,000 tokens — a 89% reduction.
Batch API
The Anthropic Batch API processes requests asynchronously at 50% cost reduction — ideal for workloads that do not require immediate responses. Use cases: content generation at scale (1,000 product descriptions), data classification (large datasets), offline analysis tasks. Submit a batch, wait up to 24 hours for completion, retrieve results. The cost reduction makes non-real-time AI workloads significantly more economical.
Token Counting and Optimisation
Use client.messages.count_tokens() before sending expensive requests to audit prompt length. Common optimisation opportunities: remove verbose few-shot examples (keep 2–3, not 10), compress system prompts (remove redundancy), use structured output formats that require fewer tokens to specify, and prefer shorter model variants (Haiku) for classification and simple extraction tasks where full reasoning is not required.




