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(litellm_pre_call_utils.py): handle no query params in request

Krrish Dholakiaa85a932e2502
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py
index 5dd58466b9f..8d2c728f592 100644
--- a/litellm/proxy/auth/user_api_key_auth.py
+++ b/litellm/proxy/auth/user_api_key_auth.py
@@ -1275,6 +1275,8 @@ def _get_request_ip_address(
client_ip = request.headers["x-forwarded-for"]
elif request.client is not None:
client_ip = request.client.host
+ else:
+ client_ip = ""
return client_ip
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py
index fddfcfc8da8..ff5b6dc86cd 100644
--- a/litellm/proxy/litellm_pre_call_utils.py
+++ b/litellm/proxy/litellm_pre_call_utils.py
@@ -171,10 +171,12 @@ async def add_litellm_data_to_request(
}
## Dynamic api version (Azure OpenAI endpoints) ##
- query_params = request.query_params
-
- # Convert query parameters to a dictionary (optional)
- query_dict = dict(query_params)
+ try:
+ query_params = request.query_params
+ # Convert query parameters to a dictionary (optional)
+ query_dict = dict(query_params)
+ except KeyError:
+ query_dict = {}
## check for api version in query params
dynamic_api_version: Optional[str] = query_dict.get("api-version")