59API

← सभी गाइड पर लौटें

Claude API Pricing: Input, Output and Cache Tokens

मूल्य · EN · 2026-09-17

Claude API pricing starts with three token types

Claude API costs are measured in tokens, not requests. A token is a small unit of text: English prose averages roughly four characters per token, while source code, JSON, and non-English text can tokenize differently. To estimate a Claude request correctly, separate it into input tokens, output tokens, and, when prompt caching is enabled, cache-write and cache-read tokens.

The basic calculation is: total cost = input tokens x input rate + output tokens x output rate + cache-write tokens x cache-write rate + cache-read tokens x cache-read rate. Rates differ by model tier, so Opus, Sonnet, Haiku, and Fable should be budgeted independently. Always use the current price table from your provider before committing a production budget.

Input tokens: everything Claude must read

Input tokens include the system prompt, user message, prior conversation history, tool definitions, attached text, and any retrieved documentation you send with the request. A 20,000-token repository guide costs input tokens every time it is included unless you use caching.

For example, this Python request sends a system instruction plus a user task. Both contribute to input usage.

from anthropic import Anthropic

client = Anthropic(base_url="https://api.59api.com", api_key="YOUR_59API_KEY")
response = client.messages.create(
    model="claude-sonnet",
    max_tokens=700,
    system="You review Python pull requests and identify correctness issues.",
    messages=[{"role": "user", "content": "Review this diff: ..."}]
)

Keep input costs under control by sending only relevant files, trimming old chat turns, and retrieving focused document chunks instead of inserting an entire knowledge base. This often saves more than changing models.

Output tokens: what Claude generates

Output tokens are Claude's generated answer, including code, explanations, structured JSON, and tool-call arguments. Output pricing is commonly higher than input pricing, so max_tokens is a financial control as well as a response-length setting. Set it near the amount of output the task actually needs.

For a classification endpoint, 100 output tokens may be sufficient. For a refactor that must return a complete file, a larger ceiling is reasonable. Avoid setting max_tokens to a very high value by default, especially for requests that can occasionally become verbose.

Cache tokens: reuse large stable prompts

Prompt caching is useful when many requests share a large prefix, such as coding standards, product documentation, or a repository map. The first request writes that stable material to cache, producing cache-write tokens. Later requests that reuse the same cacheable prefix can consume cache-read tokens, which are generally priced more favorably than repeatedly sending the same material as ordinary input.

The important detail is that cache reuse depends on an identical, cacheable prompt prefix and the provider's cache lifetime rules. Put stable instructions and reference material first; append the changing user request afterward. Do not place a timestamp, random request ID, or per-user data in the cached prefix, because it can prevent a cache hit.

A practical layout is: system rules, stable repository context, cached documentation, then the current ticket. Measure usage in API responses or provider logs and compare the cache-read count with normal input volume. If a shared prefix is small or rarely reused, caching may add complexity without meaningful savings.

Estimate a real request before shipping

Suppose a coding assistant sends 12,000 tokens of repository context and produces 800 tokens of review notes. Without caching, each call is billed for the full 12,000-token input plus 800-token output. If the repository context is stable across 100 reviews, cache the stable portion: the initial cache write has its own charge, while subsequent reviews can use cache reads and only send their changing ticket details as regular input.

For cost-effective access, 59API provides pay-as-you-go Claude and GPT model access through https://api.59api.com, with compatibility for Claude Code, Codex, and OpenAI SDK integrations. It uses native official-quality models rather than downgraded substitutes, so teams can select Opus, Sonnet, Haiku, or Fable based on the task while keeping integration changes small. Its low relay pricing and referral rebate are especially useful when you are testing model routing or operating variable workloads.

Start by logging token usage per endpoint, set model-specific output limits, then test cached and uncached versions of your largest recurring prompt. Developers who want a low-cost compatible endpoint can sign up for 59API and validate those measurements with their own traffic.

मूल्य · दस्तावेज़

शुरू करने के लिए तैयार?

कुछ ही मिनटों में Claude और GPT जोड़ें, सबसे कम कीमत पर। साइन अप करें और API key पाएं।

मुफ़्त साइन अप