Litellm oss staging 02 26 2026 - #22166
Merged
Merged
Conversation
…#22106) * fix(proxy): honor MAX_STRING_LENGTH_PROMPT_IN_DB from config env vars * fix(proxy): reuse constants fallback for MAX_STRING_LENGTH_PROMPT_IN_DB runtime resolver * test(proxy): restore PEP8 spacing between spend tracking tests
…context (#22099) * fix(proxy): improve auth exception logging levels and add structured context Downgrade expected auth failures (ProxyException, HTTPException < 500, BudgetExceededError) from ERROR to WARNING log level to reduce noise from routine rejected requests (e.g. missing/invalid API keys on polled endpoints like /schedule/model_cost_map_reload/status). Unexpected exceptions and HTTPException with status >= 500 still log at ERROR with full traceback. Enrich log messages with structured context: route, HTTP method, masked API key (using existing abbreviate_api_key), error type, and error code. All fields also passed via log extra dict for log aggregation tools. Fixes #21293 * Update tests/test_litellm/proxy/auth/test_auth_exception_handler.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…ails for OpenAI/Azure (#22090) * fix(adapter): populate cache_read_input_tokens from prompt_tokens_details The Anthropic adapter's translate_openai_response_to_anthropic checked only the private _cache_read_input_tokens attr (set by Anthropic/DeepSeek) but not prompt_tokens_details.cached_tokens (set by OpenAI/Azure). Use prompt_tokens_details.cached_tokens directly — it is already extracted and is the standard field populated by all providers. Fixes #22089 * fix(adapter): apply same cache_read_input_tokens fix to streaming path The streaming path in translate_streaming_openai_response_to_anthropic had the same bug — relying on _cache_read_input_tokens instead of prompt_tokens_details.cached_tokens.
ghost
requested a review
from Sameerlite
February 26, 2026 08:59
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis staging PR bundles three independent fixes:
All three fixes include corresponding unit tests with no real network calls. Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py | Fix: populate cache_read_input_tokens from prompt_tokens_details.cached_tokens instead of _cache_read_input_tokens, fixing OpenAI/Azure cache token mapping in both sync and streaming paths. |
| litellm/proxy/auth/auth_exception_handler.py | Improved auth error logging: expected auth failures (ProxyException, HTTPException < 500, BudgetExceededError) log at WARNING level; unexpected errors log at ERROR with traceback. Adds structured context (route, method, masked key, error type, code). |
| litellm/proxy/spend_tracking/spend_tracking_utils.py | Adds runtime resolution of MAX_STRING_LENGTH_PROMPT_IN_DB via os.getenv() to honor values set after module import by proxy config environment_variables. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py | Adds test for cache token mapping from prompt_tokens_details.cached_tokens to cache_read_input_tokens in Anthropic adapter output. Mock-only, no network calls. |
| tests/test_litellm/proxy/auth/test_auth_exception_handler.py | Adds 4 tests covering: expected errors at WARNING level, unexpected at ERROR, structured log context verification, and None/empty API key handling. All mock-based. |
| tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py | Adds test for runtime env override of MAX_STRING_LENGTH_PROMPT_IN_DB using monkeypatch. Removes trailing blank line. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Auth Error Raised] --> B{Exception Type?}
B -->|ProxyException| C[Expected Auth Error]
B -->|BudgetExceededError| C
B -->|HTTPException < 500| C
B -->|HTTPException >= 500| D[Unexpected Error]
B -->|Other Exception| D
C --> E["Log at WARNING level\n(no traceback)"]
D --> F["Log at ERROR level\n(full traceback)"]
E --> G[Build structured context:\nroute, method, masked key,\nerror_type, error_code, IP]
F --> G
G --> H[Post-call failure hook]
H --> I[Raise ProxyException]
Last reviewed commit: 475bb94
Comment on lines
+117
to
+125
| "Auth failed: error_type={}, error_code={}, route={} {}, api_key={}, ip={} - {}".format( | ||
| error_type, | ||
| error_code, | ||
| http_method, | ||
| route, | ||
| masked_key, | ||
| requester_ip, | ||
| str(e), | ||
| ), |
Contributor
There was a problem hiding this comment.
Misleading log field label
The format string route={} {} places http_method as the first {} and route as the second, producing output like route=GET /chat/completions. The route= label is misleading since its value starts with the HTTP method rather than the actual route path. The same issue exists in the exception log on line 130.
Consider giving each value its own label (e.g., route={}, method={}) for clearer log parsing.
merge main
…uctured …" This reverts commit efeaf65.
…exception-logging Revert "fix(proxy): improve auth exception logging levels and add structured context"
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…26_2026 Litellm oss staging 02 26 2026
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
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes