BerriAI/litellm · error · HTTPException

expires_after[anchor] must be a string, not a file upload

Error message

expires_after[anchor] must be a string, not a file upload

What it means

HTTPException(400) on file upload: expires_after[anchor] was submitted as a file upload part instead of a string form value (client misused multipart, attaching a file where a scalar was expected). The field must be a plain text form entry.

Source

Thrown at litellm/proxy/openai_files_endpoints/files_endpoints.py:403

        expires_after_anchor: Final = form_data_raw.get("expires_after[anchor]")
        expires_after_seconds_str: Final = form_data_raw.get("expires_after[seconds]")

        # Add litellm_metadata to data if provided (from form field)
        if extracted_litellm_metadata is not None:
            data["litellm_metadata"] = extracted_litellm_metadata

        if expires_after_anchor is not None or expires_after_seconds_str is not None:
            if expires_after_anchor is None or expires_after_seconds_str is None:
                raise HTTPException(
                    status_code=400,
                    detail={
                        "error": "Both expires_after[anchor] and expires_after[seconds] must be provided if expires_after is specified",
                    },
                )

            # Validate expires_after[anchor] is a string (not UploadFile)
            if isinstance(expires_after_anchor, UploadFile):
                raise HTTPException(
                    status_code=400,
                    detail={
                        "error": "expires_after[anchor] must be a string, not a file upload",
                    },
                )

            # Validate expires_after[seconds] is a string (not UploadFile)
            # Use positive isinstance check for proper type narrowing (matches codebase pattern)
            if not isinstance(expires_after_seconds_str, str):
                raise HTTPException(
                    status_code=400,
                    detail={
                        "error": "expires_after[seconds] must be a string, not a file upload",
                    },
                )
            # After this check, mypy knows expires_after_seconds_str is str
            expires_after_seconds_str_validated: Final[str] = expires_after_seconds_str

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Send expires_after[anchor] as a string form field, not a file upload.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at litellm/proxy/openai_files_endpoints/files_endpoints.py:403 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/128954de9a3dca00. Report an issue: GitHub.