Cost control

LLM Cost Control with Validation-Gated Routing

Per-agent budgets, token caps, and cheap-first model fallback — spend limits enforced on every request without bypassing quality gates.

8 min read

At a glance

Traffic on economical tier (typical)
~88%
Escalated after validation fail
~10%
Routed to human queue
~2%
Invented “cost avoided” KPIs
0

Representative split from validation-gated routing deployments; your mix depends on validators and prompts.

LLM cost conversations start with "use a cheaper model." They should start with "use the right model for each step, and prove the output is good enough before you pay for premium."

GPT-4 on every call is a budget fire. GPT-4o-mini on every call is affordable — until quality failures create support tickets, retries, and human rework that cost more than the tokens you saved.

ValGuard enforces per-agent budgets, token caps, and validation-gated cheap-first fallback on every request. Spend limits and quality gates share the same path — so FinOps never bypasses guards.

Read the cost optimization pillar for routing patterns. Operator details live in cost control documentation.

Cost per successful outcome, not cost per request

A $0.002 completion that fails validation and retries three times loses to a $0.02 completion that passes once. Finance should track cost per successful outcome — the same shift argued in measuring AI quality in production.

Representative economics from teams using validation-gated routing:

Traffic shareModel tierTypical role
~88%Economical (mini class)Classification, extraction, routing
~10%FlagshipSynthesis after mini fails validation
~2%Human queueDeterministic failures, policy edge cases

The Smart LLM Fallback Router playbook encodes this graph: try mini, validate, escalate on failure, audit every hop.

Surfaces where spend is controlled

Cost hub — month-to-date spend, spent-on-blocked requests, seven-day burn sparkline, recommendations, and top spend by agent.

Agent settingsmonthly_budget_usd with block, fallback_agent, or cheaper_model degrade modes (Growth+ for degrade; Free tier hard-blocks at cap).

Playbook budget routes — graph conditions on_budget_exceeded and budget_remaining_below; budget edges win over agent policy.

Request detail — cost badges labeled priced when a curated model price was used, otherwise estimated from write-time cost_estimate_source. No invented "cost avoided" KPI.

Set workspace rates under Account → Model prices (USD per 1M input/output tokens). Org overrides beat curated defaults; missing rows fall back to a token heuristic and label estimated.

The retry logic that doubles costs

Same model, same schema violation, three retries — each billed at full price. A deterministic enum failure will not self-heal with identical temperature. Retry storms wreck latency too, not just budgets.

Validation pattern:

  • No retry on deterministic violations — switch model or escalate
  • Exponential backoff on transient errors — rate limits and 503s only
  • Shared retry budget per user session — prevents runaway agents

Pair with observability metrics: alert on retry ratio, not just p99 latency.

RAG and multi-agent burners

RAG costs are retrieval + generation × retries. Common burners:

  • Oversized context windows stuffed with weak chunks
  • Regeneration loops when citations fail grounding
  • Recomputing embeddings on every query

Validation pattern:

  • Retrieval score floor — refuse cheaply instead of generating expensively
  • Chunk budget — validate sufficiency before expanding context
  • Single retry on grounding fail — widen retrieval once, then escalate

See RAG failure modes for retrieval gates that prevent wasteful generation.

Multi-agent flows compound cost: planner, researcher, writer, critic — each on flagship. Replace the critic LLM with validators wherever rules are expressible. Short-circuit when mini extraction passes its schema gate — skip the premium polish step entirely.

Exact response cache (opt-in)

For idempotent prompts, enable exact response cache per agent under Limits & privacy and set COST_RESPONSE_CACHE=1 on the proxy. Stores only post-validation accepted completions; Redis keys are org+agent scoped.

Cache hits still record estimated cost_micro_usd toward agent budgets and month-to-date rollups; upstream savings are tracked separately via metrics. Semantic similarity is not enabled yet — exact match only.

Tutorials and templates

Walk through spend controls step by step:

  • Using Cost control — hub recommendations, spend-by-agent, phrases, prices
  • Budget alerts — USD caps and degrade modes
  • Monthly token limits — complementary token caps separate from USD budgets

Install the validation-gated router from the Cost hub CTA or orchestration templates (smart-llm-fallback-router).

Honest numbers build trust

FinOps for AI fails when dashboards lie. ValGuard labels estimates as estimates, blocks as blocks, and logs escalation reasons so you can shrink the premium share over time by fixing mini prompts — not by hiding retry spend.

Cost control is not about spending less blindly. It is about spending on the model tier that actually passes the validators that matter — and stopping the loops that burn budget while quality stays flat.

Go deeper