ThisCalculator

Everyday

Claude API Pricing: Tokens, Context, and Cost Controls

Updated · Standard formula, shown below

Claude API Pricing: Tokens, Context, and Cost Controls

Claude API pricing is based on tokens processed, with separate rates for input and output tokens, and the cost for a given request depends on the model chosen and the size of the context window. This article explains how token counting works, what context windows mean for your bill, and the specific controls you can use to keep costs predictable.

How Token Counting Works

Claude models, like most large language models, do not charge by the character or word. They charge by tokens. A token is a small chunk of text that the model processes as a unit. As a rough guide, one English word is usually about 1.3 tokens, so a 1,000-word document is roughly 1,300 tokens. Punctuation and spaces count too. The exact tokenization is done by Anthropic’s tokenizer, and you can check the exact count for any string using their tokenizer tool or the API’s count_tokens endpoint.

Two separate token counts are billed for each API call:

  • Input tokens – everything you send to the model: the system prompt, any conversation history, retrieved documents, and the user’s current message.
  • Output tokens – the text the model generates as its response.

Each model family has its own per-million-token price for input and output. For example, a model like Claude Sonnet might cost $3 per million input tokens and $15 per million output tokens, while a larger model like Opus might cost $15 and $75 respectively. These figures change over time, so always check the official pricing page for current rates.

Context Windows and Their Impact on Cost

The context window is the maximum number of tokens the model can consider at once, including both input and output. Claude models offer context windows of 200,000 tokens, with some models supporting 1 million tokens for specific use cases. A larger context window lets you feed in long documents, entire codebases, or extensive conversation histories, but it also increases the input token count directly.

Because input tokens are billed per token, a request that uses 150,000 tokens of context costs 150 times more than a request with 1,000 tokens, even if the model’s response is identical. The context window does not change the per-token price; it simply sets the ceiling on how much you can send in one call.

One common misconception is that the model “remembers” previous conversations across separate API calls. It does not. Each API call is stateless – you must send the full conversation history each time if you want the model to have that context. This means a multi-turn chat application that sends 10 turns of history will bill you for all those tokens on every single turn, not just once.

Understanding the Pricing Tiers

Anthropic offers several models in the Claude family, each with different capabilities and price points. The main tiers are:

  • Claude Opus – the most capable model, best for complex reasoning and long tasks, priced highest per token.
  • Claude Sonnet – a balanced model for most production workloads, moderate pricing.
  • Claude Haiku – the fastest and cheapest model, suited for simple tasks, classification, and high-volume use.

Within each tier, there may be different versions (e.g., Sonnet 4, Sonnet 4.5) with slightly different pricing and context limits. The model you choose is the single largest factor in your API bill. For a task that only needs simple extraction, using Opus when Haiku would suffice can multiply your cost by 10x or more.

Anthropic also offers a Batch API at a 50% discount for requests that do not need real-time responses. This is useful for offline jobs like bulk summarization, where a delay of up to 24 hours is acceptable.

Practical Cost Control Strategies

Reducing token usage is the most direct way to control costs. Here are concrete techniques that work with the Claude API:

  • Trim conversation history – instead of sending every prior turn, summarize older turns into a short paragraph. This drastically reduces input tokens.
  • Set max_tokens – always set a reasonable maximum for output tokens. A model will otherwise generate until it stops, which can be much longer than needed.
  • Use system prompts efficiently – keep instructions concise. A verbose system prompt is charged on every request.
  • Cache frequent prefixes – Anthropic offers prompt caching, where a stable prefix (like a long system prompt or a shared document) is cached and billed at a lower rate. The first time you send it, you pay the full input price; subsequent requests that reuse the same prefix pay a fraction (roughly 10% of the input rate) for the cached portion.
  • Monitor token usage – use the API response’s usage field to log input and output tokens per call. Track this over time to spot unexpected spikes.

Common Mistakes That Inflate Costs

Several recurring errors cause developers to pay more than necessary:

  • Not using prompt caching – if you send the same 50,000-token document in every request, caching it could cut input cost by 90% for those tokens.
  • Forgetting that output tokens are more expensive – output is typically 5x the input price. Encouraging the model to give short answers (e.g., “reply with only the JSON”) saves money.
  • Sending the entire knowledge base every time – instead of including all documents, use retrieval (RAG) to send only the relevant snippets.
  • Using a large context window when you don’t need it – if your requests are under 10,000 tokens, a 200K context model still works, but you are paying the same per-token rate as a model with a smaller window. The window size itself doesn’t change the price, but the model tier that offers the larger window may be more expensive.

Comparing Claude Pricing to Other APIs

Claude’s pricing structure is similar to other major LLM APIs: per-token charges for input and output, with tiered models. Compared to some alternatives, Claude’s per-token rates are mid-to-premium. The key differentiator is the large context window (200K standard) and the prompt caching feature, which can make long-context workloads more affordable than competitors that lack caching.

When comparing, look at the effective cost for your specific pattern. A model with a lower per-token price but no caching may end up more expensive for a chat application with a long system prompt. Conversely, a cheaper model that requires more retries due to lower accuracy could cost more overall. Always benchmark with your own data.

Budget Alerts and Limits

Anthropic provides tools to prevent surprise bills:

  • Usage limits – you can set a monthly spending limit in the Anthropic Console. Once reached, API calls are rejected until the next billing cycle.
  • Email alerts – you can configure notifications when your usage reaches a certain percentage of your limit (e.g., 50%, 80%).
  • Per-request max_tokens – this is the simplest control: cap the output length for every call.

These controls are essential for production applications where a bug in your code could otherwise loop thousands of requests.

Frequently Asked Questions

How do I calculate the cost of a single API call?

Multiply the number of input tokens by the input price per million, add the number of output tokens multiplied by the output price per million. For example, 10,000 input tokens at $3/M and 500 output tokens at $15/M gives $0.03 + $0.0075 = $0.0375.

Does the context window affect the price per token?

No. The context window is the maximum tokens the model can handle, not a factor in the per-token price. The price is set per token regardless of how much of the window you use.

What is prompt caching and how much does it save?

Prompt caching lets you mark a stable prefix of your input (like a system prompt) to be reused across requests. The cached tokens are billed at a much lower rate (about 10% of the input price) after the first request. It can reduce costs by 90% for long, repeated prefixes.

Is the Batch API cheaper?

Yes, the Batch API offers a 50% discount on both input and output tokens, but responses are not real-time – they are processed within 24 hours. This is ideal for bulk jobs like data extraction or summarization.

Can I see how many tokens I’ve used?

Yes, the API response includes a usage object with input_tokens and output_tokens. The Anthropic Console also shows usage graphs and a detailed breakdown by model and date.

What happens if I exceed my context window?

The API returns an error (usually a 400 or 413) and does not process the request. You must reduce the input size, either by truncating history or using a model with a larger window.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.