AI Token Counts Explained: Fix Usage and Cost Surprises
What are tokens, and why do they matter?
Tokens are the units an AI model uses to process input and generate output. A token can represent a whole word, part of a word, punctuation, or whitespace. Token counts affect API costs, context limits, and how much text a model can return.
For English prose, one token is roughly four characters, or about three-quarters of a word. That makes 1,000 tokens approximately 750 words. These are planning estimates, not billing rules: code, unusual identifiers, emojis, and different languages can produce very different counts.
How are tokens actually counted?
A model-specific tokenizer converts content into token IDs. Different model families can tokenize identical text differently, so a GPT estimate is not necessarily accurate for Claude.
- Input tokens: Content supplied to the model, including instructions, conversation history, retrieved documents, and tool definitions or results.
- Output tokens: Tokens generated by the model. Depending on the model and API, billable output can include reasoning tokens that are not shown as answer text.
- Cached tokens: Reused input that may receive different pricing. Caching reduces eligible costs, not necessarily the logical size of the prompt.
Chat APIs also add message formatting and other overhead. Counting only the words in your latest question will usually underestimate the complete request.
How do I check the real token count?
- Before sending: Use the selected model's supported tokenizer or token-counting endpoint, where available. Include system instructions, tools, and conversation history, not just the user message.
- After sending: Inspect the response's usage object. OpenAI Chat Completions commonly reports prompt_tokens, completion_tokens, and total_tokens. Other endpoints may use input_tokens and output_tokens.
- Check cache fields: Anthropic-style responses can report cache creation and cache read input tokens separately. Read that endpoint's accounting rules before calculating totals; do not assume every cache field is an additional charge.
- For streaming: Enable usage reporting if the endpoint supports it, and capture the final usage event. Individual text chunks are not reliable token counters.
Why is my token count higher than expected?
Check what your application actually sends. A short follow-up can resend a long conversation. Agent frameworks may also attach lengthy instructions, tool schemas, search results, and previous tool outputs automatically.
Log a sanitized copy of the outgoing payload and compare requests turn by turn. Remove duplicate documents, trim irrelevant tool results, and summarize older conversation turns. Never log API keys or sensitive customer data.
If the request includes images, audio, or documents, use the model's modality-specific accounting rules. A text tokenizer cannot reliably estimate the entire multimodal request.
Why am I hitting the context limit?
The context window limits how much a model can handle in one request, generally including input and generated output. Models can also have a separate maximum output limit.
Check both limits for your exact model. Shorten the input, reduce the requested output allowance, or retrieve only relevant document sections. Switching to a larger-context model can help, but does not automatically make every request cheaper.
How do I turn token counts into API costs?
Calculate each billing category separately: tokens divided by 1,000,000, multiplied by the price per million tokens. For example, at hypothetical rates of $0.50 per million input tokens and $2 per million output tokens, 10,000 input tokens plus 2,000 output tokens costs $0.009. Apply actual cache and model rates separately.
Can 59API help lower token spending?
59API offers low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without downgraded substitutes. It supports Claude Code, Codex, and OpenAI SDK-compatible workflows, making it practical to compare model cost against task quality.
Its API base URL is https://api.59api.com; follow its integration instructions for any required versioned path. Compare current per-model prices and usage records, and consider its referral rebate when assessing overall costs. If you want a budget-friendly setup, sign up for 59API and test a small, representative workload first.