BerriAI/litellm · error · ValueError
Output file id is None cannot retrieve file content
Error message
Output file id is None cannot retrieve file content
What it means
ValueError raised by the batches utility that retrieves a batch's output file content when batch.output_file_id is None. OpenAI only populates output_file_id once a batch reaches a terminal state with results; if you try to fetch results before the batch has completed (or for a failed/expired batch), there is no output file to retrieve and LiteLLM fails fast.
Source
Thrown at litellm/batches/batch_utils.py:254
custom_llm_provider: Literal["openai", "azure", "vertex_ai", "hosted_vllm", "anthropic"] = "openai",
litellm_params: dict | None = None,
) -> bytes:
"""
Fetch the batch output file and return its raw JSONL bytes
Args:
batch: The batch object
custom_llm_provider: The LLM provider
litellm_params: Optional litellm parameters containing credentials (api_key, api_base, etc.)
Required for Azure and other providers that need authentication
"""
from litellm.files.main import afile_content
from litellm.proxy.openai_files_endpoints.common_utils import (
_is_base64_encoded_unified_file_id,
)
if batch.output_file_id is None:
raise ValueError("Output file id is None cannot retrieve file content")
file_id = batch.output_file_id
is_base64_unified_file_id: Final = _is_base64_encoded_unified_file_id(file_id)
if is_base64_unified_file_id:
try:
file_id = is_base64_unified_file_id.split("llm_output_file_id,")[1].split(";")[0]
verbose_logger.debug("Extracted LLM output file ID from unified file ID: %s", file_id)
except (IndexError, AttributeError) as e:
verbose_logger.error(
"Failed to extract LLM output file ID from unified file ID: %s, error: %s", batch.output_file_id, e
)
# Build kwargs for afile_content with credentials from litellm_params
file_content_kwargs: Final = {
"file_id": file_id,
"custom_llm_provider": custom_llm_provider,
}
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Poll until batch.status == 'completed' before retrieving output content.
- If the batch failed or was cancelled, read batch.error_file_id / errors instead — output_file_id stays None.
- Guard the call: if batch.output_file_id is None: skip/handle.
Example fix
# before
content = await afile_content(batch.output_file_id, ...)
# after
if batch.output_file_id is None:
raise RuntimeError(f"Batch {batch.id} not completed (status={batch.status}); no output file yet")
content = await afile_content(batch.output_file_id, ...) Defensive patterns
Strategy: validation
Validate before calling
if batch.output_file_id is None:
raise RuntimeError(f"Batch {batch.id} status={batch.status}: no output file available") Type guard
def batch_has_output(batch) -> bool:
return getattr(batch, "output_file_id", None) is not None Try / catch
try:
content = await afile_content(batch.output_file_id, ...)
except ValueError as e:
if "Output file id is None" in str(e):
logger.warning("batch %s not ready (status=%s)", batch.id, batch.status)
content = None
else:
raise Prevention
- Gate output retrieval on batch.status == 'completed'.
- For failed batches, use error_file_id instead.
- Build polling helpers with max attempts and backoff rather than fire-and-forget fetches.
When it happens
Trigger: Calling litellm.get_batch_output_file_content (or afile_content-based retrieval) on a batch object whose output_file_id is None — typically a batch still in 'in_progress'/'validating'/'finalizing', or one that failed/cancelled/expired without producing output.
Common situations: Polling code that checks batch.status != 'completed' incorrectly and fetches too early; a failed batch (check errors_file_id instead); provider responses that omit output_file_id even on completion.
Related errors
- Unclassified keys in {PRICES_PATH.name}: {', '.join(unclassi
- No Braintrust API token provided. Pass via Authorization hea
- Braintrust API error: {e.response.text}
- Failed to connect to Braintrust API: {str(e)}
- Failed to parse Braintrust API response: {str(e)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/df009126d3a7bd73.
Report an issue: GitHub.