Cost Model
Fix the task and window before summing costs
Record task ID, customer, workflow, start time, acceptance criteria, and deadline. Associate retries, model upgrades, compaction, and human takeover with the original task. Success uses the time the result is confirmed usable; label human fallback separately. Report tasks with incomplete observation windows separately.
Actual ledgers record incurred expenses; forecasts record expected expenses. Do not add probability-weighted fallback costs to the same actual fallback expense. Keep costs incurred on failed, canceled, and budget-terminated tasks.
Count each expense once
Normalize provider usage into mutually exclusive billing categories. Here uncached_input_tokens excludes cache writes and reads; all rates are per million tokens. Convert provider fields according to their documented inclusion rules.
call_cost = (
uncached_input_tokens × input_price_per_million
+ cache_write_tokens × write_price_per_million
+ cache_read_tokens × read_price_per_million
+ output_tokens × output_price_per_million
) / 1,000,000
task_resource_cost = sum(all_call_costs)
+ tool_and_runtime_cost + external_api_cost
task_delivery_cost = task_resource_cost
+ actual_review_and_fallback_labor_cost
+ allocated_service_cost
all_call_costs includes initial attempts, retries, upgrades, and compaction, so do not add retry_cost again. Report retry spending as a subset of the total. Define tool and external API boundaries so bundled resources are not charged twice.
Value actual human minutes at loaded hourly cost divided by 60. Classify review, correction, takeover, and service time without overlap. Separate acquisition and one-time onboarding, as in growth. Document shared-resource allocations and retain visibility into unallocated fixed investment.
Use a reproducible synthetic bill
Assume triaging 20 emails in 12 model calls. Teaching rates, not a vendor quote, are $3 for uncached input, $3.75 for cache writes, $0.30 for cache reads, and $15 for output, all per million tokens. Assume one prefix write, 11 reads, no retries, and $0.001 in runtime charges.
| Attribution | Usage | Cost (USD) |
|---|---|---|
| Static system and tool definitions | 3,700 write; 40,700 read | 0.026085 |
| Non-tool dynamic input and history | 26,400 uncached input | 0.079200 |
| Tool-result input, including replays | 14,400 uncached input | 0.043200 |
| Model output | 3,000 output | 0.045000 |
| Runtime | Separately charged | 0.001000 |
| Total | Resources only | 0.194485 |
Attribute each input occurrence by source. Replayed tool results remain tool-result input, never also non-tool history. Generated output incurs output charges; replaying it later incurs a separate input charge for another processing event.
Chart shares use unrounded amounts; displayed percentages are rounded. This bill excludes labor and is not total delivery cost. Store actual prices, cache durations, discounts, and regional settings in a dated rate version. See the official pricing explanation for billing categories.
Cost per success includes failed attempts
cost_per_started_task = cohort_delivery_cost / started_tasks
cost_per_successful_task = cohort_delivery_cost / accepted_agent_tasks
The numerator includes all delivery costs for the same completed task cohort, including human fallback after failure. The denominator counts distinct tasks meeting predefined agent-delivery criteria. Report human-completed tasks separately. If using eventual delivery success as another denominator, label it separately from agent success.
For example, all 100 started tasks have ended. Resources cost CNY 200, review and service cost 300, and fallback labor costs 100. Eighty tasks meet agent acceptance criteria. Cost per start is 6; cost per agent success is 7.5. Even if humans finish the other 20, agent success remains 80. With zero successes, report unit cost as not applicable and still show total spending.
Replayed history increases cumulative input
In a multi-step agent, each step often needs some history: the user’s goal, previous actions, tool results, errors, and current state. If the full history is replayed, step N carries the content of steps 1 through N-1.
That makes accumulated input grow quickly:
history_tokens ≈ per_step_history × (1 + 2 + ... + n)
Real systems do not have to be strictly O(n²), because they can trim, compact, externalize state, or retrieve only relevant events. The trend still matters: the longer the task, the more important history management becomes.
That is why compaction, memory-system, progress files, structured state, and recoverable sessions are part of the economics, not just user experience.
Caching needs stable prefixes and reuse opportunities
Prompt caching works when identical content is read repeatedly. System prompts, tool descriptions, policy blocks, and fixed output formats should stay as stable as possible.
Common ways to break caching:
- Put per-request user data into the system prompt.
- Reorder tool descriptions dynamically on every turn.
- Place timestamps, random IDs, or temporary state inside the static prefix.
- Constantly rewrite a long prompt to tweak a few words.
Also check cache lifetime, request spacing, minimum length, and provider rules. Caching saves money only when reuse savings exceed write and maintenance overhead. Verify actual usage rather than assuming stable prefixes always hit.
Output optimization must preserve necessary verification
For many models, output tokens cost more than input tokens. This encourages fewer long explanations, less unnecessary planning prose, and more direct tool use.
But “shorter output” should not become silence. Useful plans, checkpoints, and error explanations can prevent retries. The better target is:
- Reduce long reasoning text that is invisible, unverifiable, or not reusable.
- Make tools return structured results instead of large raw blobs for the model to paraphrase.
- Emit concise state at key points so users and later agents can resume.
Model rates directly change only call charges
The chart uses hypothetical options A, B, and C with model-call rates at 1/3, 1, and 5/3 of the example baseline. Token usage is identical and runtime stays at $0.001. Resource costs are $0.065495, $0.194485, and $0.323475. Bar lengths are proportional to cost. These are not model recommendations and exclude labor. Actual models may differ in usage, retries, and quality; compare total delivery cost on the same evaluation cohort.
| Model tier | Good fit | Cost intuition |
|---|---|---|
| Low-cost model | Classification, extraction, formatting, low-risk routine actions | Cheap per step, but may need more fallback |
| Mid-tier model | Most default product agent tasks | Balanced cost and reliability |
| High-capability model | Long-horizon planning, complex code, subjective quality judgment, high-risk decision support | More expensive per step, but may avoid wrong paths |
Model routing is not about always choosing the cheapest model or defaulting to the strongest one. It is about matching task risk, failure cost, and model capability.
Fields To Measure
These are recommended records, not claims about current implementation. Also capture task_id, attempt_id, customer and workflow, acceptance status and time, delivery mode, rate version, currency, actual charges, and allocation basis to reconstruct cohort ledgers:
| Field | Why it matters |
|---|---|
uncached_input_tokens / output_tokens | Shows whether cost comes from input growth or verbose output |
cache_write_tokens / cache_read_tokens | Shows whether static prefixes actually hit cache |
tool_result_tokens | Shows whether tools return too much context |
steps / retries | Shows wrong paths or loops |
model / route_reason | Shows whether routing decisions are justified |
runtime_seconds | Shows whether sandbox, browser, or external services matter |
human_review_minutes | Shows whether automation is shifting cost to people |
failure_reason | Shows whether runaway cost comes from model, tool, permission, data, or product design |
These fields feed the budgets, monitoring, and value model in Controls and ROI.
Related reading
Agent Economics separates perspectives; Controls and ROI explains how to use these records in decisions.