mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
Merge 714f9955a7 into bb72815e70
This commit is contained in:
commit
f65a38ceb7
2 changed files with 27 additions and 1 deletions
|
|
@ -1,5 +1,12 @@
|
|||
from typing import Final
|
||||
|
||||
_PROVIDER_HEADERS_TO_PASSTHROUGH: Final = frozenset(
|
||||
{
|
||||
"anthropic-ratelimit-unified-status",
|
||||
"retry-after",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_response_headers(_response_headers: dict | None = None) -> dict:
|
||||
"""
|
||||
|
|
@ -28,7 +35,10 @@ def get_response_headers(_response_headers: dict | None = None) -> dict:
|
|||
if "x-ratelimit-remaining-tokens" in _response_headers:
|
||||
openai_headers["x-ratelimit-remaining-tokens"] = _response_headers["x-ratelimit-remaining-tokens"]
|
||||
llm_provider_headers: Final = _get_llm_provider_headers(_response_headers)
|
||||
return {**llm_provider_headers, **openai_headers}
|
||||
passthrough_headers: Final = {
|
||||
key: value for key, value in _response_headers.items() if key.lower() in _PROVIDER_HEADERS_TO_PASSTHROUGH
|
||||
}
|
||||
return {**llm_provider_headers, **openai_headers, **passthrough_headers}
|
||||
|
||||
|
||||
def _get_llm_provider_headers(response_headers: dict) -> dict:
|
||||
|
|
|
|||
|
|
@ -278,6 +278,22 @@ class TestProxyHeaderExtraction:
|
|||
assert result.get("llm_provider-x-request-id") == "req-abc123"
|
||||
assert result.get("llm_provider-x-ms-region") == "eastus"
|
||||
|
||||
def test_get_response_headers_preserves_anthropic_rate_limit_headers(self):
|
||||
"""Anthropic-compatible clients need these headers on the downstream 429."""
|
||||
from litellm.litellm_core_utils.llm_response_utils.get_headers import (
|
||||
get_response_headers,
|
||||
)
|
||||
|
||||
result = get_response_headers(
|
||||
{
|
||||
"Anthropic-RateLimit-Unified-Status": "rejected",
|
||||
"Retry-After": "287441",
|
||||
}
|
||||
)
|
||||
|
||||
assert result["Anthropic-RateLimit-Unified-Status"] == "rejected"
|
||||
assert result["Retry-After"] == "287441"
|
||||
|
||||
def test_proxy_can_extract_headers_from_exception_response(self):
|
||||
"""Simulate how proxy extracts headers from exception.response.headers."""
|
||||
from litellm.litellm_core_utils.llm_response_utils.get_headers import (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue