8 September 2026 EN ES
The Serving Desk

The stack under your AI product — models, serving, and what it costs

Costs

Cut AI coding token bills with bulk-read routing and context caps

A four-step cost framework: classify the task, route by model cost, cap context, and measure token savings against quality and latency.

Illustration: Cut AI coding token bills with bulk-read routing and context caps

Model cost per task sets the bill

Model cost per task sets the bill. A Java monorepo test showed the bulk-reader path cut Claude Code token use on those reads by roughly 90%. A Gartner forecast dated June 24, 2026 projects AI coding token costs above the average developer salary by 2028. Production routing research found that intelligent model routing can cut AI coding bills by 40% to 85% with no visible loss in output quality. The bill depends on which model answers and how much context it sees. For AI coding agents, the durable control is task-level routing, not prompt polish.

Route by task class before prompting

Classify the task before the model sees it. Start with the unit of work, not the prompt. Bulk reads ask for orientation: what files exist, what symbols are present, what patterns repeat. Surface-pattern work is search or mechanical transformation. Precise edits change a small, known region. Debug work needs causal reasoning. Judgment work requires trade-off analysis. The output is a label on each request: bulk read, surface pattern, precise edit, debug, or judgment.

Spotify's Portal setup used AiKA Modes with a Claude Code shunt extension. Repetitive I/O-heavy coding jobs went to Gemini 2.5 Flash, while Claude handled precise file work, edits, debugging, and complex judgment. The cheap model handles high-volume input and output. The expensive model handles the work where a wrong guess costs a rollback. The split is task-level cost control, not sentence-level prompt tuning.

Route by model cost once the label exists. The policy sends bulk reads to a cheaper worker and reserves the stronger model for precise edits, debugging, and complex judgment. Make the policy declarative, not a note in a file. Advisory routing is easy to ignore; a hook is harder to bypass. If the label is missing, default to the expensive model and log the gap. The routing rule stays visible in the trace, not hidden in a prompt.

Context caps protect quality

Cap context with file-size hooks before the expensive model reads a whole file. Context is the multiplier. A cheap model can still use tokens if it reads a large file, and an expensive model can use more if it receives a whole repository. The cap sits before the read, not after the prompt is built.

The control is a hook that blocks reads above a line threshold. Spotify replaced advisory CLAUDE.md routing with PreToolUse hooks in the shunt plugin; one pre-read hook stops reads above the default 350-line threshold. The hook forces the agent to request a summary, a slice, or a targeted search instead of sending a large file into the prompt. Make the threshold configurable per repository. A generated file may deserve a different limit than a hand-written module. A binary-adjacent file may deserve no read at all.

Caps can hide the relevant file. The low-cost worker surfaced obvious patterns but overlooked a subtle thread-safety defect; Claude found it quickly once given the relevant context. A cap cuts context, not the line that matters. If the expensive model needs a specific region, the routing layer hands it that region, not a guess.

Measure the bill, not the vibes

Measure token savings against quality and latency. The dashboard compares tokens per task, error rate, and response time before and after routing. Track the cheap path and the expensive path separately. A routing win that hides a quality loss is not a win. A latency win that hides a review burden is not a win. The number that matters is savings on the tasks that dominate spend, not average savings.

Delegated calls added latency, with typical responses at 10 to 30 seconds and Portal capping one invocation at 30 seconds. Set a review-time metric. If the cheap path saves tokens but adds review time, the bill moved, not disappeared. Compare the routed bill to the baseline on the same task set. If the routed path fails that test, tighten the cap or move the task back to the expensive model.

Advertisement