cocodot
← Back to guides
Local card declined for overseas AI? cocodot: one card + one key
AI APIUpdated 2026-08

Why Is My AI API Bill Higher Than Expected? Hidden Tokens and How to Cut API Costs (2026)

Tool prompts, thinking tokens, resent history, a new tokenizer and retries add tokens you never typed. Find each one in usage, then cut it.

TL;DR: When an API bill is higher than your estimate, check for tokens you never typed before suspecting a pricing error. Estimates tend to count the words in your prompt and the visible answer. The bill counts everything the request carried and everything the model generated. On Anthropic's API the official pricing documentation lists several sources of extra tokens: a tool use system prompt added whenever tools are present, the tool definitions themselves, conversation history and web search results resent as input on later turns, thinking tokens billed in full as output even when only a summary is returned, and a newer tokenizer on Claude 4.7 and later models that produces roughly 30 percent more tokens for the same text. Retries add whole attempts on top. The fix starts with evidence: log the usage object of every response, split it into input, cache reads, cache writes, output and thinking tokens, and compare those lines with your statement. Then cut the largest line first. Each section below names the usage field to check and the change that reduces it.

1. Compare the estimate with the statement, line by line

Before changing anything, find out which line of the bill is larger than you expected. Every response from Anthropic's Messages API carries a usage object with input_tokens, output_tokens, cache_creation_input_tokens and cache_read_input_tokens, and server tools such as web search report their own usage. Log that object for every request, together with the model, a request identifier and your own task identifier. After a day, total each field per model and per task type, then set those totals next to your estimate. Look for the one or two lines with the largest gap. Input higher than expected points to sections 2 and 3; output higher than expected points to section 4; everything higher by a similar proportion after a model change points to section 5; more requests than user actions points to section 6. Without this split, people tend to switch models or vendors first, which changes the price without removing the tokens that caused the surprise.

2. Hidden input: the tool use system prompt and tool definitions

Anthropic's pricing page states that when a request includes tools, the API automatically adds a special system prompt that enables tool use, and those tokens are added to your normal input. The page lists the count per model: for example 286 tokens on Claude Opus 5.5 and Claude Sonnet 5.5, and 497 tokens on Claude Sonnet 4.6 when tool_choice is auto or none, rising to 589 when it is any or tool. Your own tool names, descriptions and JSON schemas are input tokens on top of that, on every call. Larger built-in toolsets weigh more: the same page puts the computer use toolset at about 4,500 input tokens and the browser use toolset at about 6,600 per request. None of this appears in the prompt you wrote. To cut it, send only the tools a given step can use, keep descriptions short and precise, and avoid forcing tool_choice when auto is enough. Because the overhead repeats on every turn, it multiplies with agent length.

3. Hidden input: history, search results and long agent loops

The Messages API is stateless, so each turn resends the conversation you want the model to see, and the input line grows with every turn. Tool results are part of that history: a large file read or database dump returned by a tool is carried into every later call unless you remove it. Web search adds a second layer. The official pricing page lists web search at $10 per 1,000 searches plus standard token costs, and states that search results retrieved during a conversation count as input tokens both within the turn and in later turns. It also says a search that errors is not billed, and that web fetch has no charge beyond the tokens of the fetched content. Practical changes: summarize older turns once a conversation passes a length you choose, replace bulky tool results with a short extract once they have been used, and cap the number of searches per task. If the same long prefix repeats, prompt caching changes its price; see /hub/prompt-caching-guide.

No overseas card needed: cocodot's OpenAI-compatible API — switch your base_url to call the models on sale.

Top up via Alipay / WeChat Pay (RMB), USDT / USDC · billed per token · switch your base_url to connect

4. Hidden output: thinking tokens are billed in full

With extended thinking, Anthropic's documentation is explicit that the billed output token count does not match the visible token count in the response: you are billed for the full thinking process, not the summarized thinking text you receive. The response reports how many of the billed output tokens were internal reasoning in usage.output_tokens_details.thinking_tokens; when streaming, that breakdown appears only on the final message_delta event. Subtracting it from output_tokens approximates the non-reasoning part of the answer. If your estimate counted only the visible text, check how much of the gap this field accounts for. Check the field per task type. For extraction, formatting or classification, test a lower supported thinking setting and compare accepted results before changing production; do not assume a task category determines the required effort. Keep thinking for the steps where it changes the outcome, and record the setting alongside the usage so later changes are traceable.

5. A model upgrade can change the token count for the same text

Token counts are not a property of your text alone; they depend on the model's tokenizer. Anthropic's pricing page states that Claude 4.7 and later models use a newer tokenizer that produces approximately 30 percent more tokens for the same text than earlier models, and the token counting documentation adds that usage and billing on these models reflect the new counts. So a team that moves from an older model to a newer one can see every token line rise by a similar proportion with no change to prompts. Do not reuse counts measured on the old model. Count with the model ID you plan to use: the official token counting endpoint is free to use, subject to its own requests-per-minute limit, which is separate from message creation. Its result is an estimate that can differ slightly from the actual count, and it does not apply caching logic. Run your test set through it before a migration and adjust estimates accordingly.

