Input vs Output Token Costs: A Developer Quick Start
Start with the two prices on your API bill
Input vs output token costs matter because a shorter prompt is not always the biggest money saver. Many models charge more per output token than per input token. To balance them, measure both sides, calculate their contribution, and optimize the larger avoidable expense.
Input tokens cover content sent to the model: instructions, conversation history, retrieved documents, tool definitions, and tool results. Output tokens cover generated content. Depending on the model and billing rules, charged output can also include reasoning tokens that are not visible in the final answer.
Tokens are text fragments, not words. Use the model’s tokenizer or API usage reporting rather than a fixed words-to-tokens conversion for budgeting.
1. Calculate the cost of a representative request
When prices are quoted per million tokens, use:
Request cost = (input tokens × input rate + output tokens × output rate) / 1,000,000.
For illustration only—not a 59API price quote—assume input costs $2 per million tokens and output costs $8 per million. A request with 6,000 input tokens and 1,500 output tokens costs $0.012 for input plus $0.012 for output: $0.024 total.
Removing 1,000 input tokens saves $0.002. Removing 500 output tokens saves $0.004. Here, reducing the answer by 500 tokens saves twice as much as removing 1,000 prompt tokens. Compare actual rates before choosing what to optimize.
2. Capture usage before changing prompts
Run 20–50 representative tasks and record the model, input tokens, output tokens, cached-token details when available, latency, retries, and whether each result passed your acceptance checks. Read usage fields from responses; for streaming, check how your endpoint returns final usage.
- Group by workflow: support replies, code edits, document extraction, and chat have different token profiles.
- Track cost per successful task: total workflow spend divided by accepted results, including failed attempts and retries.
- Inspect outliers: growing chat histories, large tool responses, and repeated repair calls often dominate spending.
3. Trim input without removing essential context
Start with redundant content. Deduplicate instructions, retrieve relevant document sections instead of entire files, and filter tool results to fields the model needs. For long conversations, retain recent turns plus a compact summary of decisions, constraints, and unresolved questions.
Keep security requirements, output schemas, and critical examples. Saving prompt tokens is counterproductive if missing context causes incorrect answers or extra calls.
If prompt caching is supported for your chosen model and route, keep reusable instructions stable and place changing task data afterward. Check actual cache-hit usage and cache pricing: cached input may have separate read and write charges, and discounts are not universal.
4. Control output with a clear response contract
Ask for a specific deliverable: “Return five bullet points, each under 20 words,” or “Return only the changed function, without commentary.” For extraction, request only required fields rather than a narrative explanation.
Set an appropriate output-token limit using the parameter supported by your model and endpoint. Treat it as a safety ceiling, not a formatting instruction. An overly tight ceiling can truncate JSON or code and trigger expensive retries. Inspect completion status and validate results before lowering it further.
5. Balance model choice with end-to-end quality
Benchmark a lower-cost option such as Gemini 2.5 Flash for routine extraction or classification, and compare Claude Sonnet 5.5 on harder coding tasks. Measure accepted-result cost rather than assuming either model is automatically cheapest for your workload. Where appropriate, escalate only failed or uncertain cases.
59API offers low-cost, pay-as-you-go access to native official-quality models without downgrading, alongside compatibility with OpenAI SDKs, Claude Code, Codex, and Gemini CLI. Its API base URL is https://api.59api.com; follow the integration documentation for endpoint paths and model identifiers.
If you want to test the economics, sign up for 59API and replay a small benchmark with a spending cap. Compare current model rates, usage totals, and acceptance rates. The goal is not minimum tokens—it is minimum cost per useful result.