LLM cost per successful task: a practical measurement framework

AINORYX engineering team Published: 8 min read

Context and when this applies

Most teams track LLM cost in one of two ways: total spend from the provider invoice, or cost per request from a pricing calculator. Neither tells you whether a feature is economically healthy, and neither lets you compare two designs fairly.

Consider two configurations of the same feature. One uses a larger model and succeeds on the first attempt most of the time. The other uses a smaller model that is cheaper per call but needs retries, escalations or human correction more often. Cost per request favors the second. Cost per successful task might favor either one, and it is the only one of these numbers that reflects what the business pays for an outcome.

This framework applies to any LLM feature with a definable outcome: a ticket correctly classified, a document correctly extracted, a support question resolved, a code change that passes tests, an agent run that reaches the correct end state. It is most useful when you are comparing models, prompts, routing strategies or architectures, or when you need a unit cost for pricing and budgeting.

The calculation

Step 1: Define a task and its success criteria

A task is the unit of value the user or business cares about, not an API call. A single task may involve several model calls, retrieval, tool calls and retries.

Success must be defined before you measure, and must be checkable. Anthropic’s guidance on defining success criteria and building evaluations recommends task-specific criteria and automated grading where possible, using code-based checks, model-based grading or human review. Practical options:

Task type Success signal
Classification, extraction Matches label or schema-valid fields match reference
Question answering Correct and grounded per rubric, on a sampled and graded subset
Support resolution No reopen or escalation within a defined window
Code generation Tests pass and change is merged
Agent workflow Reached correct end state without policy violations

In production you rarely have labels for every task. Use a mix: deterministic checks where possible, downstream signals (reopens, edits, escalations), and graded samples to estimate success rate for the rest.

Step 2: Capture cost per attempt by token type

Every provider bills tokens by type, with different prices for uncached input, cached input and output, and sometimes for cache writes. Read the usage object on every response and store it with a task ID. OpenAI reports cached tokens within the usage details, as described in its prompt caching guide. Anthropic reports input_tokens, cache_creation_input_tokens and cache_read_input_tokens separately, per its prompt caching documentation.

call_cost =
    T_in_uncached × p_in
  + T_cache_write × p_cache_write
  + T_cache_read  × p_cache_read
  + T_out         × p_out
  + per_call_tool_fees

Take p_* values from the official pricing pages for OpenAI, Anthropic and Gemini, for the exact model and processing mode (synchronous, batch, regional or priority options) you use. Store the price table with an effective date, because prices change and you will want to recompute history correctly.

Step 3: Roll up to the task, including failures

task_attempt_cost(t) =
    Σ call_cost over every model call linked to task t   # including retries and failed calls
  + retrieval_cost(t)                                    # embeddings, vector queries, reranking
  + tool_cost(t)                                         # external APIs, search, compute
  + human_cost(t)                                        # review_minutes × loaded_rate, if any

cost_per_successful_task =
    Σ task_attempt_cost(t) over all tasks in the period
  / count(tasks where success(t) = true)

The denominator counts only successful tasks, while the numerator includes every attempt. This is what makes the metric honest: failed tasks still cost money, and that cost is spread over the successes.

Step 4: Add shared and fixed costs where relevant

For a full unit cost, allocate costs that do not appear per call:

fully_loaded_cost_per_successful_task =
    cost_per_successful_task
  + (self_hosted_infra + observability + eval_runs + vector_db_base) / successful_tasks

Keep this as a separate number. Variable cost per successful task is the better signal for engineering decisions; fully loaded cost is better for pricing and budgeting.

A worked structure (Hypothetical example)

Using illustrative round numbers only: suppose a feature handles 10,000 tasks in a week, and the logs show 12,000 model-call sequences because some tasks were retried. Graded samples estimate that 9,000 tasks succeeded. If the summed attempt cost for the week is C, then:

cost_per_request          = C / 12,000
cost_per_task_attempted   = C / 10,000
cost_per_successful_task  = C / 9,000

