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
Batch helpers like retrieve_batch_content() download the results of a completed batch by reading batch.output_file_id (via the Files API). If the batch object's output_file_id is None there is nothing to fetch — the batch has not produced output yet — so a ValueError is raised before any file request. OpenAI only populates output_file_id once the batch reaches a completed/ended state.
Solutions
- Poll litellm.get_batch() until status == 'completed' (or terminal) before retrieving content
- Check batch.output_file_id is truthy before calling retrieve_batch_content()
- For failed batches, inspect batch.errors / error file instead of output content
- Re-fetch a fresh batch object rather than reusing a stale one
Example fix
# before
content = await litellm.batches.retrieve_batch_content(
batch=batch, custom_llm_provider="openai"
)
# after
batch = await litellm.aget_batch(batch_id=batch.id, custom_llm_provider="openai")
if batch.status != "completed" or batch.output_file_id is None:
raise RuntimeError(f"Batch {batch.id} not ready (status={batch.status})")
content = await litellm.batches.retrieve_batch_content(
batch=batch, custom_llm_provider="openai"
)
Defensive patterns
Strategy: validation
Validate before calling
async def safe_retrieve_batch_content(batch, custom_llm_provider: str):
if batch.status != "completed":
raise RuntimeError(f"batch {batch.id} not completed (status={batch.status})")
if not batch.output_file_id:
raise RuntimeError(f"batch {batch.id} has no output_file_id")
return await litellm.batches.retrieve_batch_content(
batch=batch, custom_llm_provider=custom_llm_provider
)
Type guard
def batch_output_ready(batch) -> bool:
return getattr(batch, "status", "") == "completed" and bool(getattr(batch, "output_file_id", None))
Try / catch
try:
content = await litellm.batches.retrieve_batch_content(batch=batch, custom_llm_provider=p)
except ValueError as e:
if "Output file id is None" in str(e):
batch = await litellm.aget_batch(batch_id=batch.id, custom_llm_provider=p)
if batch.status == "completed" and batch.output_file_id:
content = await litellm.batches.retrieve_batch_content(batch=batch, custom_llm_provider=p)
else:
raise RuntimeError(f"batch {batch.id} not ready: {batch.status}") from e
else:
raise
Prevention
- Always gate content retrieval on status == 'completed' and a non-None output_file_id
- Poll with backoff and re-fetch the batch object each cycle instead of caching it
- Handle failed batches via the error file path, not the output path
When it happens
Trigger: Calling retrieve_batch_content() on a batch whose status is still in_progress, validating, or finalizing; fetching a batch that failed (errors_file_id may exist but output_file_id stays None); using a batch object from a stale cache captured before completion.
Common situations: Polling loops that jump to content retrieval before checking status; treating a failed batch as retrievable; caching batch objects and reading them later; races between the status endpoint flipping to completed and the object held in memory.
Related errors
- 400
- API base is required for OpenAI image variations
- API key is required for OpenAI image variations
- BedrockFilesConfig does not support file deletion
- BedrockFilesConfig does not support file listing
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/df009126d3a7bd73.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/batches/batch_utils.py:266
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 77b7c6c40c)