Skip to content

feat(dynamic-pricing) F1: measured per-route economics (route_economics)#35

Draft
jmlago wants to merge 1 commit into
mainfrom
dynamic-pricing
Draft

feat(dynamic-pricing) F1: measured per-route economics (route_economics)#35
jmlago wants to merge 1 commit into
mainfrom
dynamic-pricing

Conversation

@jmlago

@jmlago jmlago commented Jun 28, 2026

Copy link
Copy Markdown
Member

What

First increment of dynamic-pricing (supersedes the static-prices approach of #32).

Adds the missing measured-economics member of the route_* family. Price is
the one ranking input the host still mostly DECLARES (sources stamp a pulled /
advertised price) while reliability, latency and tool-capability are already
rolling measured folds. This measures it.

  • route_economics.py — per-route EMA of the EFFECTIVE blended cost a route
    actually charged (USD/Mtok), from response.cost_reported (e.g. OpenRouter
    usage.cost) over token count. Exact twin of route_latency.
  • folded at the same outcome site as reliability/latency in llm_router_host.
  • surfaced as measured_usd_per_mtok in the market/perf view (shim), next to
    latency_ms.

Observability + measurement ONLY — it does NOT yet feed ranking.

Verify

Full suite 394 → 402 passed (+8 new unit tests), 2 skipped, 0 failed, under
nix-shell vs pinned core 97d0333. Behaviour preserved (additive).

NOT in this commit — these change selection (new external behaviour), the

form-giver's call, not mine:

  1. Ranking correction from measured cost. How the measured $/Mtok corrects
    the catalog's stamped price. Open design: a per-route correction ratio
    (actual ÷ expected-from-stamped-price) applied to the stamped price — which
    keeps the price_in/price_out split (the measured total can't be split per
    direction). For OpenRouter it converges ~1.0 (the pulled price is already
    right); for antseed it catches peers settling above what they advertised.
  2. OpenRouter 5.5% multiplier (cherry-pick from [codex] add effective provider pricing sources #32) — a cash-real,
    ranking+billing adjustment (the credit-purchase fee, off-band, not per-call
    observable). Kept distinct from any ranking-only preference (codex
    scarcity-price precedent, object §3).
  3. OpenAI direct price puller (HTML, Standard mode, fail-soft) and the
    provenance tags measured | pulled | advertised-untrusted.

Plan: /tmp/unhardcoded-dynamic-pricing-plan.md. #32 stays draft, closed at the
end.
This PR is a proposal for independent adjudication — not to self-merge.

Price is the one ranking input the host still mostly DECLARES (sources stamp a
pulled/advertised price) instead of MEASURING — while reliability, latency and
tool-capability are already rolling route_* folds. This adds the missing
measured-economics member.

- route_economics.py: a per-route EMA of the EFFECTIVE blended cost a route
  actually charged (USD/Mtok), from `response.cost_reported` (e.g. OpenRouter
  usage.cost) over token count. Exact twin of route_latency: success-only fold,
  None when no cost reported, in-process, reuses route_reliability.route_key.
- llm_router_host: fold the call's reported cost at the same outcome site as
  reliability/latency.
- shim market/perf view: surface `measured_usd_per_mtok` next to latency_ms, so
  the operator sees what a route REALLY cost vs the price the catalog stamped —
  the gap that matters most for marketplace peers that advertise a price they do
  not settle.

Observability + measurement ONLY: this does NOT yet feed ranking (that changes
selection — a separate, deliberate step). Additive: full suite 394 -> 402 passed
(+8 new unit tests), 2 skipped, 0 failed; behaviour preserved.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26799f53-b362-464d-a9f1-9c0100cecb41

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dynamic-pricing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant