How Tokens Are Counted: A 40% API Savings Example
What are tokens, and why do they affect your bill?
Tokens are the units an AI model processes when reading your request and generating its response. A token might represent a whole word, part of a word, punctuation, or whitespace. Tokens are not the same as words, characters, or bytes.
For ordinary 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, URLs, identifiers, emoji, and different languages can produce very different counts.
Most text API pricing separates input tokens from output tokens. Input is what the model receives; output is what it generates. Because output often costs more per token, controlling response length can save more than trimming the same number of tokens from a prompt.
How tokens are actually counted
Each model uses a tokenizer to split text into token IDs. Different tokenizers can count the same text differently, so a GPT estimate should not be treated as an exact Claude count.
- Input includes more than your latest question: system instructions, conversation history, retrieved documents, tool definitions, and tool results can all contribute.
- Message formatting adds overhead: role labels and model-specific formatting mean counting visible text alone may underestimate the request.
- Output is model-generated content: some models also bill reasoning tokens that are not exposed as ordinary response text.
- Multimodal inputs follow separate rules: images, audio, and video cannot reliably be priced using the English word estimate.
A context window is a capacity limit, not a free allowance. A model supporting a large context can still charge for every billable token you send.
Calculate a request cost with concrete numbers
Use this formula: cost = input tokens ÷ 1,000,000 × input rate + output tokens ÷ 1,000,000 × output rate. Apply any cache or other pricing categories separately when relevant.
Suppose a model costs $1 per million input tokens and $5 per million output tokens. These are illustrative rates, not a quoted 59API price. A request with 2,000 input tokens and 500 output tokens costs:
- Input: 2,000 ÷ 1,000,000 × $1 = $0.002.
- Output: 500 ÷ 1,000,000 × $5 = $0.0025.
- Total: $0.0045 per request, or $45 for 10,000 requests.
Now reduce input to 1,200 tokens and output to 300 tokens. The cost becomes $0.0012 + $0.0015 = $0.0027 per request, or $27 for 10,000 requests. That is an $18 saving, or 40%, assuming unchanged rates and request volume.
Measure usage before optimizing
Run 20–50 representative requests and record the model, task, token usage, latency, and result quality. OpenAI-style responses commonly report prompt_tokens, completion_tokens, and total_tokens in usage. Anthropic-style responses use fields such as input_tokens and output_tokens, with additional cache fields where applicable. Check the actual response format your endpoint returns.
For streaming requests, ensure your client captures usage when supported. Treat tokenizer estimates as forecasts and provider-reported usage as the billing reference. Cached tokens may be a subset of another count or a separate category; follow the endpoint's accounting rules rather than blindly adding every field.
Four practical ways to spend less
- Send relevant context only: retrieve a few useful document passages instead of attaching an entire manual. Remove duplicate instructions and stale tool output.
- Set a response budget: request a short answer or compact structured result, and configure the endpoint's supported output-token limit. Leave enough room to avoid truncating useful answers.
- Route by difficulty: test a lower-cost model for classification and extraction, reserving stronger models for complex reasoning. Measure retries too; a cheaper failed answer can cost more overall.
- Watch agent loops: Claude Code and Codex workflows can make multiple calls per task. Track total task cost, including repeated history, tool results, and retries.
Choose a low-cost API without sacrificing model quality
59API offers low-cost, pay-as-you-go access to native, official-quality Claude and GPT models without downgraded substitutes. It is compatible with Claude Code, Codex, and OpenAI SDKs; its API base URL is https://api.59api.com.
Compare current per-model rates, check caching support, and benchmark your real workload. Its referral rebate can provide additional savings under the applicable terms. Consider signing up for 59API and testing a small batch before moving production traffic.
¿Listo para empezar?
Conecta Claude y GPT en minutos a los precios más bajos, sin recortes. Regístrate para obtener tu clave API.
Registro gratis