{"record":{"id":"1ed0258012b1c570","repo":"openai/openai-python","slug":"invalid-http-client-argument-expected-an-instan","errorCode":null,"errorMessage":"Invalid `http_client` argument; Expected an instance of `httpx.Client` or `httpx2.Client` but got {type(http_client)}","messagePattern":"Invalid `http_client` argument; Expected an instance of `httpx\\.Client` or `httpx2\\.Client` but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/_base_client.py","lineNumber":929,"sourceCode":"            # if the user passed in a custom http client with a non-default\n            # timeout set then we use that timeout.\n            #\n            # note: there is an edge case here where the user passes in a client\n            # where they've explicitly set the timeout to match the default timeout\n            # as this check is structural, meaning that we'll think they didn't\n            # pass in a timeout and will ignore it\n            client_timeout = normalize_httpx_timeout(http_client.timeout) if http_client else None\n            if http_client and client_timeout != HTTPX_DEFAULT_TIMEOUT:\n                timeout = client_timeout\n            else:\n                timeout = DEFAULT_TIMEOUT\n\n        if (\n            http_client is not None\n            and not is_httpx2_sync_client(http_client)\n            and not is_legacy_httpx_sync_client(http_client)\n        ):\n            raise TypeError(\n                \"Invalid `http_client` argument; Expected an instance of `httpx.Client` or `httpx2.Client` \"\n                f\"but got {type(http_client)}\"\n            )\n\n        super().__init__(\n            version=version,\n            # cast to a valid type because mypy doesn't understand our type narrowing\n            timeout=cast(Timeout, timeout),\n            base_url=base_url,\n            max_retries=max_retries,\n            custom_query=custom_query,\n            custom_headers=custom_headers,\n            _strict_response_validation=_strict_response_validation,\n        )\n        self._client = http_client or SyncHttpxClientWrapper(\n            base_url=base_url,\n            # cast to a valid type because mypy doesn't understand our type narrowing\n            timeout=cast(Timeout, timeout),","sourceCodeStart":911,"sourceCodeEnd":947,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_base_client.py#L911-L947","documentation":"Raised by sync upload_file_chunked when `file` is bytes and `bytes` (the declared total size) was not given. The chunked upload protocol needs the total size up front to create the upload session, and it cannot be derived from streaming bytes, so the SDK raises TypeError. In practice this fires only when filename was provided but the size is missing.","triggerScenarios":"Calling upload_file_chunked with in-memory bytes, a filename, but omitting the bytes= (size) argument.","commonSituations":"Hand-rolling the multipart/chunked flow against uploads.create + parts.create + complete instead of using the helper, or partially migrating old code that passed only the file.","solutions":["Prefer the public client.files.create / upload helper over manual chunked calls so sizes are handled for you","If calling upload_file_chunked directly, always pass bytes=len(data) alongside filename","Validate size is a positive int before uploading"],"exampleFix":"# before\nclient.beta.uploads.upload_file_chunked(data, purpose='assistants', filename='a.bin')\n# after\nclient.uploads.upload_file_chunked(data, bytes=len(data), purpose='assistants', filename='a.bin')","handlingStrategy":"validation","validationCode":"if isinstance(data, bytes):\n    assert filename, 'filename required for bytes uploads'\n    assert isinstance(total_bytes, int) and total_bytes > 0, 'bytes (size) required'","typeGuard":"def chunked_args_ready(data: object, filename: object, size: object) -> bool:\n    return (not isinstance(data, (bytes, bytearray))) or (bool(filename) and isinstance(size, int) and size > 0)","tryCatchPattern":null,"preventionTips":["Prefer high-level upload helpers over manual chunked calls","Compute bytes=len(data) once and reuse it","Type-check size as int; the server also validates totals"],"tags":["openai","uploads","content-length","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"}