{"record":{"id":"7a59217279f5b86d","repo":"openai/openai-python","slug":"passing-both-body-and-content-is-not-supported","errorCode":null,"errorMessage":"Passing both `body` and `content` is not supported","messagePattern":"Passing both `body` and `content` is not supported","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/_base_client.py","lineNumber":1355,"sourceCode":"        files: RequestFiles | None = None,\n        stream: bool,\n        stream_cls: type[_StreamT] | None = None,\n    ) -> ResponseT | _StreamT: ...\n\n    def post(\n        self,\n        path: str,\n        *,\n        cast_to: Type[ResponseT],\n        body: Body | None = None,\n        content: BinaryTypes | None = None,\n        options: RequestOptions = {},\n        files: RequestFiles | None = None,\n        stream: bool = False,\n        stream_cls: type[_StreamT] | None = None,\n    ) -> ResponseT | _StreamT:\n        if body is not None and content is not None:\n            raise TypeError(\"Passing both `body` and `content` is not supported\")\n        if files is not None and content is not None:\n            raise TypeError(\"Passing both `files` and `content` is not supported\")\n        if isinstance(body, bytes):\n            warnings.warn(\n                \"Passing raw bytes as `body` is deprecated and will be removed in a future version. \"\n                \"Please pass raw bytes via the `content` parameter instead.\",\n                DeprecationWarning,\n                stacklevel=2,\n            )\n        opts = FinalRequestOptions.construct(\n            method=\"post\", url=path, json_data=body, content=content, files=to_httpx_files(files), **options\n        )\n        return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))\n\n    def patch(\n        self,\n        path: str,\n        *,","sourceCodeStart":1337,"sourceCodeEnd":1373,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_base_client.py#L1337-L1373","documentation":"Same guard as the sync variant, but in async upload_file_chunked: when `file` is raw bytes and `filename` is None, the SDK cannot name the multipart part and raises TypeError before creating the upload session. anyio.Path inputs get their .name inferred; bytes do not.","triggerScenarios":"Awaiting client.uploads.upload_file_chunked(b'...', purpose='assistants') without filename=; passing bytes from memory in async code.","commonSituations":"Async pipelines generating documents/images in memory, or porting sync path-based code to async without adding the filename argument.","solutions":["Pass filename explicitly for bytes input","Or pass a (anyio) Path so the name is inferred","Use a meaningful extension matching the content type"],"exampleFix":"# before\nawait client.uploads.upload_file_chunked(img_bytes, purpose='assistants')\n# after\nawait client.uploads.upload_file_chunked(img_bytes, purpose='assistants', filename='chart.png')","handlingStrategy":"type-guard","validationCode":"if isinstance(data, bytes) and not filename:\n    raise ValueError('filename is required for in-memory uploads')\nawait client.uploads.upload_file_chunked(data, purpose='assistants', filename=filename)","typeGuard":"def needs_filename(file: object) -> bool:\n    return isinstance(file, (bytes, bytearray))","tryCatchPattern":null,"preventionTips":["Default filename from your pipeline (e.g. f'{doc_id}.pdf') for bytes payloads","Prefer Path inputs when the file exists on disk","Cover bytes uploads in a unit test to catch missing filename early"],"tags":["openai","uploads","async","multipart","filename","typeerror","in-memory"],"backgroundTag":"missing-filename-in-memory-upload","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}