Input vs Output Token Costs: Avoid These 7 Traps
AI API bills are rarely driven by one number. The same request can have very different costs depending on how much context you send and how much text the model generates. Understanding input versus output token costs helps you reduce waste without forcing every task onto the smallest model.
1. Treating tokens like words
A token is not always a word. Common words may use one token, while code, URLs, JSON, punctuation, and some languages can use several. A 1,000-word prompt is therefore not guaranteed to contain 1,000 tokens.
How to avoid it: measure actual token usage with your provider's tokenizer or usage fields. Record input and output tokens separately for representative requests. Do not estimate your monthly bill from word count alone, especially if your application processes source code, logs, or structured data.
2. Assuming input and output cost the same
Most model pricing separates input tokens from output tokens, and the rates can differ substantially. Input tokens include system instructions, conversation history, retrieved documents, tool results, and the current user message. Output tokens include the model's response, including generated JSON or code.
A practical estimate is: total cost = input tokens × input rate + output tokens × output rate. Apply the rates for the exact model and billing route you use. Pricing can vary between model families and may change over time, so check the current schedule before making a budget commitment.
3. Sending the entire conversation every time
Stateless API calls usually require you to resend conversation history. A long chat can quietly turn a short question into a large input bill. Repeating the same policy, documentation, or examples on every request creates the same problem.
How to avoid it: summarize old turns, remove irrelevant messages, and keep a compact conversation state. For support systems, store facts and decisions separately from casual dialogue. If your provider supports prompt caching, use it for stable prefixes, but confirm the cache rules and rates rather than assuming every repeated token is free.
4. Optimizing input while ignoring output
Developers often trim prompts but allow unlimited responses. This is risky: verbose explanations, repeated fields, and unnecessarily large code blocks can make output tokens the dominant cost. It can also increase latency and make responses harder to process.
Set a realistic maximum output token limit. Define the required format, field lengths, and level of detail in the prompt. For example, request a JSON object containing a 120-character summary instead of asking for a complete explanation and truncating it in your application. A clear stopping condition is both a quality control and a cost control.
5. Using a large model for every task
Opus-class or other flagship models are useful for complex reasoning, but classification, extraction, rewriting, and simple routing may not need that level of capability. Choosing a powerful model by default can multiply costs without improving the result.
How to avoid it: create a small evaluation set and compare accuracy, output length, latency, and cost across models. Route easy requests to a fast, economical model such as Haiku or an appropriate GPT option, while escalating ambiguous or high-impact cases to a stronger model. Claude Sonnet and Opus can remain available for tasks where reasoning quality matters.
6. Paying for context that the model does not need
Retrieval systems can inflate input tokens by attaching entire documents, duplicate passages, or irrelevant search results. More context is not automatically better; it can distract the model as well as increase the bill.
Use metadata filters, smaller chunks, deduplication, and reranking before generation. Include only the passages needed to answer the question. Test retrieval quality at several context sizes and measure answer accuracy against input-token growth.
7. Forgetting retries, tools, and failed requests
A timeout does not always mean no tokens were consumed. Automatic retries, tool calls, streaming interruptions, and malformed structured output can each create additional requests. A seemingly cheap workflow may become expensive under failure conditions.
Use exponential backoff with a retry limit, an idempotency strategy where supported, and logging for request IDs, model names, input tokens, output tokens, and error types. Validate JSON locally before retrying, and cap tool-call depth so an agent cannot loop indefinitely.
Balancing cost without sacrificing usefulness
- Compress stable instructions and remove duplicate context.
- Use retrieval and summaries instead of sending full histories.
- Set output limits based on the task, not the model's maximum.
- Measure cost per successful task, not just cost per API call.
- Test model routing with real examples and review quality regressions.
59API is a practical low-cost option for this kind of optimization. It provides pay-as-you-go access to native, official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, as well as GPT models, without a model downgrade. Its API base URL is https://api.59api.com, and it works with Claude Code, Codex, and any OpenAI SDK. Developers can compare routes while keeping the same integration, and the referral rebate can further improve the economics. If you want to test a cheaper relay with measured token usage, consider signing up for 59API and start with a small, monitored workload.
Ready to get started?
Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.
Sign up free