{"record":{"id":"f10dc493971ad042","repo":"BerriAI/litellm","slug":"unsupported-file-content-type","errorCode":null,"errorMessage":"Unsupported file content type","messagePattern":"Unsupported file content type","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/files/transformation.py","lineNumber":953,"sourceCode":"        if FilesAPIUtils.is_batch_jsonl_file(\n            create_file_data=create_file_data,\n            extracted_file_data=extracted_file_data,\n        ):\n            ## Transform JSONL content to Bedrock format\n            original_file_content: Final = self._get_content_from_openai_file(extracted_file_data_content)\n            openai_jsonl_content = [json.loads(line) for line in original_file_content.splitlines() if line.strip()]\n            litellm_params_model: Final = litellm_params.get(\"model\")\n            target_model: Final = model or (litellm_params_model if isinstance(litellm_params_model, str) else \"\")\n            bedrock_jsonl_content = self._transform_openai_jsonl_content_to_bedrock_jsonl_content(\n                openai_jsonl_content, target_model=target_model\n            )\n            file_content = \"\\n\".join(json.dumps(item) for item in bedrock_jsonl_content)\n        elif isinstance(extracted_file_data_content, bytes):\n            file_content = extracted_file_data_content.decode(\"utf-8\")\n        elif isinstance(extracted_file_data_content, str):\n            file_content = extracted_file_data_content\n        else:\n            raise ValueError(\"Unsupported file content type\")\n\n        # Get the S3 URL for upload\n        api_base: Final = self.get_complete_file_url(\n            api_base=None,\n            api_key=None,\n            model=model,\n            optional_params=optional_params,\n            litellm_params=litellm_params,\n            data=create_file_data,\n        )\n\n        # s3_region_name always wins for S3 operations (same priority as in\n        # get_complete_file_url above). Overwrite aws_region_name unconditionally,\n        # after the deployment-credential merge, so the SigV4 region matches the\n        # URL region, avoiding SignatureDoesNotMatch.\n        merged_params: Final = merge_bedrock_aws_request_params(litellm_params, optional_params)\n        s3_region_name: Final = litellm_params.get(\"s3_region_name\") or optional_params.get(\"s3_region_name\")\n        request_params: Final = (","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/bedrock/files/transformation.py#L935-L971","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\npayload = json.load(open(\"batch.jsonl\"))\nawait client.files.create(file=(\"batch.jsonl\", payload, \"application/json\"), purpose=\"batch\")\n\n# after\nawait client.files.create(file=(\"batch.jsonl\", open(\"batch.jsonl\", \"rb\"), \"application/json\"), purpose=\"batch\")","handlingStrategy":"type-guard","validationCode":"def normalize_file_content(content):\n    if not isinstance(content, (bytes, str)):\n        content = json.dumps(content).encode(\"utf-8\")\n    return content","typeGuard":"def is_supported_file_content(content) -> bool:\n    return isinstance(content, (bytes, str))","tryCatchPattern":"try:\n    await client.files.create(file=(name, content, \"application/json\"), purpose=\"batch\")\nexcept ValueError as e:\n    if str(e) == \"Unsupported file content type\":\n        content = json.dumps(content).encode(\"utf-8\")\n        await client.files.create(file=(name, content, \"application/json\"), purpose=\"batch\")\n    else:\n        raise","preventionTips":["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"],"tags":["bedrock","files-api","file-upload","type-error","litellm"],"backgroundTag":"unsupported-content-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}