Back to Blog
AI Operations10 minAugust 22, 2026

How to Manage AI Token Usage Without Sacrificing Quality

Understand input, cached, output, and reasoning tokens; estimate cost before a run; and build a practical token budget for production agents.

Tokens are the unit of work, not the unit of value

A token is a chunk of text or structured content processed by a model. It may be shorter than a word, a complete word, punctuation, or part of code. Token counts determine whether a request fits the model’s context window and contribute to API cost, but a low token count does not guarantee an efficient workflow. The useful business measure is cost per successful, verified task.

An agent can spend few tokens and fail, or spend more tokens to produce a result that saves hours. Good token management is therefore not aggressive compression. It is deliberate allocation: enough relevant context and reasoning to meet the quality bar, with limits that stop repetition, irrelevant retrieval, and uncontrolled tool loops.

Know the four numbers in usage

For current Responses API workflows, track at least input tokens, cached input tokens, output tokens, and reasoning tokens. Input tokens include instructions, user content, conversation state, tool definitions, images represented for the model, and tool results passed back into later turns. Cached input is the reusable prefix billed at a discounted read rate when cache matching succeeds.

Output tokens include the model’s returned items. Reasoning tokens are reported within output-token details for reasoning models. They may not appear as visible prose, but they still affect usage and can grow when reasoning effort is high or a task is difficult.

The response usage object provides totals and detail fields such as cached_tokens, cache_write_tokens on GPT-5.6 and later, and reasoning_tokens. Store these fields with a workflow name, model, task outcome, latency, and retry count. A monthly total without task-level outcomes cannot tell you which workflow is wasteful.

Count before expensive runs

OpenAI exposes an input-token counting endpoint for Responses. Use it before very large requests, file-heavy jobs, or fan-out workflows. Preflight counting is especially useful when retrieved evidence, tool schemas, images, or conversation state varies dramatically between users.

Create a budget with separate ceilings. Reserve space for the stable instructions and tools, the current request, retrieved evidence, tool observations, final output, and a safety margin. Reject or summarize inputs that exceed their lane instead of allowing one verbose source to consume the entire window.

For example, a repository agent might allow a stable 20,000-token prefix, up to 80,000 tokens of retrieved code, 30,000 tokens for bounded tool results, and a 10,000-token output reserve. Those are not universal recommendations. Measure your repository tasks, then set limits below the model maximum so exceptional runs have room to finish.

Context capacity is not a spending target

A context window is the amount of rendered input and output state a model can consider for a request. It is not free storage and not every token receives equal practical attention. Replaying an entire chat, full repository, or every log line on each turn increases cost and latency while making the important evidence harder to identify.

Keep durable policy in one stable instruction block. Retrieve task-specific evidence on demand. Replace completed phases with a concise state summary or use supported compaction for long-running conversations. Remove stale plans, duplicate tool results, and superseded requirements.

The larger the model window, the more important this discipline becomes. A million-token context can enable genuinely broad work, but an agent that automatically fills it on every turn is not efficient.

Use prompt caching correctly

Prompt caching works on matching prefixes. Put stable instructions, tool definitions, schemas, and reusable examples first. Put user-specific or rapidly changing content later. If variable data appears near the beginning, later stable material cannot form the same exact prefix.

OpenAI says automatic caching applies to eligible recent-model prompts, with a minimum cacheable prefix of 1,024 tokens for GPT-5.6 and later. Monitor cached_tokens rather than assuming a cache hit. For GPT-5.6 and later, also monitor cache_write_tokens because cache writes and reads have different economics.

Do not distort a good prompt purely to chase caching. The prompt must still express the task correctly. Test stable-prefix changes against task success and latency, and group requests with a consistent prompt_cache_key when the documentation and your traffic pattern support it.

Control output and reasoning

Output tokens are often more expensive than input tokens. Ask for the artifact you need, not an essay around it. Define a schema, maximum list size, acceptance criteria, and desired verbosity. For machine-consumed steps, return compact structured data. Save explanatory prose for the final user-facing step.

Set reasoning effort intentionally. Use low or medium as an evaluated baseline for routine, verifiable work. Increase it only when representative tasks show a quality gain that justifies cost and latency. A global “maximum reasoning everywhere” rule wastes tokens on classification, routing, formatting, and simple extraction.

Separate cheap deterministic work from model judgment. Sorting, arithmetic, validation, deduplication, and known transformations belong in code when practical. Use the model where ambiguity, language, or reasoning adds value.

Put limits around tools and retries

Tool output becomes future input. A search returning 100 full pages, a shell command dumping a giant build log, or a database query without a row limit can dominate the next turn. Design tools to return bounded fields, pagination, summaries, and explicit error shapes. Keep raw artifacts addressable outside the prompt and pass only the relevant slice.

Set maximum tool calls, maximum retries per failure class, a wall-clock deadline, and a spend ceiling. A retry should change something: the query, tool, model, context, or strategy. Repeating the same failing request is not resilience.

For multi-agent work, budget the coordinator and each worker separately. Parallel agents can reduce wall-clock time but multiply input prefixes and tool observations. Use them only for independent workstreams whose combined value exceeds the additional cost.

Measure cost per accepted outcome

Build a dashboard or log query that answers: Which workflow consumed the tokens? Did it finish? Was the result accepted? How many retries and tool calls occurred? How much was cached? How long did a reviewer spend? What was the estimated API cost?

Compare changes on a stable evaluation set. Removing instructions may reduce tokens but increase failures. A shorter model answer may increase reviewer time. A cheaper model may need more retries. Optimize the complete system, not one usage field.

A useful weekly review ranks workflows by total spend, cost per successful task, failure rate, cache-hit ratio, and growth. Investigate outliers and regressions before applying blanket prompt cuts.

A token-management checklist

Before launch, count representative inputs, reserve output space, choose a model and reasoning baseline, stabilize the reusable prefix, bound every tool response, define retry and stop conditions, and log detailed usage with task outcomes. During operation, watch percentile distributions rather than averages: the most expensive five percent of runs often reveal missing limits.

When a workflow grows, compact after meaningful milestones, retrieve only current evidence, and retest. Token management succeeds when spend becomes predictable while verified task quality stays equal or improves.

Sources

Ready to turn this into a real system?

Start the AI audit and see what your business should automate first.

Start AI Audit

Continue exploring