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
Add output file id in managed objects for batches
Sameer Kankute6a3f0a8baf47
diff --git a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.pyindex 32be1a780a3..dfb6c6514b8 100644--- a/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py+++ b/litellm/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py@@ -175,6 +175,8 @@ class AmazonAnthropicClaudeMessagesConfig(if beta_set:anthropic_messages_request["anthropic_beta"] = list(beta_set)++ print(f"🔥 [transform_anthropic_messages_request] anthropic_messages_request: {anthropic_messages_request}")return anthropic_messages_requestdiff --git a/tests/batches_tests/test_openai_batches_and_files.py b/tests/batches_tests/test_openai_batches_and_files.pyindex 2f4f9bbcda1..055af024949 100644--- a/tests/batches_tests/test_openai_batches_and_files.py+++ b/tests/batches_tests/test_openai_batches_and_files.py@@ -577,3 +577,73 @@ async def test_vertex_list_batches(monkeypatch):assert len(list_response["data"]) == 2assert list_response["data"][0].id == "test-batch-id-456"assert list_response["data"][1].id == "test-batch-id-789"+++async def test_delete_batch_output_file():+ """+ Test that deleting a batch output file works correctly.++ This test verifies the fix for:+ - When a batch is retrieved and has an output_file_id, the file object is properly stored+ - The output file can be deleted without validation errors+ - The file_object is fetched and stored with proper metadata instead of None+ """+ litellm._turn_on_debug()+ print("Testing delete batch output file")++ file_name = "openai_batch_completions.jsonl"+ _current_dir = os.path.dirname(os.path.abspath(__file__))+ file_path = os.path.join(_current_dir, file_name)++ # Create file for batch+ file_obj = await litellm.acreate_file(+ file=open(file_path, "rb"),+ purpose="batch",+ custom_llm_provider="openai",+ )+ print("Response from creating file=", file_obj)+ batch_input_file_id = file_obj.id++ # Create batch+ create_batch_response = await litellm.acreate_batch(+ completion_window="24h",+ endpoint="/v1/chat/completions",+ input_file_id=batch_input_file_id,+ custom_llm_provider="openai",+ )+ print("Batch created with ID=", create_batch_response.id)++ # Retrieve batch to get output_file_id+ retrieved_batch = await litellm.aretrieve_batch(+ batch_id=create_batch_response.id,+ custom_llm_provider="openai"+ )+ print("Retrieved batch=", retrieved_batch)++ # If batch has completed and has output file, test deleting it+ if retrieved_batch.output_file_id:+ print(f"Testing deletion of output file: {retrieved_batch.output_file_id}")++ # This is the key test - deleting the output file should work+ # without validation errors (file_object should not be None)+ delete_output_file_response = await litellm.afile_delete(+ file_id=retrieved_batch.output_file_id,+ custom_llm_provider="openai"+ )++ print("Delete output file response=", delete_output_file_response)+ assert delete_output_file_response.id == retrieved_batch.output_file_id+ assert delete_output_file_response.deleted is True or hasattr(delete_output_file_response, 'id')+ print("✓ Successfully deleted batch output file")+ else:+ print("⚠ Batch has not completed yet or no output file available, skipping output file deletion test")++ # Clean up - delete the input file+ delete_input_file_response = await litellm.afile_delete(+ file_id=batch_input_file_id,+ custom_llm_provider="openai"+ )+ print("Delete input file response=", delete_input_file_response)+ assert delete_input_file_response.id == batch_input_file_id+ print("✓ Successfully deleted batch input file")