The Invoice Won't Tell You

A provider invoice shows an agent's input and output tokens but not which workflow stage created them, so cost cuts end up aimed at the wrong place. In our simulated research agent, a per-stage token ledger shows page reads at 73% of billed tokens and final synthesis at 0.2%, with about 53% of tokens wasted under stated assumptions. Four architectures cut modeled cost per 1,000 tasks from $3,584 to between $2,324 and $524, but router-only p95 latency got worse. All figures are illustrative simulation, not production data. Includes a seven-step instrumentation framework and a short ledger function.

Published 2026-10-26 by Dor Amir on the Nadir blog.

Filed under Agents.

Abstract.

A provider invoice tells you how many input and output tokens an agent consumed. It does not tell you which stage of the workflow created them. We simulate a research agent that searches, reads pages and synthesizes an answer, then attribute every billed token to the stage that produced it, including each later resend. In the naive version, page reads account for 73% of billed tokens, final synthesis for 0.2%, and about 53% of all tokens are waste under our stated assumptions. Four architectures, from premium-everywhere to routing plus selective reads plus caching, cut modeled cost per 1,000 tasks from $3,584 to between $2,324 and $524. The practical takeaway: instrument by stage first, because the invoice cannot show you where to cut.

Every number and chart in this post comes from a simulation with assumptions listed below. It is illustrative, not measured on production traffic, and your results will differ. Prices are placeholders, and the quality scores are assumptions, not measurements.

Introduction.

Agent workloads consume far more tokens than chat. A 2026 study of agentic coding runs reports roughly 1,000x the tokens of code chat, with input tokens rather than output tokens driving the cost, and up to 30x variation between runs of the same task (Bai et al., arXiv:2604.22750). Input-dominated cost is a hint that the bill is mostly about context: what the agent carries and re-sends, not what it writes.

That is hard to act on from an invoice. "99% input tokens" does not say whether to trim the system prompt, cap page reads, deduplicate retrieval or move a step to a cheaper model. Observability standards are catching up: the OpenTelemetry GenAI conventions define gen_ai.usage.input_tokens and gen_ai.usage.output_tokens on model spans, though agent-level conventions are still marked as in development (OpenTelemetry GenAI spans). Token counts per call exist. Attribution by stage mostly does not, unless you build it.

We have covered the anatomy of one ReAct step, the decision between search and read and per-team chargeback. This post covers the layer between them: a per-stage ledger, and what it changes.

Research question.

Where do tokens get wasted in a search-and-read agent once every token is attributed to the stage that created it, and which optimizations reduce cost without a matching loss in answer quality?

Methodology.

We simulated 4,000 research tasks per architecture. Each task runs 2 + Poisson(4) search/read cycles (6.0 on average). Assumptions:

Four architectures: (1) naive, premium model for every call; (2) router, small model for query generation, premium for reasoning and synthesis; (3) router + triage + selective read, a small-model triage call over snippets, then reading the top 2 pages in parallel with boilerplate stripped after retrieval; (4) the same plus prompt caching, assuming a perfectly stable prefix and no cache misses, which makes it an upper bound.

Results.

Result 1: the ledger sees what the invoice cannot.

Chart 1: The provider invoice shows 99% input tokens. The stage ledger shows page reads at 73%, search snippets 10%, system and tool schemas 9%, reasoning 8%. Illustrative simulation.
Chart 1: The provider invoice shows 99% input tokens. The stage ledger shows page reads at 73%, search snippets 10%, system and tool schemas 9%, reasoning 8%. Illustrative simulation.

In the naive agent, 73% of billed tokens trace back to page reads, 10% to search snippets, 9% to system prompt and tool schemas, and 8% to reasoning. Query generation and final synthesis together are under 1%. The answer is the smallest line item in the bill. This agrees with the shape reported for real coding agents: cost is driven by context, not completions.

Result 2: about half the tokens are waste.

Chart 2: Modeled token waste in the naive agent is 53% of billed tokens: irrelevant chunks 33%, duplicate retrieval 7.5%, boilerplate 6.3%, over-reading 3.6%, repeated reasoning 2.0%.
Chart 2: Modeled token waste in the naive agent is 53% of billed tokens: irrelevant chunks 33%, duplicate retrieval 7.5%, boilerplate 6.3%, over-reading 3.6%, repeated reasoning 2.0%.

