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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix test_chat_completion
Sameer Kankute791cef6d993a
diff --git a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.pyindex b28b4497e7c..bf8bc46f723 100644--- a/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py+++ b/enterprise/litellm_enterprise/proxy/common_utils/check_batch_cost.py@@ -124,8 +124,16 @@ class CheckBatchCost:**credentials,)+ # Access content - handle both direct attribute and method call+ if hasattr(_file_content, 'content'):+ content_bytes = _file_content.content+ elif hasattr(_file_content, 'read'):+ content_bytes = await _file_content.read()+ else:+ content_bytes = _file_content+file_content_as_dict = _get_file_content_as_dictionary(- _file_content.content+ content_bytes)deployment_info = self.llm_router.get_deployment(model_id=model_id)diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py b/enterprise/litellm_enterprise/proxy/hooks/managed_files.pyindex f341a1e9634..b1cbeecd1ec 100644--- a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py+++ b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py@@ -920,7 +920,9 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints):# Azure and other auth-required providers return 500/401.file_object = Nonetry:- from litellm.proxy.proxy_server import llm_router as _llm_router+ # Import module and use getattr for better testability with mocks+ import litellm.proxy.proxy_server as proxy_server_module+ _llm_router = getattr(proxy_server_module, 'llm_router', None)if _llm_router is not None and model_id:_creds = _llm_router.get_deployment_credentials_with_provider(model_id) or {}file_object = await litellm.afile_retrieve(@@ -1019,8 +1021,9 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints):# The stored file_object has the raw provider ID. Replace with the unified ID# so callers see a consistent ID (matching Case 3 which does response.id = file_id).if stored_file_object and stored_file_object.file_object:- stored_file_object.file_object.id = file_id- return stored_file_object.file_object+ # Use model_copy to ensure the ID update persists (Pydantic v2 compatibility)+ response = stored_file_object.file_object.model_copy(update={"id": file_id})+ return response# Case 3: Managed file exists in the database but not the file object (for. e.g the batch task might not have run)# So we fetch the file object from the provider. We deliberately do not store the result to avoid interfering with batch cost tracking code.diff --git a/tests/proxy_unit_tests/test_proxy_custom_logger.py b/tests/proxy_unit_tests/test_proxy_custom_logger.pyindex 909799a05ca..bdd8eb4cc67 100644--- a/tests/proxy_unit_tests/test_proxy_custom_logger.py+++ b/tests/proxy_unit_tests/test_proxy_custom_logger.py@@ -48,6 +48,10 @@ headers = {"Authorization": f"Bearer {token}"}print("Testing proxy custom logger")+ os.environ.get("OPENAI_API_KEY") is None,+ reason="OPENAI_API_KEY not set - skipping integration test"+)def test_embedding(client):try:litellm.set_verbose = False@@ -118,6 +122,10 @@ def test_embedding(client):pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")+ os.environ.get("OPENAI_API_KEY") is None,+ reason="OPENAI_API_KEY not set - skipping integration test"+)def test_chat_completion(client):try:# Your test data@@ -208,6 +216,10 @@ def test_chat_completion(client):pytest.fail(f"LiteLLM Proxy test failed. Exception {str(e)}")+ os.environ.get("OPENAI_API_KEY") is None,+ reason="OPENAI_API_KEY not set - skipping integration test"+)def test_chat_completion_stream(client):try:# Your test datadiff --git a/tests/proxy_unit_tests/test_proxy_pass_user_config.py b/tests/proxy_unit_tests/test_proxy_pass_user_config.pyindex 1a74c71ff35..4828014e335 100644--- a/tests/proxy_unit_tests/test_proxy_pass_user_config.py+++ b/tests/proxy_unit_tests/test_proxy_pass_user_config.py@@ -53,6 +53,10 @@ def client_no_auth():return TestClient(app)+ os.environ.get("AZURE_API_KEY") is None or os.environ.get("OPENAI_API_KEY") is None,+ reason="AZURE_API_KEY or OPENAI_API_KEY not set - skipping integration test"+)def test_chat_completion(client_no_auth):global headers