AI Agent Token Usage: Settings That Cut API Costs
The most effective settings for lowering AI agent token usage and API costs are a smaller, task-appropriate model; concise prompts and context; limited tool calls; and explicit caps on output tokens and agent steps. Measure quality and cost together: an agent that uses fewer tokens but repeatedly fails or retries can cost more overall.
What drives an agent’s API bill
Token billing usually depends on the model and the number of input and output tokens processed. Input can include system instructions, user messages, tool descriptions, conversation history, retrieved documents, and tool results. Output includes the model’s response and, in many agent designs, its tool-call arguments. Providers may price input and output differently, and may offer separate rates for cached input or other features. Check the current pricing and billing documentation for the API you use; rates and accounting details vary.
Agents can make several model calls to complete one user request. A tool call may be followed by another model call that interprets the result, and a multi-step workflow may repeat this cycle. Thus, the total cost is better understood as the sum of all calls, not the price of one final answer.
- Input volume: Long instructions, full chat histories, verbose tool schemas, and oversized retrieved passages all consume context.
- Output volume: Long explanations, repeated summaries, and unnecessarily detailed tool arguments increase generated tokens.
- Call count: Planning loops, retries, and unnecessary tool use multiply the cost of a task.
- Model choice: More capable models may cost more per token, but can be cheaper overall if they solve tasks with fewer calls or less rework.
Choose the model and reasoning effort by task
Route simple, well-defined work—such as classification, extraction, or formatting—to a less expensive model that meets your accuracy needs. Reserve a more capable model for tasks that genuinely require complex reasoning, difficult synthesis, or reliable handling of ambiguity. Test representative examples before switching: a cheaper model that misses key details may trigger retries or human correction.
If the API exposes a reasoning-effort or similar control, start with the lowest setting that reliably solves the task. Higher effort can improve performance on some difficult problems, but may use more computation, tokens, or time, depending on the model and provider. Do not assume that a setting has the same behavior across APIs. Compare results on your own workload, including failure rates and total calls.
Use a fixed model for predictable workloads where possible. For varied requests, a lightweight routing step can classify the task and send only difficult cases to a stronger model. Keep routing simple: the router itself makes a call, so it is worthwhile only when the savings from appropriate model selection exceed its cost.
Trim prompts and manage context
Write instructions that are specific, compact, and non-duplicative. Remove repeated rules and background that do not affect the decision. State the task, relevant constraints, and required output format clearly. For example, if a tool needs a date and an account identifier, request those fields rather than asking the model to produce a long narrative before calling it.
- Send only the conversation turns needed for the current task; do not automatically resend an unlimited transcript.
- Summarize older history into a short, verified note when continuity matters, and retain important facts rather than vague conclusions.
- Retrieve only relevant document passages, using a suitable limit on the number and size of results.
- Keep tool descriptions and schemas concise, while preserving required fields, constraints, and clear definitions.
- Ask for the minimum useful response, such as a specified number of fields or a short answer, when the task does not need elaboration.
Do not remove context merely to shrink prompts if it contains safety requirements, essential definitions, or facts needed for a correct answer. The aim is relevant context, not the shortest possible prompt.
Limit outputs, tools, and agent loops
Set a maximum output-token limit appropriate to the task. A short extraction may need only a small structured result, while a report needs more room. If the cap is too low, the response can be cut off or become unusable; set it based on observed successful outputs and check for truncation.
Give agents a bounded number of tool calls or steps, and define when they should stop and return a partial result or ask for clarification. Avoid allowing an open-ended loop in which the agent repeatedly plans, searches, and revises without a clear completion condition. Use tools only when their information or action is needed: an external lookup for a current fact may be useful, while calling a tool to reformat information already present may not be.
Make retries selective. Retry transient failures or clearly recoverable errors, not every imperfect answer. Use a limit and a concise error message that provides only what the agent needs to correct the call. Where safe and supported, cache stable results or reuse prior computations rather than asking the model to regenerate them.
Measure cost per successful task
Track token usage and call counts across the complete task, including failed attempts and tool cycles. Estimate cost using the provider’s current rates for each model and token category. Compare settings on a representative evaluation set and record both cost and task quality: completion rate, factual or extraction accuracy, latency, and frequency of human intervention.
A useful comparison is cost per successful task, rather than cost per call. For example, a cheaper model that completes a task in one call can be a better choice than a more expensive model; but if it commonly needs several retries, the apparent per-token saving may disappear. Monitor averages as well as high-cost outliers, since unusually long documents or looping agents can dominate a bill.
Common mistakes and trade-offs
- Setting every limit to the minimum: Tight context or output caps can cause missing information, truncation, and extra retries.
- Using a stronger model for every step: Routine subtasks may not need the same capability as the hardest part of a workflow.
- Over-compressing prompts: Ambiguous instructions can make outputs less reliable and increase correction costs.
- Ignoring repeated calls: A short response can still be expensive if the agent makes many hidden planning or tool calls.
- Assuming cached input is free: Cache eligibility, discounts, and token accounting depend on provider rules; verify them rather than assuming savings.
Cost reductions should not come from weakening safeguards or removing checks that prevent consequential mistakes. For sensitive actions, retain appropriate confirmation and validation. A modest increase in tokens can be worthwhile if it prevents an incorrect action or costly failure.
Frequently Asked Questions
What setting reduces AI agent costs the most?
It depends on the workload. Reducing repeated calls and unnecessary context often helps, while model choice can have a large effect when a high-priced model is used for routine work. Measure total cost per successful task to find the biggest opportunity.
Does a shorter prompt always cost less overall?
It can lower input tokens, but not if it removes instructions or context needed for a correct answer. Compare completion quality and retries as well as prompt size.
Should I set a maximum output-token limit?
Usually, yes. Choose a cap based on the longest valid response your task needs, then check for truncated outputs. A cap that is too low can cause failures and repeat calls.
Can a smaller model handle an agent workflow?
Often it can handle predictable subtasks, but performance varies by task and model. Test it on realistic examples and route harder cases to a more capable model if needed.
How do I estimate API cost for an agent?
Count input and output tokens for every model call, including retries and tool cycles, then apply the provider’s current model-specific rates. Account for any documented caching or feature-specific pricing.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.