Under our assumed rates, irrelevant retrieved chunks are the largest category at 33% of billed tokens, followed by duplicate retrieval (7.5%), verbose tool output (6.3%), over-reading (3.6%) and repeated reasoning (2.0%). The ranking depends on the assumptions, but the mechanism does not: waste in a retrieved page is paid again on every later call, so it compounds. The same effect is why over-retrieval is costly in RAG pipelines.

Result 3: cost falls in steps, and each step has a different cause.

Chart 3: Modeled cost per 1,000 tasks: naive premium $3,584; router $2,324 (35% lower); router plus triage and selective read $1,227 (66% lower); plus prompt cache $524 (85% lower). Illustrative prices.
Chart 3: Modeled cost per 1,000 tasks: naive premium $3,584; router $2,324 (35% lower); router plus triage and selective read $1,227 (66% lower); plus prompt cache $524 (85% lower). Illustrative prices.

Routing only the cheap steps saves 35%, which is modest because query generation was never the expensive stage. Selective reading is the big move (a further 31 points) because it shrinks the stage the ledger flagged. Caching adds the largest relative drop, but treat 85% as a ceiling, not a forecast: it assumes every prefix hit, and the cache-write premium and TTL misses eat into it in production. Savings from routing, selection and caching also overlap, so measure them together rather than adding them.

Result 4: latency follows tokens, but routing can add hops.

Chart 4: Modeled p50 and p95 task latency: naive 137 s and 214 s; router 133 s and 236 s; router plus selective read 112 s and 171 s; plus cache 101 s and 169 s. Assumed throughput and tool latency.
Chart 4: Modeled p50 and p95 task latency: naive 137 s and 214 s; router 133 s and 236 s; router plus selective read 112 s and 171 s; plus cache 101 s and 169 s. Assumed throughput and tool latency.

Selective, parallel reads cut modeled p50 by about 18% and p95 by about 20% versus naive. Router-only p95 got worse (236 s against 214 s) in our model because an extra hop adds tail latency without removing any prefill. This matches the pattern in tail latency and parallel tool calls: speed comes from less context and fewer sequential waits, not from a cheaper model alone.

Result 5: the tradeoff has a shape.

Chart 5: Assumed cost versus quality: premium-only 90% at $3,584; hybrid routing and triage 89% at $1,227; aggressive compression 82% at $1,362; small-model-first 80% at $224.
Chart 5: Assumed cost versus quality: premium-only 90% at $3,584; hybrid routing and triage 89% at $1,227; aggressive compression 82% at $1,362; small-model-first 80% at $224.

Quality here is assumed, so read the shape only. Aggressive compression applied before retrieval removes decision-critical information and lands below hybrid routing on both axes. Small-model-first is cheapest but costs the most quality, and it ignores retries, which the retry tax can turn into a net loss.

Discussion.

Limitations: this is a model, not a measurement. Waste rates, prices, throughputs and quality scores are assumptions. The 4-page naive read and 6-cycle average are typical of research agents but not universal.

Implementation guide.

  1. Instrument token usage by stage. Tag every model call with a stage name and task ID; record input, output and cached tokens.
  2. Separate reasoning tokens from context tokens. Reasoning is output you can shorten; context is input you can avoid sending.
  3. Detect over-reading and duplicate retrieval. Track pages read per page cited, and hash URLs or chunks per session.
  4. Route simple steps to cheaper models. Query generation, triage and formatting rarely need the flagship.
  5. Compress only after retrieval. Strip boilerplate from pages you chose to read, not blindly beforehand.
  6. Add confidence thresholds and fallback. Escalate to the premium model when the cheap model's score is low.
  7. Monitor cost, latency and answer quality together. Alert on cost per resolved task, not cost per token.
from collections import defaultdict

def ledger(calls):
    """calls: [{'task','stage','in_tok','out_tok','cached_tok','origin_stage'}]"""
    by_stage = defaultdict(int)
    for c in calls:
        # charge re-sent context to the stage that created it
        by_stage[c.get("origin_stage", c["stage"])] += c["in_tok"] + c["out_tok"]
    total = sum(by_stage.values())
    return {s: round(100 * t / total, 1) for s, t in sorted(by_stage.items(), key=lambda x: -x[1])}

Where Nadir fits.

