Pular para o conteúdo
← Back to Skalablog

Published article

AI token cost reduction: a shadow test release

Software Engineering

AI token cost reduction starts with a baseline you can trust, not with a smaller model. Run your production prompt three times on the same inputs and measure how often it disagrees with itself; that self-disagreement is the ceiling any cheaper candidate has to beat. Only then do caching, prompt search and model downsizing become measurable engineering rather than guesswork, and only then can a paired confidence interval decide the release.

AI token cost reduction needs a measured baseline

AI token cost reduction starts with observability, because a cost cut you cannot measure against a fixed benchmark is a guess. Instrument the shared model client so every attempt becomes part of a trace linking model calls, tools and retries for one task, and record the prompt version, model settings, token usage, latency and cost. OpenTelemetry, the open-source telemetry standard, is one framework used for that trace data.

Alvin Pane, head of agent intelligence at the AI customer-communication company OutRival, described this workflow in an October 2026 AI Engineer talk. His team's digital workers handle tasks over phone, text and email, and the application layer processes billions of tokens a day. At that volume, repeated model calls compound into latency and compute cost.

The talk's running example is a synthetic 5,000-token customer-intent prompt for a fictional company called HarborBite. Pane is explicit that it is a proxy built to mirror structural prompt bloat, not a customer case study.

Once the telemetry exists, the same records double as a benchmark. Historical production requests become the test set that later prompt-search and model-downsizing runs are scored against.

Measure production's own variance before judging a cheaper model

A cheaper candidate model that disagrees with your production model is not automatically worse, because production disagrees with itself. OutRival's candidate disagreed with the expensive production baseline on about 18% of examples, and the team initially discarded it on that number alone. To find out what the 18% actually measured, they asked whether production agrees with production.

They ran the production prompt three separate times on the same inputs. It disagreed with itself roughly 7% of the time, so production's self-agreement was about 93%. The candidate was being held to a consistency standard the baseline could not meet.

That AA test is the ceiling. It converts model-to-model disagreement from a pass/fail signal into a composite of baseline variance plus real behavioral difference. Without it, a 7% noise floor gets read as candidate failure.

Any figure here is specific to OutRival's prompts, inputs and sampling settings. Self-disagreement is not a fixed property of a model name, so run the test on your own traffic rather than adopting 7% as a universal threshold.

The three levers, in sequence

Three technical levers cut token spend, and Pane runs them in order because each one makes the next cheaper to evaluate.

  1. Cache the repeated work. Structure prompts so the stable prefix, the instructions and examples that do not change between requests, is identical across calls. That maximizes prefix-cache hits and removes tokens you were paying for twice.

2. Shrink the prompt. The HarborBite example carries 20 edge cases, pedantic definitions, hard-coded worked transcripts and defensive lines such as instructions not to confuse enthusiasm with authorization. Pane treats the rewrite as a search problem rather than an editing problem.

3. Downsize the model. With a tight prompt and a working search loop, route simple work such as intent routing or data extraction to a cheaper model and reserve the expensive model for heavy reasoning. The same search loop can also fit a prompt to a smaller model directly.

Search beats hand-editing a bloated prompt

Treating the prompt as a search space means defining the interface contract, the expected output schema and a scoring function, then letting an optimizer revise the instructions against your benchmark. Pane names DSPy, the Stanford-maintained framework for programming language models, as the place to declare that contract, and GEPA as the optimizer that searches the instruction space and learns from failures.

The automated search stripped most of HarborBite's long worked examples and replaced them with compact rules. Pane reported a 51% reduction in instruction tokens while the application contract stayed the same. The 51% covers instruction tokens in that synthetic prompt, not the whole pipeline's bill.

That distinction matters. A 51% smaller instruction block still consumes output tokens, tool calls and retries that the rewrite does not touch, so it is not a 51% cost reduction on the task.

Automation also sidesteps the social problem Pane describes: nobody wants to be the engineer who deletes a line and breaks production. A scoring function gives the deletion a test, so the edit becomes reversible.

Shadow evaluation compares three things, not one

A smaller model can fit a narrow benchmark and fail on unfamiliar inputs, so the release test runs in shadow on live-shaped traffic and measures three pairings: production against production, candidate against candidate, and candidate against production. The third pairing is not a clean quality signal until the first two establish each system's internal variance.

Pane describes the arithmetic as disagreement between versions minus average within-version disagreement, which leaves an estimate of how far apart the two decision distributions sit. The ceiling test supplies the within-version term.

Different does not mean wrong. If the optimizer worked, the distributions should differ because the cheaper prompt handles some inputs better than the original. Human review of sampled diffs sorts the disagreements into regressions, improvements and two acceptable answers to an ambiguous input.

In the HarborBite walkthrough the completed review confirmed 443 regressions against 2,463 improvements, roughly six improvements per regression. Those counts come from a synthetic example, so they illustrate the review mechanics rather than a measured production result.

Ship on a confidence interval and check critical categories

