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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
use _safe_get_request_query_params
Ishaan Jaff36d46e0ecfda
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex 70f9636adf5..fb70426bd52 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -256,6 +256,9 @@ def get_api_key(Tuple[Optional[str], Optional[str]]: Tuple of the api_key and the passed_in_key"""from litellm.proxy.auth.route_checks import RouteChecks+ from litellm.proxy.common_utils.http_parsing_utils import (+ _safe_get_request_query_params,+ )api_key = api_keypassed_in_key: Optional[str] = Noneif isinstance(custom_litellm_key_header, str):@@ -276,8 +279,8 @@ def get_api_key(elif isinstance(azure_apim_header, str):passed_in_key = azure_apim_headerapi_key = azure_apim_header- elif RouteChecks.is_generate_content_route(route=route) and request is not None and request.query_params.get("key"):- google_auth_key: str = request.query_params.get("key") or ""+ elif RouteChecks.is_generate_content_route(route=route) and request is not None and _safe_get_request_query_params(request).get("key"):+ google_auth_key: str = _safe_get_request_query_params(request).get("key") or ""passed_in_key = google_auth_keyapi_key = google_auth_keyelif pass_through_endpoints is not None:diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.pyindex 875d69437cb..ee12f8814e6 100644--- a/litellm/proxy/common_utils/http_parsing_utils.py+++ b/litellm/proxy/common_utils/http_parsing_utils.py@@ -102,6 +102,18 @@ def _safe_get_request_parsed_body(request: Optional[Request]) -> Optional[dict]:return {key: parsed_body[key] for key in accepted_keys}return None+def _safe_get_request_query_params(request: Optional[Request]) -> Dict:+ if request is None:+ return {}+ try:+ if hasattr(request, "query_params"):+ return dict(request.query_params)+ return {}+ except Exception as e:+ verbose_proxy_logger.debug(+ "Unexpected error reading request query params - {}".format(e)+ )+ return {}def _safe_set_request_parsed_body(request: Optional[Request],