Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

FIx test_read_request*

Sameer Kankutef8e0b377691a
diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py
index 8d179a9caed..04d46ecaeb8 100644
--- a/litellm/proxy/common_utils/http_parsing_utils.py
+++ b/litellm/proxy/common_utils/http_parsing_utils.py
@@ -143,7 +143,8 @@ def _safe_get_request_headers(request: Optional[Request]) -> dict:
"""
if request is None:
return {}
- cached = getattr(request.state, "_cached_headers", None)
+ state = getattr(request, "state", None)
+ cached = getattr(state, "_cached_headers", None)
if cached is not None:
return cached
try:
@@ -154,7 +155,8 @@ def _safe_get_request_headers(request: Optional[Request]) -> dict:
)
headers = {}
try:
- request.state._cached_headers = headers
+ if state is not None:
+ state._cached_headers = headers
except Exception:
pass # request.state may not be available in all contexts
return headers