{"record":{"id":"c8da74868cb0cd7e","repo":"openai/openai-python","slug":"passing-raw-bytes-as-body-is-deprecated-and-will","errorCode":null,"errorMessage":"Passing raw bytes as `body` is deprecated and will be removed in a future version. Please pass raw bytes via the `content` parameter instead.","messagePattern":"Passing raw bytes as `body` is deprecated and will be removed in a future version\\. Please pass raw bytes via the `content` parameter instead\\.","errorType":"console","errorClass":"DeprecationWarning","httpStatus":null,"severity":"warning","filePath":"src/openai/_base_client.py","lineNumber":1411,"sourceCode":"        )\n        return self.request(cast_to, opts)\n\n    def put(\n        self,\n        path: str,\n        *,\n        cast_to: Type[ResponseT],\n        body: Body | None = None,\n        content: BinaryTypes | None = None,\n        files: RequestFiles | None = None,\n        options: RequestOptions = {},\n    ) -> ResponseT:\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=\"put\", url=path, json_data=body, content=content, files=to_httpx_files(files), **options\n        )\n        return self.request(cast_to, opts)\n\n    def delete(\n        self,\n        path: str,\n        *,\n        cast_to: Type[ResponseT],\n        body: Body | None = None,\n        content: BinaryTypes | None = None,\n        options: RequestOptions = {},","sourceCodeStart":1393,"sourceCodeEnd":1429,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_base_client.py#L1393-L1429","documentation":"SyncAPIClient.put warns with a DeprecationWarning when the body argument is a raw bytes instance. Raw bytes bodies must now go through the content parameter; body is reserved for JSON-serializable data. The warning is emitted before FinalRequestOptions is constructed and the request sent.","triggerScenarios":"Calling client.put(url, body=b\"...\") — e.g. uploading a pre-serialized JSON string, file bytes, or binary payload via body instead of content.","commonSituations":"Code written against older SDK versions, or internal helpers that pass bytes bodies for file uploads; warnings may be hidden by default filters and surface only in CI with -W error.","solutions":["Move raw bytes from body= to content=","If the bytes are JSON, pass a dict via body= instead and let the SDK serialize","Run tests with -W error::DeprecationWarning to catch remaining call sites"],"exampleFix":"# before\nclient.put(url, body=payload_bytes, headers={\"Content-Type\": \"application/octet-stream\"})\n\n# after\nclient.put(url, content=payload_bytes, headers={\"Content-Type\": \"application/octet-stream\"})","handlingStrategy":"type-guard","validationCode":"if isinstance(body, bytes):\n    opts = {\"content\": body}\nelse:\n    opts = {\"body\": body}\nclient.put(url, **opts)","typeGuard":"def is_raw_bytes(v: object) -> TypeGuard[bytes]:\n    return isinstance(v, (bytes, bytearray))","tryCatchPattern":"with warnings.catch_warnings():\n    warnings.simplefilter(\"error\", DeprecationWarning)\n    client.put(url, content=raw)","preventionTips":["Run tests with -W error::DeprecationWarning to catch these early","Always use content= for bytes and body= for JSON data","Grep for 'body=b' and '.encode(' near client calls during upgrades"],"tags":["deprecation","request-body","bytes","http"],"backgroundTag":"deprecated-parameter-usage","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}