Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 6 min read

One AI Request Is Not One Unit of Work

Your AI endpoint returned HTTP 200. The dashboard says the model call cost $0.003. The agent retried twice, called three tools, and a person still had to correct the result. Was the feature cheap? You cannot tell from

Your AI endpoint returned HTTP 200. The dashboard says the model call cost $0.003. The agent retried twice, called three tools, and a person still had to correct the result.

Was the feature cheap?

You cannot tell from the token dashboard.

Most AI dashboards measure provider calls. Product teams deliver outcomes. Those are different units, and the gap is where a lot of AI economics disappear.

This is becoming an engineering problem, not just a finance problem. In its Q2 2026 Global AI Pulse, published on June 24, KPMG surveyed 2,145 senior leaders across 20 markets. It found that 42% had only partial visibility into AI spending and 23% struggled with usage-based costs. KPMG's findings are a useful reminder: if you cannot see how a workflow spends money, you cannot optimize it reliably.

Start with the task, not the call

A single user task might produce:

  • one initial model call;
  • two retries;
  • a tool call to retrieve data;
  • another model call after the tool result;
  • an escalation to a stronger model;
  • a human review or correction.

If you count only the first call, you have not measured the task. You have measured one event in its execution.

Give every logical unit of work a stable task_id. Give every model or tool invocation an attempt_id. Then record enough metadata to connect the whole path:

Field Why it matters
task_id Groups retries, escalations and tool calls into one unit
attempt_id Identifies each individual operation
model and version Lets you compare routes without mixing model changes
input, cached-input and output tokens Captures the provider's actual usage categories
tool and infrastructure cost Includes work outside the model API
outcome Distinguishes accepted, human-completed and failed tasks
human review minutes Shows whether automation moved work or merely moved the bill

You do not need to store raw prompts or customer data to build this ledger. Use task IDs and sanitized dimensions such as task type, model version and outcome.

Two metrics are better than one

First calculate the model-and-tool cost of an accepted task:

cost per accepted task =
  total model + tool spend across the cohort
  -----------------------------------------
          number of accepted tasks

The numerator includes every attempt in the cohort: successful calls, retries, escalations and failed tasks. Those failures still consumed resources.

Then calculate a fully loaded version:

fully loaded cost per accepted task =
  model + tools + human review/rework cost
  ---------------------------------------
            accepted tasks

Keep both numbers. The first helps engineers optimize the technical workflow. The second helps a product team decide whether the workflow is actually economical.

Define β€œaccepted” outside the model. It might mean a deterministic validation passed, a reviewer approved the result, or the user completed the intended action. An HTTP 200 is not acceptance, and β€œthe model says it is confident” is not an acceptance test.

A small Python cost ledger

The following example uses illustrative prices per million tokens. Replace them with your provider's current rate card, including cached-input pricing where available.

from collections import defaultdict

# USD per 1M tokens β€” illustrative values, not live provider prices.
PRICES = {
    "fast":   {"input": 0.20, "cached_input": 0.02, "output": 0.80},
    "strong": {"input": 2.00, "cached_input": 0.20, "output": 8.00},
}

attempts = [
    {
        "task_id": "A", "model": "fast",
        "input_tokens": 1200, "cached_input_tokens": 0,
        "output_tokens": 160, "tool_cost_usd": 0.002,
    },
    {
        "task_id": "B", "model": "fast",
        "input_tokens": 2600, "cached_input_tokens": 1800,
        "output_tokens": 220, "tool_cost_usd": 0.003,
    },
    {
        "task_id": "B", "model": "strong",  # escalation
        "input_tokens": 3100, "cached_input_tokens": 2400,
        "output_tokens": 300, "tool_cost_usd": 0.001,
    },
    {
        "task_id": "C", "model": "fast",   # eventually failed
        "input_tokens": 1700, "cached_input_tokens": 0,
        "output_tokens": 190, "tool_cost_usd": 0.002,
    },
]

outcomes = {
    "A": {"accepted": True,  "human_review_minutes": 0},
    "B": {"accepted": True,  "human_review_minutes": 4},
    "C": {"accepted": False, "human_review_minutes": 3},
}

