Claude API Token Pricing: Inputs, Outputs & Cache
Claude API pricing starts with three token meters
Claude API costs are easier to control when you separate every request into input tokens, output tokens, and cache-related tokens. These are distinct billing categories, not different names for the same prompt length. A request can contain all three: new context sent to Claude, previously cached context read from storage, and the model response it generates.
The practical formula is: total request cost = new input tokens + cache-write tokens + cache-read tokens + output tokens, each multiplied by that model's applicable rate. Exact rates differ between Claude Opus, Sonnet, Haiku, and newer offerings, so always consult the active model pricing before estimating production spend.
1. Count input tokens as new context
Input tokens are the text, code, images, tool definitions, system instructions, and conversation history that Claude must process as new context. They are charged when they are not served from a prompt cache. For a coding agent, input can grow quickly because each turn may include repository instructions, file contents, terminal output, diffs, and prior messages.
- Keep system prompts precise. Remove duplicate rules and outdated instructions.
- Send only files relevant to the current task instead of a whole repository snapshot.
- Summarize older conversation turns after decisions are made.
- Put stable, reusable context at the beginning of the prompt so it can be cached.
A common cost mistake is treating a long prompt as harmless because the answer is short. A 20-token response can still be expensive if every call repeatedly sends 50,000 tokens of uncached project context.
2. Treat output tokens as the controllable generation budget
Output tokens are everything Claude generates: explanations, code, JSON, tool calls, and structured reasoning exposed in the response. Output pricing is typically higher than standard input pricing, particularly on premium models. That makes output limits a direct lever for controlling spend.
Set a realistic maximum output token limit for each workflow. A classifier may need only a few hundred tokens, while a code-generation task may need several thousand. Ask for a specific format and scope: for example, request a patch plus a short rationale rather than a broad tutorial. For extraction jobs, require valid JSON with only the required fields. Clear constraints reduce both unnecessary output and retries caused by unusable responses.
3. Understand cache writes versus cache reads
Prompt caching is the key optimization for repeated large context. A cache write occurs when Claude stores an eligible prompt prefix for reuse. A cache read occurs when a later request reuses that stored prefix within its cache lifetime. Cache writes have their own rate because context must be prepared and stored; cache reads are usually substantially cheaper than reprocessing the same tokens as ordinary input.
Anthropic-style caching is prefix-sensitive. The reusable material must appear identically and in the same order before the changing portion of later requests. Put stable content first: system instructions, API schemas, coding standards, documentation, and a persistent repository summary. Put the variable user question, current file diff, or latest tool result after that stable prefix.
- Use one consistent system prompt across a session.
- Do not insert timestamps, request IDs, or changing metadata into the cacheable prefix.
- Keep tool definitions stable; changing a schema can prevent reuse.
- Batch related requests close together so cached context remains available.
- Measure cache-read tokens separately from total input tokens in logs.
4. Choose the model by token economics, not reputation alone
Use Claude Opus when the task genuinely benefits from its strongest reasoning, such as difficult architecture decisions or high-stakes code review. Sonnet is often the practical default for agentic development and complex production workflows. Haiku is well suited to routing, extraction, labeling, short summaries, and other high-volume tasks. For any additional Claude variants available through your provider, evaluate them against real prompts rather than assuming a larger model is automatically cheaper overall.
A useful pattern is model routing: run inexpensive classification or retrieval first, then send only difficult cases to a stronger Claude model. This reduces both input and output spend while retaining quality where it matters.
5. Use a relay that preserves compatibility and cost visibility
59API is a low-cost, pay-as-you-go option for developers who need Claude Opus, Sonnet, Haiku, Fable, and GPT models without changing their established tooling. Its API endpoint, https://api.59api.com, is compatible with Claude Code, Codex, and OpenAI SDK workflows, making it practical to compare models or route workloads with minimal integration friction. Because it provides native official-quality models rather than downgraded substitutes, optimization can focus on prompt design, caching, and model selection instead of compensating for weaker outputs.
Track tokens by model, endpoint, cache status, and feature. After a week of production data, identify the largest repeated prompt prefixes and the endpoints with excessive output. Then apply caching and tighter output caps before reducing model quality. Developers looking for lower-cost access can sign up for 59API and use its referral rebate alongside disciplined token budgeting.
शुरू करने के लिए तैयार?
कुछ ही मिनटों में Claude और GPT जोड़ें, सबसे कम कीमत पर। साइन अप करें और API key पाएं।
मुफ़्त साइन अप