The same spend produces three different unit costs. Only the last one changes when a design change improves success rate without changing token usage.

Step 5: Compare designs on the same basis

The metric earns its keep when you use it to decide between alternatives. To compare a current configuration A with a candidate B (a different model, a routing rule, a trimmed prompt, a new retrieval setup):

Run A and B on the same eval set, or split live traffic between them.
For each option:
    success_rate       = successful_tasks / tasks
    cost_per_success   = Σ task_attempt_cost / successful_tasks
    p95_task_latency   = 95th percentile end-to-end time per task

Prefer B only if:
    cost_per_success(B) < cost_per_success(A)
    and success_rate(B) ≥ success_rate(A) − agreed_tolerance
    and p95_task_latency(B) ≤ latency_target

Agree on agreed_tolerance and latency_target with the product owner before running the comparison, not after seeing the results. When the success rate is estimated from graded samples, make sure the sample is large enough that the difference between options is larger than the sampling noise; otherwise, collect more samples before deciding. For low-volume features, an offline eval set gives a faster answer than waiting for production traffic to accumulate.

Limitations and alternatives

Success labels are noisy. Downstream signals such as reopens or edits are proxies, and model-graded evaluation needs calibration against human labels. Report the success rate with its sample size, and recompute when grading changes.

Attribution requires trace IDs. If model calls are not linked to a task ID, retries and multi-step flows cannot be rolled up. Adding a propagated task or trace ID is often the first engineering change.

Human time is easy to omit. If reviewers correct outputs, that time belongs in the numerator. Excluding it makes weaker models look cheaper than they are.

Caching makes per-call cost variable. The same request can cost different amounts depending on cache state. Measure over a period long enough to reflect real hit rates rather than estimating from a single call.

Not every feature has a clean outcome. For open-ended chat, use a proxy (resolved conversations, positive feedback on a sample) and state its limits. When no outcome can be defined, cost per conversation with a quality score from graded samples is a reasonable fallback.

Averages hide expensive segments. A healthy average can mask a small slice of tasks, such as very long documents, specific tenants or a hard question category, that consumes a disproportionate share of spend through long context, many agent steps or repeated retries. Break cost per successful task down by input length bucket, task category and customer segment. Those breakdowns are usually where routing, context limits or a dedicated workflow make the biggest difference, and they show whether a proposed change helps the expensive tail or only the cheap majority.

Price changes break comparisons. Compare designs using the same price table, and recompute historical periods with prices effective at the time.

What to measure

  • Cost per successful task, per feature, per release and per model or route.
  • Success rate with sample size and grading method.
  • Attempts per task: retries, escalations and steps, as a distribution with p95.
  • Failure cost share: spend on tasks that did not succeed, as a share of the total.
  • Token mix per task: uncached input, cached input, cache writes and output.
  • Human review minutes per task, where review exists.
  • p50 and p95 latency per task, since a cheaper design that misses latency targets may not be viable.

Track these on a dashboard by feature, with alerts when cost per successful task rises beyond an agreed threshold after a release.

Assumptions

  • Each task has a success definition agreed before measurement, and a grading method applied consistently across options.
  • Usage data is captured from provider responses or a gateway and linked to a task ID.
  • Prices are taken from official provider pages with an effective date; this article lists none.
  • Human review time is costed with a loaded rate your finance team provides.
  • Shared infrastructure costs are allocated separately from variable cost per task.
  • The hypothetical numbers above are illustrative and do not represent any real system.

Sources

  1. OpenAI API pricing — accessed November 23, 2026
  2. Anthropic Claude API pricing — accessed November 23, 2026
  3. Gemini Developer API pricing — accessed November 23, 2026
  4. OpenAI prompt caching guide — accessed November 23, 2026
  5. Anthropic prompt caching documentation — accessed November 23, 2026
  6. Anthropic: define success criteria and build evaluations — accessed November 23, 2026