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 all 130126 tests

Sameer Kankuted03548b0642b
diff --git a/litellm/llms/bedrock/chat/invoke_handler.py b/litellm/llms/bedrock/chat/invoke_handler.py
index 49292545208..81ba717ab3f 100644
--- a/litellm/llms/bedrock/chat/invoke_handler.py
+++ b/litellm/llms/bedrock/chat/invoke_handler.py
@@ -1533,6 +1533,7 @@ class AWSEventStreamDecoder:
)
],
id=self.response_id,
+ model=self.model,
usage=usage,
provider_specific_fields=model_response_provider_specific_fields,
)
diff --git a/litellm/llms/bedrock/passthrough/transformation.py b/litellm/llms/bedrock/passthrough/transformation.py
index 71c418757bf..5efd3ba1d9f 100644
--- a/litellm/llms/bedrock/passthrough/transformation.py
+++ b/litellm/llms/bedrock/passthrough/transformation.py
@@ -236,6 +236,7 @@ class BedrockPassthroughConfig(
if len(all_translated_chunks) > 0:
model_response = stream_chunk_builder(
chunks=all_translated_chunks,
+ logging_obj=litellm_logging_obj,
)
return model_response
return None
diff --git a/litellm/llms/openai/chat/guardrail_translation/handler.py b/litellm/llms/openai/chat/guardrail_translation/handler.py
index e2cf9f46104..d0ed3f165cc 100644
--- a/litellm/llms/openai/chat/guardrail_translation/handler.py
+++ b/litellm/llms/openai/chat/guardrail_translation/handler.py
@@ -362,7 +362,7 @@ class OpenAIChatCompletionsHandler(BaseTranslation):
if has_stream_ended:
# convert to model response
model_response = cast(
- ModelResponse, stream_chunk_builder(chunks=responses_so_far)
+ ModelResponse, stream_chunk_builder(chunks=responses_so_far, logging_obj=litellm_logging_obj)
)
# run process_output_response
await self.process_output_response(
diff --git a/litellm/llms/watsonx/audio_transcription/transformation.py b/litellm/llms/watsonx/audio_transcription/transformation.py
index fd6ac61821e..397b5c932f1 100644
--- a/litellm/llms/watsonx/audio_transcription/transformation.py
+++ b/litellm/llms/watsonx/audio_transcription/transformation.py
@@ -98,16 +98,16 @@ class IBMWatsonXAudioTranscriptionConfig(
"""
# Use common utility to process the audio file
processed_audio = process_audio_file(audio_file)
-
- # Get API params to extract project_id or space_id
- api_params = _get_api_params(params=optional_params.copy(), model=model)
+ project_id = optional_params.get("project_id") or optional_params.get(
+ "watsonx_project"
+ )
+ space_id = optional_params.get("space_id")
+ api_params = _get_api_params(params=optional_params, model=model)
# Initialize form data with required fields
form_data: WatsonXAudioTranscriptionRequestBody = {"model": model}
- project_id = api_params.get("project_id")
- space_id = api_params.get("space_id")
-
+ # Only add project_id or space_id if they were explicitly provided by the user
if project_id:
form_data["project_id"] = project_id
elif space_id:
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index dd7f70750ca..a3254c32340 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -7094,8 +7094,8 @@ async def token_counter(request: TokenCountRequest, call_endpoint: bool = False)
f"Provider token counting failed ({result.status_code}): {result.error_message}. "
"Falling back to local tokenizer."
)
- else:
- # Success - return the result
+ elif result is not None:
+ # Success - return the result (only if not None)
return result
# Check if token counter is disabled before fallback
diff --git a/litellm/router.py b/litellm/router.py
index 3e5e8c9b8db..b77e3c9c299 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -1514,7 +1514,7 @@ class Router:
return FallbackStreamWrapper(stream_with_fallbacks())
- async def _acompletion(
+ async def _acompletion( # noqa: PLR0915
self, model: str, messages: List[Dict[str, str]], **kwargs
) -> Union[ModelResponse, CustomStreamWrapper,]:
"""
@@ -1699,13 +1699,13 @@ class Router:
per-deployment retry settings instead of the global setting.
"""
# Only set if exception doesn't already have num_retries
- if hasattr(exception, "num_retries") and exception.num_retries is not None:
+ if hasattr(exception, "num_retries") and exception.num_retries is not None: # type: ignore
return
litellm_params = deployment.get("litellm_params", {})
dep_num_retries = litellm_params.get("num_retries")
if dep_num_retries is not None and isinstance(dep_num_retries, int):
- exception.num_retries = dep_num_retries
+ exception.num_retries = dep_num_retries # type: ignore
def _update_kwargs_with_default_litellm_params(
self, kwargs: dict, metadata_variable_name: Optional[str] = "metadata"