6. Retries and truncation: paying for the same work twice

A user action can turn into several billed attempts. Anthropic's official SDKs retry certain errors twice by default, Claude Code retries up to 10 times by default, and many applications add their own retry loop on top, so one failure can multiply. Streaming adds a subtlety documented on the errors page: a response can return HTTP 200 and still report an error inside the stream. Log every attempt with its request identifier, then compare attempts with user actions; if the ratio is well above one, keep a single retry layer with backoff and a total attempt limit. Truncation is the other loop. When a response stops with stop_reason max_tokens, the official guidance is to raise max_tokens or continue the response. Resending the whole request from scratch pays for the input again and regenerates what you already had. Set max_tokens per task type, check stop_reason on every response, and continue rather than restart when an answer is cut off.

7. Cut in the order your usage data points to

With the split from section 1, change the largest line first and measure again after each change. If tool overhead dominates, load tools per step. If history dominates, summarize and trim. If thinking dominates, lower it for simple calls. If input repeats a long stable prefix, enable prompt caching: on cocodot, Claude cache hits at half the input price; Claude cache writes at 1.25x the input price (2x for the portion written to the 1-hour cache), the same structure as the official pricing, and the official cache-hit multiplier is lower, which /hub/ai-api-official-vs-relay-when works through. If simple tasks run on a large model, test a smaller one on the same acceptance rules; /hub/llm-cost-optimization-2026 covers routing and evaluation. Change one thing at a time, otherwise you cannot tell which change moved the bill. Keep the before and after usage totals with the date, the model and the prompt version, so the next review starts from evidence rather than memory.

8. Keep the bill readable, and where cocodot fits

Two habits keep surprises small. First, review usage weekly by model and by task, not just the monthly total; the largest line this week is next week's target. Second, keep guardrails in your own code: a per-task attempt limit, a per-job token allowance and a deadline. Do not assume a budget alert stops charges. Whether the platform offers a spending cap that stops usage, and which services it covers, is set out in its official documentation. A prepaid balance is not a hard cap: requests already in flight when the balance runs out may still be billed; your statement is the record. cocodot bills per token through one OpenAI-compatible endpoint, https://cocodot.co/api/ai/v1, for Claude, GPT, Gemini and other model families. Listed Claude / GPT / Gemini rates are at or below the official list price; check the pricing page for each model's current rate. For runaway-spend patterns specific to agents, see /hub/api-relay-runaway-risk.

Symptom → where the tokens come from → what to change

What you seeLikely source of extra tokensWhat to change
Input much higher than your promptTool use system prompt and tool definitions on every callSend only the tools a step needs
Input grows turn after turnFull history and earlier web search results resentSummarize or trim older turns
Output much longer than the visible answerThinking tokens billed in fullRead thinking_tokens; lower thinking effort for simple work
Same prompt, more tokens after a model upgradeNewer tokenizer on Claude 4.7 and laterRecount with the token counting endpoint
More requests than user actionsSDK and application retries stackingLog attempts; keep one retry layer
Answers cut off, then asked againstop_reason max_tokens followed by a full resendRaise max_tokens or continue the response

FAQ

Why is my Claude API bill higher than my token estimate?

Check first for tokens the request carried that you did not count: the tool use system prompt and tool definitions, resent history, earlier search results, full thinking tokens billed as output, or a newer tokenizer. Log the usage object of each response and compare it field by field with your statement to find which one.

Are thinking tokens billed as output?

Yes. Anthropic's documentation states that you are billed for the full thinking process, not the summarized thinking visible in the response. The field usage.output_tokens_details.thinking_tokens shows how many billed output tokens were reasoning.

Do tools cost tokens even when the model does not call them?

When a request includes tools, the API adds a tool use system prompt whose size per model is listed on the official pricing page, and your tool definitions are input tokens too. Both are counted on every request that includes them, so send only the tools a step needs.

Is the token counting endpoint free?

Anthropic's documentation says token counting is free to use, with its own requests-per-minute limit that is separate from message creation. The count is an estimate and does not apply caching, so treat it as a planning number and confirm against the usage of real requests.

Does web search cost extra on the Claude API?

The official pricing page lists web search at $10 per 1,000 searches plus standard token costs, and the retrieved results count as input tokens in later turns too. A search that errors is not billed. Prices change, so check the official pricing page for the current figure.

About cocodot

cocodot is a payment and AI access service for developers and cross-border teams in mainland China. It provides US-BIN virtual cards issued by a licensed institution — used to pay for overseas subscriptions and ad accounts — and an OpenAI-compatible AI API gateway for calling Claude, GPT and Gemini from within mainland China. Both share one wallet, funded by Alipay / WeChat Pay (RMB), USDT / USDC and accounted in USD. Card: $9.9 to open, 3% to load, $1 per active card per month; spending: $0.60 settlement fee on purchases under $20; a corresponding fee applies when the issuer charges one.

Service scope, pricing and limits →
OpenAI-compatible API, pay in RMBGet API access