Add Ramp Router price mode - #36
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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 checkandmypyclean onsrc/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:
apigets reassigned to"ramp_router"before the total_tokens consistency guard runs inextract_openai_native, so the guard andcompute_cost/_split_cache_writeagree on the de-overlap convention. Confirmed the reassignment sits above the guard, not below. This is exactly the kind of divergencetoken_semantics.pyexists to prevent, and it is handled correctly. - Confirmed
TOKEN_BILLED_PROVIDERSno longer listsramp_router(superseded by the catalog price source) and thatPricingUnavailableError's newdetailkwarg 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, andcapture_ramp_router.pyalready 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_aliasknowingly 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/rampRouterUnpricedTierare 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
sarkissianraffi
approved these changes
Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.