Anthropic API billing असल में कैसे काम करती है
Updated 2026-07-15
Anthropic API को per token bill करता है: input के लिए एक rate, output के लिए higher rate, और prompt cache writes और reads के लिए अलग rates, सब prepaid credits से draw होते हैं। ज्यादातर surprise bills output tokens और re-send हुई conversation history से आते हैं, headline input price से नहीं।
Quick answer: आपसे actually किस चीज़ के लिए charge किया जाता है
Anthropic Claude API को per token charge करता है, prepaid basis पर। आप developer console में credits खरीदते हैं, और हर request उस balance को तीन meters पर draw down करती है: input tokens (जो कुछ आप भेजते हैं), output tokens (जो कुछ model generate करता है, thinking tokens समेत), और prompt cache traffic (writes input rate का 1.25x bill होते हैं, reads 0.1x पर)। खुद API के लिए कोई subscription नहीं है, और Claude Pro या Max subscription API credits include नहीं करती। Output महंगा meter है। Claude Sonnet 4.6 का list price $3.00 per million input tokens और $15.00 per million output tokens है, यानी 5x gap। Claude Opus 4.7 का list price $5.00 in और $25.00 out है। अगर आपका bill expected से ज्यादा है, तो सबसे पहले output volume और conversation history growth check करें।
तीन meters: input, output, और cache tokens
Input सिर्फ user के message से कहीं ज्यादा cover करता है। System prompt, पूरी conversation history, tool definitions, tool results, और images, ये सब हर उस request पर input tokens में count होते हैं जिसमें ये शामिल हों। Output वह सब कुछ cover करता है जो model वापस लिखता है, और reasoning-capable models पर इसमें thinking tokens भी शामिल हैं जो आप कभी user को show भी नहीं करते। Prompt caching तीसरा meter है और वह जिसे ज्यादातर teams unused छोड़ देती हैं। आप एक stable prefix (एक लंबा system prompt, एक document, एक fixed tool list) को cache_control breakpoint से mark करते हैं। पहली request default 5-minute cache के लिए input rate का 1.25x write premium pay करती है; जो भी request window के अंदर उस prefix को reuse करती है वह इसे 0.1x पर वापस read करती है। एक 1-hour cache भी 2x write rate पर available है। नीचे दो flagship Claude models के लिए official list prices पर पूरा rate card है।
| Meter | क्या count होता है | Sonnet 4.6 | Opus 4.7 |
|---|---|---|---|
| Input tokens | System prompt, history, message, tools, images | $3.00 / 1M | $5.00 / 1M |
| Output tokens | Model responses, thinking tokens समेत | $15.00 / 1M | $25.00 / 1M |
| Cache write (5 min) | Cached prefix की पहली write, input का 1.25x | $3.75 / 1M | $6.25 / 1M |
| Cache read | Cached prefix का reuse, input का 0.1x | $0.30 / 1M | $0.50 / 1M |
एक worked example: एक chatbot, एक दिन
official rates पर Claude Sonnet 4.6 पर एक support chatbot लें: प्रति दिन 10,000 requests, हर एक में 2,000-token system prompt plus 1,500 tokens की history और user message, जिसका जवाब 500-token reply में दिया जाता है। Table वही workload system prompt cached और uncached दोनों तरह से दिखाती है। Caching के बिना दिन का cost $180.00 होता है, यानी लगभग $5,400 प्रति महीना। System prompt को cache करने से (5-minute window पर लगभग 300 cache expirations मानते हुए) यह घटकर करीब $128 प्रति दिन, लगभग $3,840 प्रति महीना हो जाता है। ध्यान दें कि क्या नहीं बदला: output cost। Caching केवल input को touch करती है, यही वजह है कि output discipline किसी भी दूसरे single lever से ज्यादा मायने रखती है।
| Line item | Tokens प्रति दिन | Rate प्रति 1M | Daily cost |
|---|---|---|---|
| Input, बिना caching | 35,000,000 | $3.00 | $105.00 |
| Output, बिना caching | 5,000,000 | $15.00 | $75.00 |
| Caching के बिना Total | 40,000,000 | $180.00 | |
| Cache writes (system prompt) | 600,000 | $3.75 | $2.25 |
| Cache reads (system prompt) | 19,400,000 | $0.30 | $5.82 |
| Uncached input (history + message) | 15,000,000 | $3.00 | $45.00 |
| Output | 5,000,000 | $15.00 | $75.00 |
| Caching के साथ Total | 40,000,000 | $128.07 |
Anthropic bills teams को surprise क्यों करते हैं
चार patterns ज्यादातर "bill estimate से कई गुना ज्यादा क्यों है" वाली conversations explain करते हैं। 1. Output input का 5x है, और thinking भी output में count होती है। Estimates input rate पर anchor होते हैं क्योंकि वही number सबसे पहले quote होता है। लेकिन लंबे answers, verbose formatting, और extended thinking, सब output rate पर bill होते हैं। एक model जो answer देने से पहले 3,000 tokens तक reason करता है और फिर 500 में जवाब देता है, वह एक छोटे से दिखने वाले reply के लिए 3,500 output tokens bill करता है। 2. History हर turn पर फिर से bill होती है। API stateless है, इसलिए हर turn पूरी conversation को input के रूप में फिर से भेजता है। औसतन 20 turns वाला chat single turn का 20x cost नहीं करता; यह उससे कहीं ज्यादा cost करता है, क्योंकि turn 20 पिछले 19 turns को input के रूप में carry करता है। जब तक आप trim या summarize नहीं करते, input cost लगभग conversation length के square के हिसाब से बढ़ता है। 3. Subscriptions और API credits अलग हैं। Claude Pro और Max Claude apps को cover करते हैं, API को नहीं। Teams मान लेती हैं कि subscription API traffic को absorb कर लेगी, फिर पता चलता है कि console चुपचाप auto-reload enabled prepaid balance से draw कर रहा था। 4. Request में सब कुछ input है, और attribution मुश्किल है। Tool definitions, tool results, images, और system prompts हर उस request पर input के रूप में bill होते हैं जिसमें ये शामिल हों। इसे कई API keys, environments, और features में बिना per-key logging के फैला दें, और invoice आने तक कोई नहीं बता सकता कि किस feature ने पैसा खर्च किया।
Anthropic बनाम OpenAI billing, side by side
दोनों providers एक जैसे तरीके से meter करते हैं: per token, अलग input और output rates, by default prepaid credits। जो अंतर आपके bill के लिए मायने रखते हैं वे cache mechanics और spend controls में हैं। Practical फर्क caching में है। OpenAI automatically prompt caching apply करता है, कोई write fee नहीं और cached portion पर discount। Anthropic में आपको खुद cache_control breakpoints place करने पड़ते हैं, यह write premium charge करता है, और बदले में input rate के 0.1x पर कहीं सस्ते reads देता है। लंबे stable prompts वाले workloads के लिए, सही तरीके से किया गया Anthropic caching एक stronger lever है; गलत तरीके से किया जाए (system prompt में एक timestamp, एक unstable tool list), तो यह चुपचाप कभी hit ही नहीं होता और आप full price plus write premiums pay करते हैं।
| Billing detail | Anthropic | OpenAI |
|---|---|---|
| Billing की unit | Per token, अलग input और output rates | Per token, अलग input और output rates |
| Payment model | Prepaid credits; usage tiers rate limits बढ़ाते हैं | By default prepaid credits |
| Prompt caching | Explicit cache_control; write 1.25x, read 0.1x | Automatic; cached input पर discount, कोई write fee नहीं |
| Cache lifetime | Default 5 minutes, 2x write rate पर 1 hour | आपके लिए managed, typically minutes से लेकर एक hour तक |
| Batch discount | Batches API के through 50% off | Batch API के through 50% off |
| Reasoning tokens | Thinking tokens output के रूप में bill होते हैं | Reasoning tokens output के रूप में bill होते हैं, reply में नहीं दिखते |
| Spend controls | Workspace spend limits, optional auto-reload | Project budgets और alerts |
Ship करने से पहले अपना Anthropic API cost कैसे estimate करें
हर API response में एक usage object होता है जिसमें exact input_tokens और output_tokens होते हैं, plus caching active होने पर cache_creation_input_tokens और cache_read_input_tokens। वह object ही ground truth है। दूसरे providers के लिए बने client-side tokenizers Claude tokens को undercount करते हैं, इसलिए उनसे estimate न करें। तरीका यह है: कुछ representative requests भेजें, usage object पढ़ें, और counts को average करें। फिर यह formula apply करें: cost = (input_tokens / 1,000,000 x input rate) + (output_tokens / 1,000,000 x output rate), plus अगर आप cache करते हैं तो cache write और read terms। Expected daily volume से multiply करें, और multi-turn products के लिए growth headroom add करें क्योंकि history हर turn पर input को ऊपर धकेलती है। कुछ भी भेजने से पहले counts चाहिए तो Anthropic एक count_tokens endpoint भी expose करता है।
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "Summarize this ticket: ..."}]
}'
# Response आपके cost model के लिए ground truth include करता है:
# "usage": {"input_tokens": 2412, "output_tokens": 486,
# "cache_read_input_tokens": 0, "cache_creation_input_tokens": 0}अपना Anthropic API bill कम करने के पांच तरीके
पांचवीं tactic वह जगह है जहां एक gateway अपनी जगह earn करता है। APIsRouter एक OpenAI-compatible gateway है जो हर request, हर API key पर model, input tokens, output tokens, और exact dollar cost log करता है, ताकि हर feature या environment को usage view में अपनी खुद की key और अपनी खुद की line मिले। यह Claude Sonnet 4.6 को $2.40 input और $12.00 output per million tokens पर list करता है और Claude Opus 4.7 को $4.00 और $20.00 पर, जो official list से 20% कम है, pay-as-you-go billed होता है और कोई subscription नहीं; /topup पर पहला top-up double हो जाता है। किसी existing OpenAI SDK integration को इस पर point करना बस एक two-line change है:
- अपने लंबे, stable prefixes को cache करें। एक system prompt या document जो requests में repeat होता है, पहली write के बाद हर cache read पर input rate का दसवां हिस्सा bill होता है।
- History trim करें और max_tokens cap करें। पुराने turns को फिर से भेजने के बजाय summarize करें या drop करें, और max_tokens को task की जरूरत के हिसाब से set करें ताकि कोई runaway answer हजारों extra output tokens bill न कर दे।
- Habit से नहीं, task के हिसाब से route करें। Opus को उन steps के लिए reserve करें जिन्हें actually इसकी जरूरत है, और bulk classification, extraction, और drafts को deepseek-v4-flash या glm-5 जैसे cheaper models पर push करें।
- जो भी asynchronous हो उसे batch करें। Batches API requests को 24 hours के अंदर half price पर process करती है, backfills, evals, और nightly jobs के लिए ideal।
- अपने traffic के सामने per-key cost visibility रखें। ज्यादातर billing surprises attribution problems होती हैं: invoice आने तक कोई नहीं बता सकता कि किस feature या customer ने पैसा खर्च किया।
from openai import OpenAI
client = OpenAI(
api_key="sk-APIsRouter-...",
base_url="https://api.apisrouter.com/v1",
)
response = client.chat.completions.create(
model="claude-sonnet-4-6",
messages=[{"role": "user", "content": "Summarize this ticket: ..."}],
)
# Token counts हर response पर वापस आते हैं; gateway console
# इसके अलावा इस key के तहत इस request की exact cost भी record करता है।
print(response.usage.prompt_tokens, response.usage.completion_tokens)अक्सर पूछे जाने वाले प्रश्न
Anthropic API billing कैसे काम करती है?
आप credits के लिए prepay करते हैं, और हर request tokens के आधार पर cost deduct करती है: input एक rate पर, output higher rate पर, और prompt cache writes और reads input rate के 1.25x और 0.1x पर। Rates model के हिसाब से अलग होते हैं, और जैसे-जैसे आपका cumulative spend बढ़ता है usage tiers higher rate limits unlock करते हैं।
क्या Claude Pro या Max में API credits शामिल हैं?
नहीं। Subscriptions Claude apps को cover करती हैं; API developer console में एक prepaid credit balance से अलग bill होता है। API traffic को subscription के against budget करना unexpected bill के सबसे common कारणों में से एक है।
मेरा Anthropic API bill इतना ज्यादा क्यों है?
सामान्य कारण, क्रम में: output tokens (input rate का 5x, और thinking tokens भी output में count होते हैं), conversation history हर turn पर re-send और re-bill होना, और कई keys में unattributed traffic। Models switch करने से पहले per-request usage logs निकालें; अक्सर पता चलता है कि ज्यादातर spend के लिए एक ही endpoint या एक ही prompt जिम्मेदार है।
Anthropic API पर spending limit कैसे set करूं?
Anthropic Console में आप workspace spend limits set कर सकते हैं और control कर सकते हैं कि credits auto-reload हों या नहीं। हर workspace के लिए एक hard limit set करें और experiments के लिए auto-reload disable करें। एक prepaid gateway balance भी एक natural ceiling की तरह काम करता है, क्योंकि balance खत्म होने पर requests आपके budget से आगे bill होने के बजाय रुक जाती हैं।
Claude API का cost प्रति request कितना होता है?
अपने token counts को model rates से multiply करें। Claude Sonnet 4.6 पर 2,000 input tokens और 500 output tokens वाली request का cost 2,000/1M x $3.00 plus 500/1M x $15.00 होता है, official rates पर करीब $0.0135। Claude Opus 4.7 पर वही request करीब $0.0225 की होती है।
क्या prompt caching वाकई Anthropic API costs कम करती है?
हां, जब requests minimum cacheable size (model के हिसाब से लगभग एक से चार हजार tokens) से ऊपर का एक stable prefix share करती हैं। Cache reads input rate के दसवें हिस्से पर bill होते हैं, इसलिए 1.25x write के बाद एक reused system prompt $3.00 से घटकर $0.30 per million tokens हो जाता है। यह output tokens के लिए कुछ नहीं करता, जिन्हें caching touch नहीं कर सकती।