fix(anthropic): map responses cached tokens to cache reads - #32445
Closed
silencedoctor wants to merge 11 commits into
Closed
fix(anthropic): map responses cached tokens to cache reads#32445silencedoctor wants to merge 11 commits into
silencedoctor wants to merge 11 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
silencedoctor
force-pushed
the
fix/anthropic-responses-cache-usage
branch
from
July 8, 2026 07:51
76223b8 to
82d3474
Compare
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
2 tasks
chore(ci): promote internal staging to main
_await_model_servable used poll_timeout (120s), the spend/log read-back budget. A stuck model reload therefore stalled every suite that creates a deployment for two minutes before failing Give create_model a fixed harness middle ground: model_servable_timeout=40s, polled every 2s, with each /v1/models call capped at 5s and clamped to the remaining deadline so one slow GET cannot overrun the wait. Happy path still returns on the first listing. Not derived from proxy general_settings or env Transport.get accepts an optional per-call timeout for that clamp. Unit tests cover the deadline arithmetic and clamp without a live proxy (cherry picked from commit c082a0e)
create_model returned after the first /v1/models hit that listed the model, so chat could still land on a cold gateway worker (numWorkers>1 / peer pod) and 400 Invalid model name. Require continuous listing for the product default add_deployment interval (30s) after first sight so every worker has synced from the DB; first listing still bounded at 40s (cherry picked from commit 7d1ee2f)
Keep the create_model DB-sync wait in the harness; the pure-function unit file is not needed for this PR (cherry picked from commit 8920465)
When less than one full poll interval remained in the first-listing budget, the pre-sleep check returned NotServable without another /v1/models call. Sleep only min(interval, time left) so a model that becomes listable in the last seconds of the timeout still gets a clamped final poll (cherry picked from commit 8439195)
A poll may start with remaining budget and still return after started+timeout if the transport overruns its clamp. Recheck the first-listing deadline after the response so a late listing does not open the continuous DB-sync phase (cherry picked from commit 7ff2bcb)
…l_servable_timeout test(e2e): bound the post-/model/new servable wait at 40s
silencedoctor
force-pushed
the
fix/anthropic-responses-cache-usage
branch
from
July 29, 2026 11:11
82d3474 to
5e80efc
Compare
|
|
silencedoctor
changed the base branch from
litellm_oss_staging
to
litellm_internal_staging
July 29, 2026 12:24
Contributor
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.
Relevant issues
Fixes #28354
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
This is a deterministic adapter translation bug. The public issue #28354 already includes a live-provider reproduction showing OpenAI Responses returns non-zero
usage.input_tokens_details.cached_tokenswhile LiteLLM's Anthropic/v1/messagesresponse reports zero cache reads. This PR's proof isolates the affected LiteLLM translation entrypoints with sanitized Responses usage data. It contains no real provider request, API key, hostname, customer payload, or organization-specific identifier.Before fix, captured from
upstream/litellm_oss_stagingat710f6b2dcd:After fix, captured from this PR at
82d34743da:Local validation:
Type
🐛 Bug Fix
✅ Test
Changes
OpenAI Responses usage reports cached prompt tokens under
usage.input_tokens_details.cached_tokens, and itsinput_tokensincludes those cached tokens. Anthropic Messages usage expects cache reads undercache_read_input_tokens, whileinput_tokensshould be the uncached input count.This PR adds one shared Responses usage -> Anthropic usage mapper and uses it in both affected Responses adapter return paths:
translate_responseresponse.completed->message_deltaIt also preserves Anthropic-style fallback semantics: when usage already provides
cache_read_input_tokensdirectly and no Responsesinput_tokens_details.cached_tokensis present, the mapper does not subtract cache reads frominput_tokensagain.Regression coverage added for:
input_tokens_details.cached_tokensinput_tokens_details.cached_tokens