A point estimate is not a release criterion. Compute a paired confidence interval around the net quality gain, keep both versions answering the exact same request, and group repeated runs of the same conversation together so sampling noise is accounted for.

The rule Pane gives is that the lower confidence bound must sit above zero before anyone claims the candidate is better. If the interval crosses zero, the honest state is that the evidence is insufficient, and the next step is more data rather than a launch.

Run the same math separately on critical customer categories. A strong global average can hide one vital intent that is degrading, and that category deserves its own interval rather than a share of the aggregate.

The result is a release rule instead of a debate. Cache the obvious repeated work, let the optimizer shrink instructions, measure variance with the ceiling test, then let the paired interval decide.

Evidence class and limits of this workflow

Every number in the playbook is a 2026 first-person account from the engineer running the workflow. Treat the 18% and 7% disagreement rates, the 51% instruction-token reduction and the 443-versus-2,463 review counts as speaker-reported and configuration-specific, not as independently reproduced benchmarks.

LeverWhat it changesReported gainEvidence class
Prefix cachingRepeated input tokensNot quantified in the talkSpeaker experience
Prompt search with DSPy and GEPAInstruction tokens51% reduction on the synthetic promptSpeaker-reported, vendor-tool workflow
Model downsizing and routingWhich model serves each callNone reported; prompts often failed reviewSpeaker experience
AA ceiling testInterpretation of disagreementProduction self-agreement about 93%Speaker-reported measurement

The talk frames the approach as replacing guesswork with an explicit release rule. It is a workflow for reducing inference cost while holding measured behavior, not a claim that any specific percentage of spend will disappear.

FAQ

  • What is the ceiling test in LLM evaluation? The ceiling test runs your existing production prompt several times on the same inputs and measures how often it disagrees with itself. That self-disagreement rate is the consistency ceiling any cheaper candidate is judged against. It separates baseline noise from real behavioral change.
  • How does DSPy fit into AI token cost reduction? DSPy, the Stanford-maintained framework for programming language models, lets you declare the input and output contract plus a scoring function instead of hand-writing instructions. An optimizer such as GEPA then searches the instruction space against your benchmark and revises prompts from failure feedback.
  • Is prefix caching or prompt shrinking more effective? Prefix caching removes repeated input tokens with no change to behavior, so it is the cheaper first step. Prompt shrinking needs a quality test because the rewritten instructions can change outputs. Run caching first, then shrink.
  • When should you downsize to a smaller model? After the prompt is tight and the search loop is scoring against a fixed benchmark. Route simple work such as intent routing or extraction to a cheaper model, and keep the expensive model for heavy reasoning. Expect some downsizing runs to fail review.
  • Why is model-to-model agreement a weak quality measure? Because production is probabilistic and ambiguous inputs produce different answers across runs. Agreement folds the baseline's own variance into the comparison, so a candidate can look bad purely from sampling noise rather than from worse behavior.
  • What confidence level should you use before shipping a cheaper model? The talk's rule is that the lower bound of the paired confidence interval around the net gain must be above zero. If the interval crosses zero, collect more evidence instead of shipping.
  • Why check critical categories separately? A good global average can conceal one important customer intent that regressed. Running the paired interval per critical category catches damage that the aggregate hides.
  • Does a 51% token reduction mean a 51% cost cut? No. The reported 51% covers instruction tokens in one synthetic prompt. Output tokens, tool calls, retries and other pipeline steps keep their own cost, so the saving on the full task is smaller.
  • How long should shadow evaluation run? Long enough for the paired interval's lower bound to clear zero on your real traffic and on each critical category. Sample size, traffic mix and how much each system varies all set the duration.

Reclaiming token maxing as a weekly habit

Pane's closing suggestion is to pick the most expensive task you run, measure its baseline variance, put it through a search loop and see how much of the bill was bloat. The token leaderboard measures consumption, and consumption is what you pay, not what you ship.

The workflow only works with real telemetry. Prompt versions, model settings, token counts, latency and cost per attempt are the raw material for both the ceiling test and the release decision, and they are the part most teams skip when they jump straight to a cheaper model.

If you record talks or long-form explanations where you walk through a workflow like this, the reasoning often stays locked in the video. Skala Blog takes a YouTube link, transcribes the video and drafts an article from it. You can review and edit the draft before publishing, which turns a one-time explanation into a page readers and answer engines can find later.

Continue building

If this breakdown of measured token optimization was useful, there is more material on the Skala Blog covering agent workflows, inference cost and evaluation practice. It is a place to keep reading when you want the reasoning behind a talk rather than the headline.

For readers in Brazil who want to go deeper on shipping real systems, the Crazystack community runs the Crazystack Typescript track and the Bootcamp do Dev Doido, and Gustavo Dev Doido publishes practical engineering material for that audience at crazystack.com.br.

Write the playbook down before you change the prompt, because the numbers are the only thing that will settle the argument later.

A note on how this article was made

Skala Blog

Source video