spend_by_task = defaultdict(float)

for attempt in attempts:
    price = PRICES[attempt["model"]]
    cached = min(attempt["cached_input_tokens"], attempt["input_tokens"])
    fresh = attempt["input_tokens"] - cached

    token_cost = (
        fresh * price["input"]
        + cached * price["cached_input"]
        + attempt["output_tokens"] * price["output"]
    ) / 1_000_000

    spend_by_task[attempt["task_id"]] += (
        token_cost + attempt["tool_cost_usd"]
    )

accepted = sum(result["accepted"] for result in outcomes.values())
total_model_and_tool = sum(spend_by_task.values())
human_minutes = sum(
    result["human_review_minutes"] for result in outcomes.values()
)

hourly_human_cost = 45  # illustrative fully loaded hourly rate
human_cost = human_minutes / 60 * hourly_human_cost

if accepted:
    print("Model + tool cost / accepted task:",
          round(total_model_and_tool / accepted, 4))
    print("Fully loaded cost / accepted task:",
          round((total_model_and_tool + human_cost) / accepted, 2))

print("Acceptance rate:",
      f"{accepted / len(outcomes):.0%}")

Notice task C: it failed, but its attempts remain in the numerator. If you remove failed tasks from spend, the metric rewards a workflow for wasting money on work it never completed.

For a real system, persist these events rather than keeping them in memory. Store the price-card version and the timestamp used to calculate each cost. Provider prices and model names change; historical reports should not silently recalculate old work at today's rates.

Example: the model bill is not the whole bill

Imagine a batch of 100 tasks:

  • model and tool spend across all attempts: $14.40;
  • accepted tasks: 80;
  • 25 tasks needed three minutes of human review;
  • fully loaded human cost: $48 per hour.

The model-and-tool cost is $0.18 per accepted task. But those 25 reviews add $60, bringing the fully loaded cost to $0.93 per accepted task.

Both figures are useful. If you report only $0.18, you hide the work that remained with the team. If you report only $0.93, you lose the detail engineers need to improve the model workflow.

A recent DEV.to case study about automating supplier-order checks made a similar point: the author reported a large reduction in model cost after moving closed-set decisions away from a generation loop, while emphasizing cost per completed task. Treat those numbers as that author's case study, not a universal benchmark: the workflow breakdown and discussion.

The scale can be significant. On November 18, 2026, Business Insider reported that Harness engineers had used 265 billion AI tokens in a week; the company cited cheaper models and a soft weekly budget as two ways it managed spend. That is one company's account, not a benchmark for every team, but it shows why usage telemetry belongs in engineering operations: the report.

What to optimize after you can measure it

Once the ledger exists, look for the expensive paths rather than immediately switching to the cheapest model.

  1. Remove unnecessary model decisions. If the task is choosing among a small, known set of routes, test whether ordinary code or a classifier is enough.
  2. Route by task difficulty. Use a cheaper model for routine work and escalate on explicit, measurable conditions. Include the escalation cost in the same task.
  3. Bound loops and retries. Set a maximum attempt count, a deadline and a clear terminal state. An agent that never stops has no predictable unit cost.
  4. Reduce repeated context. Measure cached and uncached input separately. Keep stable instructions reusable and pass only the context needed for the current step.
  5. Protect quality. Compare acceptance rate, failure rate and human review time alongside cost. A cheaper model that doubles rework may be more expensive in practice.

Run a representative evaluation set before changing routes. Then deploy the new policy in shadow mode, compare the decisions and costs, and only promote it when quality stays within an agreed threshold.

A one-hour starting point

You can get a useful first measurement without building a full observability platform:

  • Add a stable task_id to each AI workflow.
  • Capture model usage and tool spend for every attempt.
  • Record one terminal outcome per task.
  • Add human review minutes where a person completes or corrects the work.
  • Produce a daily report grouped by task type and model version.

Start with one workflow that runs often. A small, accurate ledger is more valuable than a large dashboard that counts tokens but cannot tell you whether the work was accepted.

What do you measure today: tokens per request, cost per completion, or cost per accepted result? And which number has surprised you?

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.