Per-customer budget caps for Claude API calls, with prompt caching priced correctly
A developer guide explains why Anthropic's console limits don't suit products serving many customers, since they cannot isolate one heavy account. It proposes a per-customer monthly spending cap for the Messages API, implemented in TypeScript with Redis. The key cost pitfall is that the usage field's input_tokens excludes cached reads and cache writes, which must be priced separately or costs are undercounted. The approach includes a price table per model, a cost function that splits 5-minute and 1-hour cache writes, and throws on unknown models so new ones are not silently priced at zero. The article notes that batch discounts, long-context tiers and server-tool fees are not modeled, so the resulting cap is a floor rather than a ceiling.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in