BerriAI/litellm · error · ValueError

file_id is required in file_content_request

Error message

file_id is required in file_content_request

What it means

Raised by the Anthropic files handler when retrieving batch results content: file_content_request must contain a 'file_id' identifying the batch ('{batch_id}' or 'anthropic_batch_results:{batch_id}' are both accepted). The handler extracts it with .get() and rejects missing/empty values before building the results URL.

Source

Thrown at litellm/llms/anthropic/files/handler.py:77

        """
        Async: Retrieve file content from Anthropic.

        For batch results, the file_id should be the batch_id.
        This will call Anthropic's /v1/messages/batches/{batch_id}/results endpoint.

        Args:
            file_content_request: Contains file_id (batch_id for batch results)
            api_base: Anthropic API base URL
            api_key: Anthropic API key
            timeout: Request timeout
            max_retries: Max retry attempts (unused for now)

        Returns:
            HttpxBinaryResponseContent: Binary content wrapped in compatible response format
        """
        file_id: Final = file_content_request.get("file_id")
        if not file_id:
            raise ValueError("file_id is required in file_content_request")

        # Extract batch_id from file_id
        # Handle both formats: "anthropic_batch_results:{batch_id}" or just "{batch_id}"
        if file_id.startswith("anthropic_batch_results:"):
            batch_id = file_id.replace("anthropic_batch_results:", "", 1)
        else:
            batch_id = file_id

        # Get Anthropic API credentials
        api_base = self.anthropic_model_info.get_api_base(api_base)
        auth_header: Final = self.anthropic_model_info.get_auth_header(api_key, api_base)

        if auth_header is None:
            raise ValueError("Missing Anthropic API Key")

        # Construct the Anthropic batch results URL
        encoded_batch_id: Final = encode_url_path_segment(batch_id, field_name="batch_id")
        results_url: Final = f"{api_base.rstrip('/')}/v1/messages/batches/{encoded_batch_id}/results"

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass file_id in file_content_request, e.g. {'file_id': 'anthropic_batch_results:batch_01ABC'} or {'file_id': 'batch_01ABC'}.
  2. If you only have the batch id, put it directly in file_id — both prefixed and raw forms are handled.
  3. Check for typos: it is 'file_id', not 'batch_id' or 'id'.

Example fix

# before
content = handler.get_file_content(file_content_request={"batch_id": "batch_01ABC"})

# after
content = handler.get_file_content(file_content_request={"file_id": "batch_01ABC"})
Defensive patterns

Strategy: validation

Validate before calling

def make_file_content_request(file_id: str | None, batch_id: str | None = None) -> dict:
    fid = file_id or (f"anthropic_batch_results:{batch_id}" if batch_id else None)
    if not fid:
        raise ValueError("file_id or batch_id is required")
    return {"file_id": fid}

Type guard

def has_file_id(file_content_request: object) -> bool:
    return (
        isinstance(file_content_request, dict)
        and isinstance(file_content_request.get("file_id"), str)
        and bool(file_content_request["file_id"])
    )

Try / catch

try:
    content = handler.get_file_content(file_content_request=req)
except ValueError as e:
    if "file_id is required" in str(e):
        return http_error(400, "file_id is required")
    raise

Prevention

When it happens

Trigger: Calling the file-content endpoint for batch results with a file_content_request dict that lacks 'file_id' or has it empty — e.g. passing {'batch_id': '...'} instead of {'file_id': '...'}.

Common situations: Confusing the field name with the batch id parameter used elsewhere in the batches API; forwarding a partially-built request from a job runner; empty file_id after a failed upstream lookup.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/b1b47c05d41f74de. Report an issue: GitHub.