BerriAI/litellm · error · ValueError

file_id must be a URI

Error message

file_id must be a {scheme} URI

What it means

Guard in validate_managed_cloud_file_id: after URL-decoding, the file_id does not start with the expected scheme prefix (e.g. 's3://'), so it is not a managed cloud file URI of the configured storage type.

Solutions

  1. Use a file_id URI with the expected scheme (e.g. gs:// or s3:// as configured).
  2. Check the file_id format returned by the files API and pass it unchanged.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/litellm_core_utils/cloud_storage_security.py:143 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/be35e62e7c6ab2fe. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/cloud_storage_security.py:143

            value = cast(Mapping[str, Any], trusted_model_credentials).get("allow_legacy_cloud_file_ids")

    if isinstance(value, bool):
        return value
    if isinstance(value, str):
        return value.strip().lower() in {"1", "true", "yes", "on"}
    return False


def validate_managed_cloud_file_id(
    file_id: str,
    scheme: str,
    configured_bucket_name: str,
    allowed_object_prefixes: Sequence[str],
    allow_legacy_cloud_file_ids: bool = False,
) -> tuple[str, str]:
    decoded_file_id: Final = unquote(file_id)
    if not decoded_file_id.startswith(scheme):
        raise ValueError(f"file_id must be a {scheme} URI")

    full_path: Final = decoded_file_id[len(scheme) :]
    if "/" not in full_path:
        raise ValueError("file_id must include a cloud storage object name")

    bucket_name, object_name = full_path.split("/", 1)
    configured_bucket, configured_prefix = split_configured_cloud_bucket_name(configured_bucket_name)
    if bucket_name != configured_bucket:
        raise ValueError("file_id bucket does not match the configured storage bucket")

    _validate_cloud_object_path(object_name)
    allowed_prefixes = tuple(allowed_object_prefixes)
    if configured_prefix:
        allowed_prefixes = tuple(f"{configured_prefix.rstrip('/')}/{prefix}" for prefix in allowed_prefixes)

    if object_name.startswith(allowed_prefixes):
        return bucket_name, object_name

View on GitHub (pinned to 77b7c6c40c)