What to know first
Use low, base, and high scenarios. Add model input, cached input, and output tokens; search, containers, files, storage, runtime, retries, and human review; then apply real logs to replace assumptions and enforce a budget cap.
Start with six cost categories
An AI agent usually involves model tokens, tools, runtime, storage, retries, and human work. A task that appears to contain one prompt can resend system instructions, conversation history, tool schemas, retrieval results, and files on later turns.
Platforms meter these items differently: some use tokens, while others also charge for container minutes, session hours, search calls, file capacity, or seats. List the components first, then map each one to the vendor rate card.
| Cost | Common meter |
|---|---|
| Model | Input, cached input, output, and reasoning tokens |
| Tools | Search/call count, container, or compute time |
| Runtime | Session hours, container minutes, or concurrency |
| Data | File search, vector/object storage, and bandwidth |
| Failures and retries | Repeated requests and recovery steps |
| Human work | Approvals, review, rework, and operations |
Sources: OpenAI API: PricingOpenAI: Understanding and counting tokensAnthropic: Claude Platform pricing
A monthly formula you can implement
Treat each agent task as a sequence of steps. Record model and tool usage at each step. Calculate tokens using model rates, add tools, runtime, and storage, and estimate human cost from review minutes and an internal hourly rate.
If a task uses multiple models, give each model its own row. Track cache hits separately. Treat retries as a multiplier or a separate scenario instead of hiding them in an average.
Single-task cost = Σ(input/cache/output token cost + tool cost + runtime + storage) + retry cost + human review cost
Monthly budget = single-task cost × task count + fixed seats/infrastructure + risk buffer
Sources: OpenAI API: PricingOpenAI API: Prompt cachingAnthropic: Claude Platform pricing
Worked example: budget 100 coding-agent tasks
Assume each task averages 80,000 input tokens, with 15,000 cache hits and 10,000 output tokens. Using illustrative rates of $2 per million input, $0.10 per million cached input, and $10 per million output, the token cost is 65,000×2/1,000,000 + 15,000×0.10/1,000,000 + 10,000×10/1,000,000 = $0.2315 per task.
If each task also has three tool calls, ten minutes of runtime, 0.2 expected retries, and five minutes of human review, add those rows using the vendor and internal rates. The token portion for 100 tasks is $23.15; it is not the complete project cost.
| Line | Per-task example | 100 tasks |
|---|---|---|
| Tokens | $0.2315 | $23.15 |
| Tool calls | Use the tool rate | Unit rate × 300 calls |
| Runtime | 10 minutes | 1,000 minutes |
| Retries | Expected cost of 0.2 retries | Apply the failure rate |
| Human review | 5 minutes | 500 minutes |
Use low, base, and high scenarios
The low case uses short context, fewer tools, and a low failure rate. The base case uses the previous week's P50 usage. The high case uses P90 or a load test for context, concurrency, and retries. This prevents one average from hiding long-tail tasks.
Customer support, coding, research, and data agents have different cost shapes. Coding agents may be dominated by context and runtime; research agents by search and files; support agents by request volume and cache hit rate.
P50 budget = median task cost × expected task count
P90 budget = P90 task cost × peak task count + concurrency/retry buffer
Sources: OpenAI API: PricingAnthropic: Claude Platform pricing
Engineering controls that keep spend bounded
- Set maximum steps, tokens, tool allowlists, and runtime per task.
- Reuse stable system prompts and tool definitions, and measure cache hits instead of blindly shrinking context.
- Use a lower-cost model for classification, retrieval, and formatting, and escalate only complex decisions.
- Use backoff, retry caps, and idempotency checks to prevent failure loops.
- Log task ID, model, tokens, tools, runtime, failure reason, and human outcome.
- Set budget alerts and stop thresholds by project, team, and task type.
Sources: OpenAI API: Prompt cachingOpenAI API: PricingOpenAI: Using Codex with your ChatGPT plan
Frequently asked questions
Is token cost enough to estimate an AI agent?
No. Include tools, container or session time, file search, storage, retries, and human review; the exact meters differ by platform.
Sources: OpenAI API: PricingAnthropic: Claude Platform pricing
Why can an agent task become more expensive as it runs?
History, tool results, and files enlarge later inputs, while the agent may make more calls or retries. A single-step rate is not the task total.
Sources: OpenAI: Understanding and counting tokensOpenAI API: Pricing
How do I set an agent budget cap?
Set maximum steps, tokens, tools, runtime, and spend alerts, and log actual usage. Pause or request approval when a threshold is reached.
Sources: OpenAI: Using Codex with your ChatGPT planOpenAI API: Pricing
Does caching always reduce agent cost?
Cache hits often have a lower rate, but the result depends on stable prompts, model support, and cache write/read rules. Use the measured hit rate.
Official sources and review notes
Sources checked on October 17, 2026. Rates and eligibility rules can change; confirm the latest official guidance and your own agreement.
- OpenAI API: Pricing
- OpenAI: Understanding and counting tokens
- OpenAI API: Prompt caching
- Anthropic: Claude Platform pricing
- OpenAI: Using Codex with your ChatGPT plan
AISub prepared this guide from public OpenAI documentation, with an independent worked example and purchasing advice. AISub is an independent price index and is not affiliated with OpenAI.
