Repository navigation
test(cost): cover unpriced provider slugs and explicit zero rates - #42467
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Thanks, two of the three were right and are fixed in bc829e3. The helper docstrings explained what the code already shows, so they are gone. The vendor pinning was the real catch. The tests asserted Worth noting what that rewrite turned up, since it nearly slipped through. My first On the third point, lines 801 and 828 are 98 and 39 characters, so there is nothing to |
… readable 0.1.8 and 0.1.9 both claimed to stop streamed Claude turns being logged at zero cost. Neither did. The code has been sitting in the package doing nothing, so it goes. The diagnosis was right and the placement was wrong. 0.1.8 rewrote the chunks coming out of the stream, but the cost is computed inside CustomStreamWrapper from a value chunk_creator reads off the raw chunk first. 0.1.9 corrected that attribute through chunk_creator, which is right for a plain wrapper, except the Router interposes a FallbackStreamWrapper that overrides __anext__ and never calls chunk_creator. That class is defined inside _acompletion_streaming_iterator, so it is not importable and the tests could not have built it: all three attempts were verified against a hand-made wrapper that behaves differently from what the proxy gets. The bug is upstream: BerriAI/litellm#42161, PR at BerriAI/litellm#42467. An explicit input_cost_per_token in model_info works around it meanwhile. Tool-name aliasing from 0.1.7 is untouched. Its tests now cover only what it actually does, including that the stream wrapper is handed back as itself. LICENSE is plain MIT again so GitHub stops reporting NOASSERTION; the oh-my-pi attribution that used to sit mid-file is in NOTICE, shipped in the wheel.
…rn at zero
Anthropic names the dated build in `message_start`, so a streamed turn carries
`provider_response_model="claude-opus-5-20250930"` while the price map holds
`claude-opus-5`. `_select_model_name_for_cost_calc` prefers the reported name
over `response.model`, and `get_model_info` answers a model it has never heard
of with zero rates rather than raising -- so the turn is billed 0.0 with nothing
in the logs to explain it.
Same usage, only that field varying, on main:
provider_response_model absent -> 0.00079
provider_response_model=claude-opus-5 -> 0.00079
provider_response_model=claude-opus-5-20250930 -> 0.0
Missing is harmless; the damage is a name that is present and unpriced.
The reported name still wins whenever it resolves to a rate -- it is the most
specific truth about what served the turn. It is only passed over when charging
by it would produce a silent zero, and then the response's own model is used:
the name the deployment resolved to, and the one an unstreamed turn is already
priced by.
This is not specific to Anthropic or to streaming. Any provider reporting a more
specific slug than the map carries -- dated, regional, build-suffixed -- is
affected, and only streamed turns carry the field, which is why it reads as a
streaming bug from the outside.
Reported in BerriAI#42161.
bc829e3 to
eda6bbf
Compare
…in tests Three points from the review, two of which were right. The helper docstrings explained behaviour the code already shows, which AGENTS.md rules out. Removed. The tests asserted that `claude-opus-5` is in the price map and `claude-opus-5-20250930` is not. Both are facts we do not own: if Anthropic registers the dated build, the test breaks without any litellm change. They now use a name that is ours, and assert the invariant instead, that what the provider reports cannot change the price of a turn the map cannot quote it by. Picking that name needed care. An arbitrary string makes `get_model_info` raise, which a caller upstream already handles, so the test passed with or without the fix and defended nothing. A `claude-` prefixed name reaches the zero-rate fallback that this bug rides on, so `claude-test-42161` reproduces it and stays ours. The third point, that lines 801 and 828 exceed 120 characters, does not hold: they are 98 and 39.
eda6bbf to
00b8e37
Compare
59843dd to
57182eb
Compare
Mark the blind except in _has_rate with noqa: BLE001, as the file does elsewhere for get_model_info.
…ponse_model basedpyright counted the bare variable as partially unknown (reportUnknownArgumentType +1 over the budget).
|
Updated onto current
Changes since the last review:
Two checks still fail, and they fail the same way on other open PRs: |
|
thank you for contributing! |
TLDR
Problem this solves:
How it solves it:
Current main already handles the original report. After integrating main, this PR contains only regression tests and documentation, with no pricing implementation changes relative to main
User Flow
Before, current main already calculates the expected charges
After, the same behavior has focused regression coverage
Relevant issues
Related to #42161. This PR no longer claims a new runtime fix for that issue
Pre-Submission checklist
All three targeted regression cases passed after integrating main at
66cd1a651647. An earlier full-file run had 515 passing tests and one failure when Windows environment isolation prevented Prisma from finding the home directory. That full-file failure was not rerun to reconfirm itScreenshots / Proof of Fix
This is a regression-only PR. The same real
completion_costprogram passed at the current merge base and the published tip. Rates and model names are locally registered test values, so no provider account or paid request is involvedRun the shared program from each checkout
Before (66cd1a6)
0.086, the explicitly priced provider costs0.86, and the explicitly free provider costs0.0After (b7f95fa)
CI follow-up
The root shard failed after a runtime-registration replay test overwrote
supports_function_callingon the shared catalog and then restored the same already-mutated dictionary. A later proxy-capability case on that worker read the leaked valueBoth registration replay tests now use the existing
local_model_cost_mapfixture. The failing capability assertion is unchanged. A serial run of the replay cases, proxy capability cases, and pricing regressions passed all 24 cases. A real SDK registration probe also changed the flag temporarily and confirmed the original catalog and capability were restoredThe pricing smoke was repeated at this tip and preserved the same four charges. No production pricing implementation changed. The new push starts a fresh CI run rather than rerunning the failing revision
Type
Test
Documentation
Caveats
Medium
Low
No maintainer review is requested until the latest automated checks and findings are examined
Final Attestation