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_completion_mistral_api_mistral_large_function_call

Ishaan Jaffef9177f0a87e
diff --git a/litellm/litellm_core_utils/llm_request_utils.py b/litellm/litellm_core_utils/llm_request_utils.py
index 50dbdc5536e..b322d598caa 100644
--- a/litellm/litellm_core_utils/llm_request_utils.py
+++ b/litellm/litellm_core_utils/llm_request_utils.py
@@ -27,6 +27,10 @@ def _ensure_extra_body_is_safe(extra_body: Optional[Dict]) -> Optional[Dict]:
if _prompt is not None and hasattr(_prompt, "__dict__"):
extra_body["metadata"]["prompt"] = _prompt.__dict__
+ if len(extra_body) == 0:
+ # don't send empty extra_body, providers like mistral will throw an error
+ return None
+
return extra_body
diff --git a/litellm/utils.py b/litellm/utils.py
index 3893f947ec6..12192fc8db4 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -3470,6 +3470,10 @@ def get_optional_params( # noqa: PLR0915
optional_params["extra_body"] = _ensure_extra_body_is_safe(
extra_body=optional_params["extra_body"]
)
+
+ if optional_params["extra_body"] is None:
+ # don't pass extra_body if it's empty/None
+ optional_params.pop("extra_body", None)
else:
# if user passed in non-default kwargs for specific providers/models, pass them along
for k in passed_params.keys():
diff --git a/tests/local_testing/test_completion.py b/tests/local_testing/test_completion.py
index 8a6ccafc9c4..24a43c01837 100644
--- a/tests/local_testing/test_completion.py
+++ b/tests/local_testing/test_completion.py
@@ -16,7 +16,7 @@ sys.path.insert(
import os
from unittest.mock import AsyncMock, MagicMock, patch
-
+from litellm._logging import verbose_logger
import pytest
import litellm
@@ -976,6 +976,10 @@ async def test_completion_codestral_chat_api():
def test_completion_mistral_api_mistral_large_function_call():
litellm.set_verbose = True
+ import logging
+
+ logging.basicConfig(level=logging.DEBUG)
+ verbose_logger.setLevel(logging.DEBUG)
tools = [
{
"type": "function",