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(tests): drop import-time completion call in test_register_model (#29521)

Mateo Wang3f33efdd5758
diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.py
index 5043d25ee37..c18f2216f61 100644
--- a/litellm/llms/openai/responses/transformation.py
+++ b/litellm/llms/openai/responses/transformation.py
@@ -299,11 +299,8 @@ class OpenAIResponsesAPIConfig(BaseResponsesAPIConfig):
or litellm.openai_key
or get_secret_str("OPENAI_API_KEY")
)
- headers.update(
- {
- "Authorization": f"Bearer {api_key}",
- }
- )
+ headers.setdefault("Content-Type", "application/json")
+ headers["Authorization"] = f"Bearer {api_key}"
return headers
def get_complete_url(
diff --git a/tests/local_testing/test_register_model.py b/tests/local_testing/test_register_model.py
index 635fd79abff..44fb440bbbd 100644
--- a/tests/local_testing/test_register_model.py
+++ b/tests/local_testing/test_register_model.py
@@ -1,8 +1,11 @@
#### What this tests ####
# This tests calling batch_completions by running 100 messages together
+import ast
import sys, os
import traceback
+from pathlib import Path
+
import pytest
sys.path.insert(
@@ -60,3 +63,24 @@ def test_update_model_cost_via_completion():
assert litellm.model_cost["gpt-3.5-turbo"]["output_cost_per_token"] == 0.4
except Exception as e:
pytest.fail(f"An error occurred: {e}")
+
+
+def test_no_test_invocation_at_module_scope():
+ tree = ast.parse(Path(__file__).read_text())
+ defined = {
+ node.name
+ for node in tree.body
+ if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
+ }
+ invoked = [
+ node.value.func.id
+ for node in tree.body
+ if isinstance(node, ast.Expr)
+ and isinstance(node.value, ast.Call)
+ and isinstance(node.value.func, ast.Name)
+ and node.value.func.id in defined
+ ]
+ assert not invoked, (
+ f"{invoked} run at import time, so pytest collecting this file fires real "
+ "provider calls; any failure aborts collection and tears down the whole job"
+ )
diff --git a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
index 4b2e9471fb7..d389b54b3f1 100644
--- a/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
+++ b/tests/test_litellm/llms/openai/responses/test_openai_responses_transformation.py
@@ -247,6 +247,7 @@ class TestOpenAIResponsesAPIConfig:
assert "Authorization" in result
assert result["Authorization"] == f"Bearer {api_key}"
+ assert result["Content-Type"] == "application/json"
# Test with empty headers
headers = {}