{"record":{"id":"98786342ddb15911","repo":"openai/openai-python","slug":"missing-stream-class","errorCode":null,"errorMessage":"Missing stream class","messagePattern":"Missing stream class","errorType":"exception","errorClass":"MissingStreamClassError","httpStatus":null,"severity":"error","filePath":"src/openai/_legacy_response.py","lineNumber":242,"sourceCode":"                        client=cast(Any, self._client),\n                        options=self._options,\n                    ),\n                )\n\n            if self._stream_cls:\n                return cast(\n                    R,\n                    self._stream_cls(\n                        cast_to=extract_stream_chunk_type(self._stream_cls),\n                        response=self.http_response,\n                        client=cast(Any, self._client),\n                        options=self._options,\n                    ),\n                )\n\n            stream_cls = cast(\"type[Stream[Any]] | type[AsyncStream[Any]] | None\", self._client._default_stream_cls)\n            if stream_cls is None:\n                raise MissingStreamClassError()\n\n            return cast(\n                R,\n                stream_cls(\n                    cast_to=cast_to,\n                    response=self.http_response,\n                    client=cast(Any, self._client),\n                    options=self._options,\n                ),\n            )\n\n        if cast_to is NoneType:\n            return cast(R, None)\n\n        response = self.http_response\n        if cast_to == str:\n            return cast(R, response.text)\n","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_legacy_response.py#L224-L260","documentation":"Raised when a response is expected to be streamed but the client has no default stream class configured. The SDK needs a Stream/AsyncStream class to wrap the response, and it looks it up via client._default_stream_class; if that attribute is None (typically because the client was constructed in an unusual or partially-initialized way, or a custom client subclass did not set a stream class), parsing a streaming response cannot proceed.","triggerScenarios":"Calling client.post(..., stream=True) (or any streaming endpoint) with cast_to that requires a stream wrapper when _default_stream_class is None; constructing an OpenAI/AsyncOpenAI instance via a custom subclass or mock that never assigns the stream class.","commonSituations":"Mocking or patching the OpenAI client in tests so internals are missing; using a forked/custom HTTP client subclass that overrides __init__ and skips stream class setup.","solutions":["Construct the client normally with OpenAI() / AsyncOpenAI() instead of a custom subclass or mock","If subclassing, ensure super().__init__() is called so _default_stream_class is set","Don't patch client internals; use recorded responses or a mock transport instead"],"exampleFix":"// before\nclass MyClient(OpenAI):\n    def __init__(self):\n        self.api_key = '...'\n# after\nclass MyClient(OpenAI):\n    def __init__(self):\n        super().__init__()\n","handlingStrategy":"validation","validationCode":"from openai import OpenAI\nclient = OpenAI()\nassert getattr(client, '_default_stream_class', None) is not None, 'client misconfigured; call super().__init__() in subclasses'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call super().__init__() when subclassing OpenAI/AsyncOpenAI","Mock transports rather than client internals in tests"],"tags":["streaming","client-setup","sdk-internal"],"backgroundTag":"missing-client-configuration","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}