BerriAI/litellm · error · ValueError
file is required
Error message
file is required
What it means
The Bedrock create-file handler requires the multipart 'file' field; data.get('file') returned None, so there are no bytes to extract, name, and PUT to S3. This guard runs before purpose validation.
Source
Thrown at litellm/llms/bedrock/files/transformation.py:345
) -> str:
"""
Get the complete S3 URL for the file upload request
"""
request_params: Final = merge_bedrock_aws_request_params(litellm_params, optional_params)
bucket_name = litellm_params.get("s3_bucket_name") or os.getenv("AWS_S3_BUCKET_NAME")
if not bucket_name:
raise ValueError(
"S3 bucket_name is required. Set 's3_bucket_name' in litellm_params or AWS_S3_BUCKET_NAME env var"
)
bucket_name, object_prefix = split_configured_cloud_bucket_name(bucket_name)
s3_region_name: Final = litellm_params.get("s3_region_name") or optional_params.get("s3_region_name")
aws_region_name: Final = s3_region_name or self._get_aws_region_name(request_params, model)
file_data: Final = data.get("file")
purpose: Final = data.get("purpose")
if file_data is None:
raise ValueError("file is required")
if purpose is None:
raise ValueError("purpose is required")
extracted_file_data: Final = extract_file_data(file_data)
object_name = self.get_object_name(extracted_file_data, purpose)
if object_prefix:
object_name = f"{object_prefix}/{object_name}"
encoded_object_name: Final = encode_s3_object_key_for_url(object_name)
# S3 endpoint URL format
s3_endpoint_url: Final = (
request_params.get("s3_endpoint_url") or f"https://s3.{aws_region_name}.amazonaws.com"
).rstrip("/")
return f"{s3_endpoint_url}/{bucket_name}/{encoded_object_name}"
def get_supported_openai_params(self, model: str) -> list[OpenAICreateFileRequestOptionalParams]:
return []
View on GitHub (pinned to 6c2dcb801b)
Solutions
- Send the request as multipart/form-data with a part named exactly 'file'.
- Verify with curl: curl -F file=@batch.jsonl -F purpose=batch .../v1/files.
- Fix client SDK form construction to include the file part.
Example fix
# before (no file part)
requests.post(url, json={"purpose": "batch"})
# after
requests.post(url, files={"file": open("batch.jsonl", "rb")}, data={"purpose": "batch"}) Defensive patterns
Strategy: validation
Validate before calling
assert data.get("file") is not None, "multipart field 'file' is required" Try / catch
try:
resp = litellm.create_file(file=f, purpose="batch")
except ValueError as e:
if "file is required" in str(e):
return HTTP 400 # client must send multipart
raise Prevention
- Always POST files as multipart/form-data with field name 'file'.
- Add request-schema validation at the API gateway for upload endpoints.
When it happens
Trigger: POSTing a files request without the multipart file part — malformed form data, wrong field name ('file' vs 'fileUpload'), or a JSON body where a file cannot be represented.
Common situations: Client sends JSON instead of multipart/form-data; field name mismatch between client SDK and litellm's expected 'file'; proxies stripping multipart parts; tests posting metadata only.
Related errors
- file content is required
- purpose is required
- File data is required
- file_id is required in file_content_request
- file_id must be a managed LiteLLM S3 file id
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/7875f18464e7f838.
Report an issue: GitHub.