AI coding agents often incur higher costs than expected due to reasoning tokens and inefficient cache usage. Reasoning tokens, which are invisible in the final output, are billed at the same rate as completion tokens. In some cases, these tokens can account for up to 90% of the total output volume.
Caching relies on matching the exact prefix of a request. Any variation in the system prompt, tool definitions, or project rules results in a cache miss. Factors such as dynamic timestamps, random request IDs, or changing the order of tools prevent effective caching and lead to increased expenses.
To optimize costs, developers should maintain a stable prefix, sort tool lists deterministically, and append new context only at the end of prompts. Using the Anthropic protocol for Claude is recommended, as OpenAI-compatible endpoints may fail to report cache usage correctly, leading to unnecessary full-price billing.
Monitoring usage via logs is essential for cost management. Key metrics to track include the cache hit rate and the proportion of reasoning tokens in the output. High cache hit rates are generally more effective for cost reduction than simply switching to cheaper models.






