Continuous optimization

The counterfactual is the point: lenops keeps a baseline of what each request would have cost under its original model and context, then charts it against what was actually spent. The gap between the two lines is the product.

Saved
$487.00
24.8% below baseline
Actual spend
$1473.00
14d cumulative
Baseline
$1960.00
no intervention
Run rate
−$34.79/day
net change vs baseline
Projected annual
$12694.00
at current rule set
Counterfactual

Optimized spend vs spend without intervention

Two cumulative lines. The first step change is routing; the second is the optimization rule set.

actual baseline (no intervention) cumulative saving
Attribution

Where the saving came from

SourceKindSavedShare
routing · routine-and-non-dev → localrouting$218.4044.8%
optimize · context_compactionoptimization$104.2221.4%
optimize · prompt_cacheoptimization$81.1616.7%
optimize · model_routing (downshift)optimization$52.9010.9%
routing · availability fallbacksrouting$30.326.2%
Rules

Optimization rule set

4 active · 3 enforcing, 1 in shadow. Shadow rules measure the saving without changing the response.

cache-repeat-prompts
prompt_cache · when prompt repeated ≥2x
compact-long-context
context_compaction · when prompt tokens > 8000
downshift-on-pressure
model_routing · when team budget used > 85%
batch-ci-docs
request_batching · when queue depth > 5
Safety

Rails that no rule may cross

Checked before any strategy is applied. A rule that would violate a rail is skipped and the skip is logged.

  • never degrade priority=p0
  • never compact below the declared minimum context
  • never apply a lossy strategy to environment=prod unless the rule opts in explicitly
Catalog

Available strategies

Ten strategies the harness can apply. Two of them optimize latency rather than cost, and are labelled as such.

StrategyWhat it doesTypical savingIn use
prompt_cachereuse a cached prefix60–90% of cached tokensactive
context_compactionsummarize history beyond a threshold30–60% of prompt tokensactive
model_routingserve from a cheaper equivalent tiervaries by tier gapactive
request_batchingcoalesce queued requests10–25% overheadactive
response_cachereturn a stored answer for an exact hit100% of the call
max_tokens_capcap output tokens per team or workload5–20% of output tokens
retrieval_pruninglower RAG top-k and dedupe chunks10–30% of prompt tokens
tool_iteration_caplimit agentic tool iterations per task10–35% per task
streamingstream tokens to cut time-to-first-tokenlatency only
speculative_decodingdraft model proposes, larger model verifieslatency only