This is the kind of problem model routing is built for. Instead of treating every step as a flagship-model problem, a team can classify each step's difficulty and send it to the cheapest model that clears a quality floor. Nadir does that with model="auto" and returns per-request routing and cost metadata, so the ledger above can be built from response headers instead of a new tracing stack. Savings vary with your workload, and the stage ledger is how you find out whether your agent looks like this simulation.

Conclusion.

The future of LLM cost optimization is not only cheaper models. It is better orchestration, better routing, better retrieval discipline and better measurement. In our simulation, the stage that mattered was invisible on the invoice. Measure first, then cut.

If you want to see where your own spend goes, estimate your savings, route a slice of your agent traffic, and compare cost, latency and quality per stage against your current baseline.


Sources: [Bai et al., "How Do AI Agents Spend Your Money? Analyzing and Predicting Token Consumption in Agentic Coding Tasks," arXiv:2604.22750](https://arxiv.org/abs/2604.22750). [OpenTelemetry, "Semantic conventions for generative client AI spans"](https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/). Simulation code and parameters are described in the Methodology section; all figures are illustrative.

More on agents

What Nadir is

Nadir is an LLM router. Nadir sends each prompt to the cheapest model that can handle it. A small decision model reads each prompt against your model menu and picks the lowest-cost model it expects to handle it. When the decision model is uncertain or unavailable, the request goes to the strongest model on the menu. The routing step makes no call to your model provider.

Nadir runs two ways. The decision API returns a model, reasoning-effort, cache, context, and policy recommendation without calling a model provider, beside the gateway you already run. That is how a shadow-mode evaluation works, and its projected savings stay advisory. The OpenAI compatible managed proxy executes the route, and migration is a two-line change: point the base URL at api.getnadir.com and set model to auto. On that path an optional verifier can score a complete non-streaming answer and escalate to a stronger model when it misses the configured bar. Streaming bypasses post-generation verification. BYOK is supported on every tier.

For coding agents, Nadir Auto is a terminal launcher for Claude Code or Codex that asks Nadir for the main-session model before each turn, with your configured model as the fallback and cost ceiling. Delegation integrations for Claude Code, Codex, or Cursor instead recommend a model tier for subagent work, and the agent decides; the Claude plugin can also move a main-thread turn to Haiku when Nadir's cache check prices it cheaper, unless its switch_main_model option is off. Either way inference runs on your own provider account, so Nadir holds no provider keys on that path.

What the numbers are, and what they are not

Nadir publishes each evaluation with its scope. On checkable code, run-check-escalate solved 392 of 395 common HumanEval and MBPP problems (99.2%), graded by running the canonical tests; that applies only to tasks with runnable deterministic tests. Nadir-Tumbler posts an arena_score of 72.3 on RouterArena's public scorer, 5th of 23 routers, which measures the routing decision on RouterArena's own model pool. A reference-assisted RouterBench evaluation over 11,420 held-out triples produced a 60% lower projected cost than always-Opus with about 98% retained quality and a 1.7% catastrophic-route rate. That experiment gave the verifier the expensive-model reference answer, which production does not have, so it is a research ceiling and not the deployed path.

None of these is a production guarantee, a universal savings rate, or a forecast for any particular workload. Customer savings are reported from measured execution against a declared baseline, and customer quality only from outcome-labelled traffic. Projected savings and realized savings are separate artifacts and are never blended.

Design-partner program

Three rungs, picked by risk appetite. Rung 0 Shadow runs advisory decision calls alongside live traffic and returns a projected receipt, with nothing in the request path changed. Rung 1 Hosted is the two-line swap on a production slice and returns a realized receipt. Rung 2 On-prem is a supervised six-week proof of concept inside the partner's VPC, where no prompt, response, or usage reaches Nadir. The commitments are the same at every rung. Apply for a rung directly: Rung 0 Shadow, Rung 1 Hosted, or Rung 2 On-prem. Not sure which fits? Start at getnadir.com/contact/?reason=design-partner.

Licensing

NadirClaw is the self-hosted core, source-available under the PolyForm Noncommercial License. Source-available is the correct label; NadirClaw is not open source. Nadir Route's hosted plan has no base fee and charges a variable fee only on measured savings from requests Nadir executed.

Pages on this site

Machine-readable summaries of this site: llms.txt and llms-full.txt.