Skip to content
Skillpedia
Misc81k Β· #1598

cost-counterfactual

What it does

This skill compares your real AI spending with what it would have cost if every task had used one model tier. It is for people who want to know whether automatic model choice is worth it.

When to use it

  • βœ“When you want to know if picking models automatically is saving you money.
  • βœ“When you suspect the router uses expensive models too often.
  • βœ“When you want to compare your spending with using only the cheapest or the most capable model.

Skill link

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-counterfactual/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-cost-tracker/skills/cost-counterfactual/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œIs my automatic model choice actually saving me money compared with always using one model?”

5 new skills a week. 1 minute to read.

How it works

The skill recalculates past token use at the price of each tier and subtracts your real cost. A positive result means the routing saved money, and a negative result means it spent more.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Multi-baseline counterfactual cost analysis. Pairs with the existing observability surface:

  • cost-budget-check β€” "have we crossed a threshold?" (reactive)
  • cost-projection β€” "when will we cross a threshold?" (predictive)
  • cost-counterfactual β€” "is the routing earning its keep?" (comparative) ← this one

Algorithm

  1. Read all session-* records from the cost-tracking namespace.
  2. Apply --since window filter (default all-time).
  3. Sum tokens across byModel[*] entries for each session.
  4. For each requested baseline (default: all three):
    • counterfactualUsd = (input Γ— tier.input + output Γ— tier.output + cache_write Γ— tier.cache_write + cache_read Γ— tier.cache_read) / 1M
  5. Compute savings = counterfactualUsd βˆ’ actualUsd.
  6. Emit per-baseline totals + savings % across the comparison set.

Smoke transcript (2 sessions: 50K haiku tokens + 50K sonnet tokens)

| Sessions considered | 2 |
| Total input tokens  | 100,000 |
| Actual spend        | $0.162500 |

| Baseline           | Hypothetical | Actual    | Savings    | %       |
| `always-haiku`     | $0.025000    | $0.162500 | -$0.137500 | -550.00% |
| `always-sonnet`    | $0.300000    | $0.162500 | +$0.137500 |   45.83% |
| `always-opus`      | $1.500000    | $0.162500 | +$1.337500 |   89.17% |

How to read negative savings

A negative always-haiku result means the router chose more-expensive models than haiku on tasks haiku could have handled. That's an over-escalation signal:

  • Maybe qualityBar is set too high
  • Maybe the sonnet/opus session was warranted by complexity but the baseline doesn't know that
  • Run cost optimize (or inspect specific sessions via cost conversation) to investigate

Positive savings quantify the router's win against that baseline. The most informative number is usually always-sonnet β€” it's the standard "safe default" baseline most teams would pick if they didn't have routing.

When to use

  • Quarterly cost review: "We saved $X vs always-Sonnet β€” here's the proof."
  • CI gate: cost counterfactual --format json | jq '.baselines[1].savingsPct > 30' β€” fail builds if routing isn't saving β‰₯30% vs sonnet baseline (workload-shift detector).
  • Routing-config validation: When introducing a new qualityBar or cost-ceiling, re-run counterfactual to confirm savings didn't regress.

Stationarity caveat

Like all counterfactual analyses, this assumes the same tokens at the same complexity would have produced the same outcome from the baseline model. That's an upper bound β€” the baseline might have failed and required retries, which the math doesn't capture. Treat the numbers as a quality-blind ceiling.

FAQ

What do negative savings mean?

They mean the routing spent more than the baseline would have. That often means tasks went to a stronger model than they needed.

Which baselines are compared?

Always haiku, always sonnet and always opus, each with its own price table.

Can I limit the time period?

Yes. A since setting limits the analysis to a recent window, and all time is used by default.

Details

Original description by the author

Multi-baseline counterfactual cost analysis. Compares actual session spend to hypothetical always-haiku / always-sonnet / always-opus routing baselines. Answers "is the routing earning its keep?" Negative savings flag over-escalation; positive savings quantify the router's win.

repo: ruvnet/ruflo

Popularity

GitHub stars
81k
Ranking position
#1598
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills