fix(batches): only skip output fetch for all-error completed batches

Narrow the null output_file_id guard to batches that also have an
error_file_id, matching the OpenAI/Azure all-error completion shape and
avoiding zero-cost logging for other completed batches missing output URIs.
This commit is contained in:
Souravrajvi0 2026-07-21 05:24:03 +00:00
parent 6a7db09b01
commit e332ebed6e
2 changed files with 14 additions and 3 deletions

View file

@ -55,7 +55,7 @@ async def _handle_completed_batch(
litellm_params: Optional litellm parameters containing credentials (api_key, api_base, etc.)
"""
# All-error batches can complete with output_file_id=None and only an error_file_id.
if batch.output_file_id is None:
if batch.output_file_id is None and getattr(batch, "error_file_id", None) is not None:
return 0.0, Usage(), []
# Get batch results

View file

@ -600,7 +600,7 @@ async def test_calculate_batch_cost_and_usage_orchestration(monkeypatch):
# =========================================================================== #
def _batch(output_file_id):
def _batch(output_file_id, error_file_id=None):
from litellm.types.llms.openai import Batch
return Batch(
@ -612,6 +612,7 @@ def _batch(output_file_id):
object="batch",
status="completed",
output_file_id=output_file_id,
error_file_id=error_file_id,
)
@ -720,7 +721,10 @@ async def test_handle_completed_batch_all_error_batch_no_output_file(monkeypatch
monkeypatch.setattr(bu, "_get_batch_output_file_content_as_dictionary", fake_get_content)
cost, usage, models = await bu._handle_completed_batch(_batch(None), custom_llm_provider="openai")
cost, usage, models = await bu._handle_completed_batch(
_batch(None, error_file_id="file-err"),
custom_llm_provider="openai",
)
assert cost == 0.0
assert usage.total_tokens == 0
@ -730,6 +734,13 @@ async def test_handle_completed_batch_all_error_batch_no_output_file(monkeypatch
assert called is False
@pytest.mark.asyncio
async def test_handle_completed_batch_missing_output_without_error_file_still_raises():
"""Completed batches with no output and no error file keep the explicit fetch error."""
with pytest.raises(ValueError, match="Output file id is None"):
await bu._handle_completed_batch(_batch(None), custom_llm_provider="openai")
# =========================================================================== #
# Remaining branch: vertex usage disable-transform path.
#