BerriAI/litellm · error · ValueError
Unsupported file content type
Error message
Unsupported file content type
What it means
After extraction, non-batch-JSONL file content must be bytes or str (bytes are utf-8 decoded; str passes through). Any other Python type — dict, list, int — hits this branch and is rejected before the S3 PUT is signed. Batch JSONL files take a separate path that reads and re-transforms the content, so they never reach this check.
Solutions
- Serialize before passing: json.dumps(obj) or keep the original bytes
- If you meant to upload an OpenAI batch file, set purpose="batch" so the JSONL transform path runs
- Type-check content with isinstance(content, (bytes, str)) before the call
Example fix
# before
payload = json.load(open("batch.jsonl"))
await client.files.create(file=("batch.jsonl", payload, "application/json"), purpose="batch")
# after
await client.files.create(file=("batch.jsonl", open("batch.jsonl", "rb"), "application/json"), purpose="batch") Defensive patterns
Strategy: type-guard
Validate before calling
def normalize_file_content(content):
if not isinstance(content, (bytes, str)):
content = json.dumps(content).encode("utf-8")
return content Type guard
def is_supported_file_content(content) -> bool:
return isinstance(content, (bytes, str)) Try / catch
try:
await client.files.create(file=(name, content, "application/json"), purpose="batch")
except ValueError as e:
if str(e) == "Unsupported file content type":
content = json.dumps(content).encode("utf-8")
await client.files.create(file=(name, content, "application/json"), purpose="batch")
else:
raise Prevention
- Keep payloads as raw bytes from disk rather than parsed objects
- For batch uploads always set purpose="batch" so the JSONL transform handles the content
- Add an isinstance check at your service boundary before calling files.create
When it happens
Trigger: files.create(file=("f.jsonl", {"records": [...]}, "application/json")) with purpose != "batch" so the JSONL branch is skipped; passing content as a list of parsed JSON objects instead of a serialized string; passing an int/float payload.
Common situations: Loading JSON with json.load and passing the resulting dict directly instead of the raw text/bytes; middleware that pre-parses file bodies; code that assumes LiteLLM serializes arbitrary objects.
Related errors
- BedrockFilesConfig does not support file deletion
- BedrockFilesConfig does not support file listing
- BedrockFilesConfig does not support file retrieval
- file_id is required for Bedrock file content retrieval
- raw_response.text
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/f10dc493971ad042.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/bedrock/files/transformation.py:953
if FilesAPIUtils.is_batch_jsonl_file(
create_file_data=create_file_data,
extracted_file_data=extracted_file_data,
):
## Transform JSONL content to Bedrock format
original_file_content: Final = self._get_content_from_openai_file(extracted_file_data_content)
openai_jsonl_content = [json.loads(line) for line in original_file_content.splitlines() if line.strip()]
litellm_params_model: Final = litellm_params.get("model")
target_model: Final = model or (litellm_params_model if isinstance(litellm_params_model, str) else "")
bedrock_jsonl_content = self._transform_openai_jsonl_content_to_bedrock_jsonl_content(
openai_jsonl_content, target_model=target_model
)
file_content = "\n".join(json.dumps(item) for item in bedrock_jsonl_content)
elif isinstance(extracted_file_data_content, bytes):
file_content = extracted_file_data_content.decode("utf-8")
elif isinstance(extracted_file_data_content, str):
file_content = extracted_file_data_content
else:
raise ValueError("Unsupported file content type")
# Get the S3 URL for upload
api_base: Final = self.get_complete_file_url(
api_base=None,
api_key=None,
model=model,
optional_params=optional_params,
litellm_params=litellm_params,
data=create_file_data,
)
# s3_region_name always wins for S3 operations (same priority as in
# get_complete_file_url above). Overwrite aws_region_name unconditionally,
# after the deployment-credential merge, so the SigV4 region matches the
# URL region, avoiding SignatureDoesNotMatch.
merged_params: Final = merge_bedrock_aws_request_params(litellm_params, optional_params)
s3_region_name: Final = litellm_params.get("s3_region_name") or optional_params.get("s3_region_name")
request_params: Final = (View on GitHub (pinned to 77b7c6c40c)