mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-10 11:13:08 +00:00
PPQ.AI (BYOK) requests were billed at ~5% of their true cost because _resolve_usd_cost fell through to usage.cost (a small BYOK routing fee) instead of using cost_details.upstream_inference_cost (the real inference cost). The proxy operator absorbed the inference cost. The fix adds a BYOK-specific branch in _resolve_usd_cost: when is_byok is true and cost_details.upstream_inference_cost is present, bill upstream_inference_cost + byok_fee — what PPQ actually deducts from the balance. Non-BYOK providers (e.g. OpenRouter) are unaffected because their usage.cost already equals upstream_inference_cost. Regression tests mirror the live glm-5.2-fast request from GitHub issue #615, asserting the corrected billing (940,274 msats vs the old 45,202 msats — a 20.8× undercharge). Closes #615