Guide · Costs
The AI API Cost Cheat Sheet
Ways to cut OpenAI and Anthropic API costs, checked against the official docs (Oct 2026), plus a spend-limit checklist. From BillCurfew (billcurfew.com).
Cut costs
1. Batch anything that can wait.
- OpenAI Batch API: 50% off the regular endpoints. Results come back within 24 hours.
- Anthropic Message Batches: everything is billed at 50% of standard prices, and most batches finish in under an hour.
- Good jobs to batch: evals, classification, embeddings, bulk summaries.
- Give each request a unique
custom_id, because results can come back in a different order.
2. Cache your repeated prompt prefix.
- Anthropic: a cache read costs 0.1x the base input price on most models (less on some newer ones). A 5-minute cache write costs 1.25x, and a 1-hour write costs 2x.
- OpenAI: caching is on by default for supported models. On GPT-5.6 and later, a read costs 0.1x the input rate and a 30-minute write costs 1.25x.
- Put stable content first (tools, system prompt, reference docs) and changing content last.
- A timestamp near the top of the prompt breaks the cache.
- Prompts shorter than the minimum length aren't cached, and you won't get an error. On Anthropic, check
cache_read_input_tokens. On OpenAI, checkcached_tokens. - Batch and caching discounts stack on Anthropic.
3. Use the cheapest model that does the job.
- Prices vary a lot between model tiers. For example, Anthropic lists Claude Haiku 4.5 at $1 per million input tokens and Claude Opus 4.5 at $5.
- Send simple tasks (routing, extraction, tagging) to a small model. Save the top model for the hard parts.
4. Set max_tokens close to what you expect back.
- It caps how long a reply can run.
- On OpenAI, a smaller
max_tokensalso helps with rate limits, because limits are counted from the larger ofmax_tokensand the estimated request size.
5. Keep retries under control.
- The official OpenAI SDKs retry some
429and503errors automatically. - If you add your own retry loop on top, the two can multiply requests. Cap the number of attempts and the total retry time.
- Never retry quota or billing errors.
Spend-limit checklist
- ☐ OpenAI: set a spend alert, which notifies you while traffic keeps flowing.
- ☐ OpenAI: set a hard spend limit for the organization or each project. Past it, requests return
429. - ☐ Anthropic: set your own monthly spend limit on the Console Billing page, below your tier's cap. Past it, requests return
400with "You have reached your specified API usage limits." - ☐ Anthropic: set separate limits per Workspace so one app can't use up the whole budget. (The default Workspace can't have a spend limit.)
- ☐ Use a separate project or Workspace and a separate API key for each app or environment.
- ☐ Teach your code to recognize "spend limit reached" so it doesn't retry it in a loop. On Anthropic, the tier spend-cap
429haserror_code: enforced_spend_limit_reachedand noretry-afterheader. - ☐ Remember that Anthropic batches can go slightly over a Workspace spend limit.
- ☐ Add cost alerts that fire in hours, not at month-end, and have a way to stop traffic fast.
BillCurfew watches your OpenAI, Anthropic and OpenRouter spend, alerts you early, and has a kill switch for runaway jobs. Start free with one key, no card, at billcurfew.com.
Sources
- https://platform.openai.com/docs/guides/batch
- https://docs.anthropic.com/en/docs/build-with-claude/batch-processing
- https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
- https://platform.openai.com/docs/guides/prompt-caching
- https://platform.openai.com/docs/guides/rate-limits
- https://docs.anthropic.com/en/api/rate-limits