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: fix test

Krrish Dholakia01aa536716d1
diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml
index e22888f298a..83e71c55e1c 100644
--- a/litellm/proxy/_new_secret_config.yaml
+++ b/litellm/proxy/_new_secret_config.yaml
@@ -7,6 +7,11 @@ model_list:
model: azure/gpt-4o
api_key: os.environ/AZURE_API_KEY
api_base: os.environ/AZURE_API_BASE
-
+ - model_name: fake-openai-endpoint-5
+ litellm_params:
+ model: openai/my-fake-model
+ api_key: my-fake-key
+ api_base: https://exampleopenaiendpoint-production.up.railway.app/
+ timeout: 1
litellm_settings:
fallbacks: [{"gpt-3.5-turbo": ["gpt-4o"]}]
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index 6bf2ef90683..f37bbd7d093 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -1994,13 +1994,14 @@ class ProxyException(Exception):
message: str,
type: str,
param: Optional[str],
- code: Optional[Union[int, str]] = None,
+ code: Optional[Union[int, str]] = None, # maps to status code
headers: Optional[Dict[str, str]] = None,
+ openai_code: Optional[str] = None, # maps to 'code' in openai
):
self.message = str(message)
self.type = type
self.param = param
-
+ self.openai_code = openai_code or code
# If we look on official python OpenAI lib, the code should be a string:
# https://github.com/openai/openai-python/blob/195c05a64d39c87b2dfdf1eca2d339597f1fce03/src/openai/types/shared/error_object.py#L11
# Related LiteLLM issue: https://github.com/BerriAI/litellm/discussions/4834
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index 0dd3aabe988..a631ba963be 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -3716,7 +3716,8 @@ async def chat_completion( # noqa: PLR0915
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
headers=headers,
)
@@ -3929,7 +3930,8 @@ async def completion( # noqa: PLR0915
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
)
@@ -4138,7 +4140,8 @@ async def embeddings( # noqa: PLR0915
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
)
@@ -4257,7 +4260,8 @@ async def image_generation(
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
)
@@ -4518,7 +4522,8 @@ async def audio_transcriptions(
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
)
@@ -4667,7 +4672,8 @@ async def get_assistants(
message=getattr(e, "message", error_msg),
type=getattr(e, "type", "None"),
param=getattr(e, "param", "None"),
- code=getattr(e, "code", getattr(e, "status_code", 500)),
+ openai_code=getattr(e, "code", None),
+ code=getattr(e, "status_code", 500),
)
diff --git a/tests/test_fallbacks.py b/tests/test_fallbacks.py
index aab8e985bde..449778826b7 100644
--- a/tests/test_fallbacks.py
+++ b/tests/test_fallbacks.py
@@ -193,7 +193,7 @@ async def test_chat_completion_with_timeout():
start_time = time.time()
response, headers = await chat_completion(
session=session,
- key="sk-1234",
+ key="sk-PIp1h0RekR",
model=model,
messages=messages,
num_retries=0,