Skip to content

Add Ramp Router price mode - #36

Merged
anassg-lago merged 1 commit into
mainfrom
feat/ramp-router-price-mode
Sep 7, 2026
Merged

anassg-lago merged 1 commit into
mainfrom
feat/ramp-router-price-mode

Conversation

@anassg-lago

Copy link
Copy Markdown
Collaborator

Price Router calls from Router's own /v1/models catalog, on both the Responses surface (OpenAI client) and the Messages surface (Anthropic client). Learn the Router key from the wrapped client; price only the default tier; bill Anthropic cache writes at their 5m/1h rate on /v1/messages; refuse Fireworks entries served through Baseten rather than misprice them. Reconciled against the Router dashboard across three sweeps; documented mismatches (eight OpenAI models, two legacy snapshots) are recorded in docs/ramp-router.md with a markup recommendation instead of code.

Price Router calls from Router's own /v1/models catalog, on both the
Responses surface (OpenAI client) and the Messages surface (Anthropic
client). Learn the Router key from the wrapped client; price only the
default tier; bill Anthropic cache writes at their 5m/1h rate on
/v1/messages; refuse Fireworks entries served through Baseten rather
than misprice them. Reconciled against the Router dashboard across
three sweeps; documented mismatches (eight OpenAI models, two legacy
snapshots) are recorded in docs/ramp-router.md with a markup
recommendation instead of code.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE (no blockers found). Posting as a COMMENT review because this session is not permitted to submit APPROVE/REQUEST_CHANGES reviews on this repo.

No blockers.

What I checked:

  • Ran the full unit suite: uv run pytest tests/unit -q -> 930 passed. ruff check and mypy clean on src/lago_agent_sdk.
  • Manually re-derived the core money math instead of trusting the checklist: the $0.02518225 claim (16 input + 20113 cache_write_5m + 5 output on claude-haiku-4-5 pricing) reconciles exactly: 16e-6 + 20113 x 1.25e-6 + 5 x 5e-6 = 0.02518225.
  • Traced the token_semantics ordering hazard the code itself flags in a comment: api gets reassigned to "ramp_router" before the total_tokens consistency guard runs in extract_openai_native, so the guard and compute_cost/_split_cache_write agree on the de-overlap convention. Confirmed the reassignment sits above the guard, not below. This is exactly the kind of divergence token_semantics.py exists to prevent, and it is handled correctly.
  • Confirmed TOKEN_BILLED_PROVIDERS no longer lists ramp_router (superseded by the catalog price source) and that PricingUnavailableError's new detail kwarg is optional, so no other call site breaks.
  • Grepped fixtures, the capture script, and full branch history (git log -p main..head) for leaked identifiers: nothing. The "Bearer sk-router-learned" / "learned-key-123" strings in tests are fixture placeholders asserting header construction, not real keys, and capture_ramp_router.py already redacts real Bearer tokens on capture.
  • Checked this repo's other open PRs: only a dependabot PR, no file overlap.

Non-blocking notes:

  • The live-account dashboard reconciliation percentages (measured 2026-09-04/2026-09-07) aren't independently verifiable from here; they're dated, specific, and falsifiable if wrong, so I'm taking them at face value rather than treating them as unverified.
  • _is_foreign_backend_alias knowingly turns a few Baseten-served calls that happen to match the Fireworks rate into misses instead of prices. Correct, documented tradeoff (a mispriced hit is worse than an honest miss), not a bug.

Merge notes:

  • No overlapping open work in this repo.
  • Companion PR getlago/lago-agent-sdk-js#55 mirrors this change. Diffed the two: computeCost/splitCacheWrite/parseRampRouter/isForeignBackendAlias/rampRouterUnpricedTier are behaviorally identical, same golden money test values, same fixtures. Either can merge first.

Genuinely good work on the depth of measurement: the documented table of Router-vs-catalog rate mismatches with dates, and the explicit refusal to bake a time-limited or undocumented factor into the SDK itself, is the right call for a billing library.


Generated by Claude Code

@anassg-lago
anassg-lago merged commit 5da85e2 into main Sep 7, 2026
6 checks passed
This was referenced Sep 7, 2026
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.

2 participants