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]

test: improve debugging for test

Krrish Dholakia5c6dcd60295b
diff --git a/litellm/proxy/auth/auth_utils.py b/litellm/proxy/auth/auth_utils.py
index d1e1b170983..2f26ec65333 100644
--- a/litellm/proxy/auth/auth_utils.py
+++ b/litellm/proxy/auth/auth_utils.py
@@ -1,5 +1,6 @@
import re
import sys
+import traceback
from fastapi import Request
@@ -87,14 +88,16 @@ def get_request_route(request: Request) -> str:
remove base url from path if set e.g. `/genai/chat/completions` -> `/chat/completions
"""
try:
- if request.url.path.startswith(request.base_url.path):
+ if hasattr(request, "base_url") and request.url.path.startswith(
+ request.base_url.path
+ ):
# remove base_url from path
return request.url.path[len(request.base_url.path) - 1 :]
else:
return request.url.path
except Exception as e:
- verbose_proxy_logger.warning(
- f"error on get_request_route: {str(e)}, defaulting to request.url.path"
+ verbose_proxy_logger.debug(
+ f"error on get_request_route: {str(e)}, defaulting to request.url.path={request.url.path}"
)
return request.url.path
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.py
index 1192490422a..d8f41a9e722 100644
--- a/litellm/proxy/auth/user_api_key_auth.py
+++ b/litellm/proxy/auth/user_api_key_auth.py
@@ -532,6 +532,12 @@ async def user_api_key_auth(
api_key, str
): # if generated token, make sure it starts with sk-.
assert api_key.startswith("sk-") # prevent token hashes from being used
+ else:
+ verbose_logger.warning(
+ "litellm.proxy.proxy_server.user_api_key_auth(): Warning - Key={} is not a string.".format(
+ api_key
+ )
+ )
if (
prisma_client is None and custom_db_client is None
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index 923021efc24..cc59f6d58a6 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -1389,6 +1389,7 @@ class PrismaClient:
WHERE v.token = '{token}'
"""
+ print_verbose("sql_query being made={}".format(sql_query))
response = await self.db.query_first(query=sql_query)
if response is not None:
diff --git a/litellm/tests/test_key_generate_prisma.py b/litellm/tests/test_key_generate_prisma.py
index 53f6ab7f5c4..58bfb66b8df 100644
--- a/litellm/tests/test_key_generate_prisma.py
+++ b/litellm/tests/test_key_generate_prisma.py
@@ -303,6 +303,7 @@ def test_call_with_invalid_key(prisma_client):
def test_call_with_invalid_model(prisma_client):
+ litellm.set_verbose = True
# 3. Make a call to a key with an invalid model - expect to fail
setattr(litellm.proxy.proxy_server, "prisma_client", prisma_client)
setattr(litellm.proxy.proxy_server, "master_key", "sk-1234")
@@ -326,6 +327,11 @@ def test_call_with_invalid_model(prisma_client):
request.body = return_body
# use generated key to auth in
+ print(
+ "Bearer token being sent to user_api_key_auth() - {}".format(
+ bearer_token
+ )
+ )
result = await user_api_key_auth(request=request, api_key=bearer_token)
pytest.fail(f"This should have failed!. IT's an invalid model")