Files
new-api/service
EtgpaoandCaIon 1b63c28dcc fix(claude): preserve explicit zero usage and cache-only billing (#7816)
* fix(claude): preserve explicit zero usage during stream finalization

* test: use synthetic values for Claude usage regressions

* fix(claude): estimate stream usage only when the counts are missing

Trusting every explicit zero let an upstream that reports zeros stream
output for free, and a zero in message_delta erased the input counted
at message_start. Decide from the counts instead: input is missing only
when input, cache reads and cache writes are all zero, and output only
when it is zero after streamed content. A broken stream still takes the
larger of the reported and estimated output. A fully cached prompt and
a refusal before any output keep their zeros, so relaykit usage parsing
goes back to its previous form.

---------

Co-authored-by: CaIon <[email protected]>
2026-10-14 22:31:33 +08:00
..
2025-06-07 12:26:23 +08:00
2025-08-15 16:54:26 +08:00