You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
accounting: Billing basis from the credential's shape drops some per-token savings out of dollar totals #2074
The accountant's saving counts as money only when its billing basis is usd. The basis comes from accountant.BillingFrom on the client's credential, snapshotted before the outbound chain (pipeline.Context.BillingSnapshot). The rule is by credential shape:
client credential
basis
x-api-key, or Bearer sk-… (not sk-ant-oat…)
usd
Bearer sk-ant-oat…, or any JWT-shaped bearer
subscriptionEquivalent
any other bearer, x-goog-api-key, or no credential
unknown
Two kinds of per-token traffic therefore leave every dollar total, where settle.Avoided on main counted them in dollars:
Wrong shape. A JWT bearer from a gateway or Keycloak is read as a subscription login. An opaque gateway key or a Gemini key is read as unknown.
Swapped credential. When inference-router sends a request to a server the request did not name, setKey replaces the credential with the server's own key. The basis still follows the client's original credential. Example: a Claude Code subscription login routed to a LiteLLM server with an sk- key is recorded as subscription, but the server's API key pays for that request.
The rule is documented in docs/pricing.md ("How the basis is chosen") as of #2057.
Why the snapshot is early
token-exchange, tokenbroker, inference-router (setKey) and staticinject all rewrite Authorization on the outbound chain. Reading the credential after all of them would misclassify more traffic, not less. So a fix must be targeted, not "read it later".
Possible fixes
Router: when inference-router swaps in a server's own key, let it set the basis from that key (a narrow hook from the router into the billing snapshot). Token-exchange and tokenbroker keep the client's basis.
JWT: in the accountant library, treat a JWT bearer as subscription only for known subscription endpoints (for example chatgpt.com), else unknown. This changes the label, not the dollar totals.
Unknown basis: decide whether a per-request or per-server config (for example an inference-router server's billing: api) may state the basis when the credential shape cannot.
A test should replay huang195's table (the same pruned request with each credential) and the router case.
Activity
fix(accounting): Address the review of the savings layer
fix(accounting): Address the review of the savings layer
fix(accounting): Address the review of the savings layer
fix(accounting): Address the review of the savings layer