Agent workflow guide
AI Agent Cost Calculator Guide
Agent costs can grow faster than a single chat request because each run may include planning, tool calls, retrieved context, intermediate reasoning, final answers, and retries.
Break the agent into billable steps
A useful estimate starts with the actual loop the agent follows. Count the first instruction prompt, each tool-planning step, each tool result sent back to the model, the final answer, and any validation or repair pass. Even when a user sees one answer, the model may have processed several request-response cycles.
Collect six usage numbers
- Base prompt tokens: system instructions, tool schemas, policies, examples, and stable product context.
- User task tokens: the user's request and any attached text for the run.
- Tool result tokens: search results, database rows, file excerpts, API responses, or code snippets returned to the model.
- Output tokens per step: planning notes, tool arguments, intermediate summaries, and the final response.
- Average steps per run: the number of model calls needed before the task finishes.
- Retry rate: extra calls caused by validation failures, timeouts, tool errors, or low-confidence answers.
The agent cost formula
Price each model call, then add the workflow
Model cost per call = (uncached input tokens × input rate + cached input tokens × cached rate + billable output tokens × output rate) / 1,000,000
Cost per attempted task = sum of model call costs + tool execution fees + any cache write or storage charges
Monthly cost = initial attempts × average initial-attempt cost + extra retry costs + shared infrastructure costs
Cost per successful task = total spend across all attempts / successfully completed tasks
Rates above are dollars per million tokens. Cached and uncached input must be disjoint: do not charge cached tokens again at the ordinary input rate. Price each model separately if the workflow uses different models. Include billable reasoning tokens according to the provider's usage and pricing rules; visible answer length alone may understate output usage.
A tool call is not necessarily a model call. One model response can request multiple tools, and executing a custom function can incur its own API or compute cost. Count the model response that requests the tool, the returned content in subsequent model inputs, and any separate execution fee.
Example: four model calls for one support task
Assume an 8,000-token base prompt, a 600-token ticket, and three tool results of 1,500 tokens each. Each of the first three model calls emits 200 tokens of tool arguments; the fourth emits a 600-token answer. This simplified example retains all previous messages and tool results, with no caching or extra reasoning tokens. Actual serialized inputs may also include provider-specific overhead.
- Call 1: 8,600 input tokens; 200 output tokens.
- Call 2: 8,600 + 200 + 1,500 = 10,300 input tokens; 200 output tokens.
- Call 3: 10,300 + 200 + 1,500 = 12,000 input tokens; 200 output tokens.
- Call 4: 12,000 + 200 + 1,500 = 13,700 input tokens; 600 output tokens.
Total usage is 44,600 input tokens and 1,200 output tokens. The 4,500 new tool-result tokens are not the same as total processed input: earlier results are included again in later calls. Do not multiply this already-summed total by four.
Illustrative dollar estimate
At $2 per million input tokens and $8 per million output tokens, model cost is (44,600 × 2 + 1,200 × 8) / 1,000,000 = $0.0988 per initial attempt.
If each of the three tool executions costs $0.005, the initial attempt costs $0.0988 + $0.0150 = $0.1138. For 10,000 initial attempts, that is $1,138.00 before retries and shared infrastructure.
These are illustrative rates, not a quote for any model or tool. Replace them with your selected provider's current rates. Use the calculator to estimate representative text, then sum the actual inputs and outputs for each step; multiplying the first prompt by the call count misses growing history.
Partial retries versus full reruns
Suppose 10% of those 10,000 tasks need exactly one extra final-answer call with 13,700 input and 600 output tokens. Each retry costs $0.0322, so 1,000 retries add $32.20. The monthly total becomes $1,170.20, excluding shared infrastructure. No tool executes again in this scenario.
If instead 10% require a complete rerun with identical model and tool usage, the extra cost is $113.80 and the total is $1,251.80. A blanket 10% multiplier is only appropriate for that equal-cost rerun assumption. A failure percentage alone does not tell you how many retries occur or how much each costs.
For the partial-retry scenario, if 9,500 tasks ultimately succeed, $1,170.20 / 9,500 = $0.1232 per successful task, rounded. Failed tasks still contribute to spend. If no tasks succeed, this metric is undefined; report the spend and zero completions instead.
Reduce cost without weakening the agent
Shorten tool schemas, return only the fields the model needs, summarize long tool results before the next step, cap the number of search results, and route simple tasks to a lower-cost model. Use the context window cost guide to budget accumulated tool evidence and reserve output space. For stable instructions or tool definitions, compare the estimate with the prompt caching guide to price eligible cache hits separately from cache misses.
Agents can also hit API capacity limits because one visible action may create several model calls. Use the token rate-limit guide to estimate peak requests per minute before launching high-volume workflows. For repository agents, the AI code review cost guide separates PR diffs, retrieved source, cached context, and follow-up reviews.
Measure the production loop
After launch, log model calls per user task, input tokens, output tokens, tool result size, retries, and whether the task succeeded. Track task IDs and attempt IDs so retries are counted once. Compare normal and long-running tasks, and set limits on calls, tool executions, and total spend per task. For volume planning, use the monthly AI API budget guide.
Provider references
Checked August 28, 2026: Google's function-calling documentation explains the model/tool exchange; its token-counting guide covers usage measurement. Check the Gemini pricing page for model-specific output, caching, and tool charges. The example above is independent of those published prices.