Optimize
Cost control
In short: Cost control means choosing cheaper models, capping output, using prompt caching and limiting each key's spending so a bug cannot drain your balance.
On this page
Each request costs its tokens at the rates in the models table, taken from a prepaid balance. Nothing renews or charges on its own, and requests stop when the balance reaches $0. This page covers how to spend less and how to make sure a bug cannot spend more than you intend.
What a request costs
cost = input_tokens × input rate / 1,000,000
+ output_tokens × output rate / 1,000,000
rounded to the nearest $0.000002 (at least $0.000002 on a paid model)
(cached input tokens use the cached rate; reasoning tokens count as output)For example, a request with 3,000 input tokens and 800 output tokens costs:
| Model id | Input / 1M | Output / 1M | This request |
|---|---|---|---|
| qwen-qwen3.8-27b:free | $1.40 | $7 | $0.0098 |
| gpt-6-luna:free | $0.70 | $3.50 | $0.0049 |
| z-ai-glm-5.3-flash:free | $0.07 | $0.21 | $0.000378 |
| stepaudio-3-chat-preview:free | Free | Free | $0 |
Output tokens cost several times more than input tokens on most models, so long answers and long thinking are usually where the money goes. The exact cost of every request is on the usage page, which you can filter by model and key and export as CSV.
The cost in the reply. The usage object of a reply also carries cost: the amount in US dollars this call took from your balance or your plan allowance, worked out with the formula above. Non-streamed replies have it in the body. In a stream it is in the usage event: on chat completions send "stream_options": {"include_usage": true}; the Responses API puts it in response.completed, the Anthropic format in message_delta.
cost is left out, never estimated, when the exact amount is not known at that point: calls paid by a coupon or priced at a discount, calls with cache-write, image or audio tokens, Anthropic cache reads, built-in tools such as web search, and keys in the auto group. The usage page always has the final amount.
How can I spend less per request?
- Pick the smallest model that does the job. Try a fast model first and move up only for the requests where it falls short. Every model shares the same API, so this is a one-line change.
- Cap the output. Set
max_tokenson every request. Without it, a model can write until its own maximum, and you pay for every token. - Turn reasoning down. On reasoning models,
reasoning_effort: "low"often answers as well for routine work, with far fewer output tokens. - Send less history. The whole conversation is billed on every turn. Drop old turns, summarise them, and remove images once they have been discussed.
- Reuse prefixes. Keep long instructions and documents at the start of the prompt so prompt caching bills them at the cached rate.
- Ask for short answers. “Answer in at most three sentences” in the system prompt is the cheapest optimisation there is.
Which models are free or discounted?
Free models cost nothing per token, and discounted models cost less than their usual rate until an end date.
When free models are listed, they cost nothing per token. Models on the free lane (ids ending in :free) carry no rate of their own and share one allowance: 100 requests and 3,000,000 tokens a day for every account, in Chat and through the API. Each person has 1 API key and 1 request at a time. Flagship ids use more of it: Claude Opus, Claude Fable, Step 5 and uncensored models count 3 requests (33 a day) and Claude Sonnet counts 2 (50 a day), with tokens weighted the same way. No balance and no card are needed: the $10 sign-up credit pays for priced models first, and once it is gone the models that bill $0 keep their daily requests. A paid subscription, a coupon or the owner raising your account is the only way past the daily number. Discounted models are listed on the models page with their end dates.
Limit what a key can spend
Give every app, environment and teammate its own key under API keys, and set on each:
- Spend limit: the most this key can ever spend. When it is used up the key stops working; your balance and your other keys are not affected.
- Expiry date: for temporary access, demos and contractors.
- Model list: only the models this key may call, so a typo or a changed config cannot switch an app to an expensive model.
- Spend per end user: if your app serves its own users through one key, the most each of them can spend in an hour, a day, 7 or 30 days. Send the end user’s id in the
userfield (ormetadata.user_idfor Anthropic Messages); see per-key limits.
See Authentication and keys for how each setting behaves.
How do I cap the whole account?
A key limit protects one key. An account spend cap protects the balance itself: under Settings, set an amount per day, week or month (all UTC). Every metered request on the account counts, from any key, the console Playground and the browser chat.
- When the cap is reached, paid models are refused with
429, codeaccount_spend_cap, and aRetry-Afterthat counts down to the reset. Free models still answer. - A cap of $0 switches paid models off for the account without touching the keys.
- The request that crosses the cap still finishes, so the total can end slightly above it.
- An optional warning percentage shows a notice under Settings before the cap is reached; pair it with a low-balance alert for email or a webhook.
How do I keep an eye on spending?
- The usage page shows each request with its model, key, tokens and cost, for up to 30 days at a time.
- The billing page shows your balance, what you have spent to date, and a notice when the balance is empty.
- The API response itself carries token counts in
usage, not prices. Multiply by the rates if you want to track cost in your own logs.
Usage reports by email. Under Settings in the console you can opt in to a daily, a weekly and a monthly report. Each covers the last finished period (UTC day; week from Monday; calendar month): spend and requests compared with the period before, tokens, your top 3 models and top 3 keys, and your balance with an estimate of how long it lasts at that rate. A period without billed requests sends no report. Reports go to the email address on your account, and to your alert webhook or Slack if you set one; every report email has its own unsubscribe link.
Related
- Pricing and billing: how the balance, credit packs and plans work.
- Models: every rate.
- Account security and alerts: a webhook alert when the balance runs low.