{"record":{"id":"79f633731e1584ed","repo":"openai/openai-python","slug":"missingstreamclasserror","errorCode":null,"errorMessage":"MissingStreamClassError","messagePattern":"MissingStreamClassError","errorType":"exception","errorClass":"MissingStreamClassError","httpStatus":null,"severity":"error","filePath":"src/openai/_response.py","lineNumber":173,"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":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_response.py#L155-L191","documentation":"Parsing an SSE streaming response requires a stream class to wrap the response iterator, and the client's _default_stream_cls is None. This happens when the response object isn't bound to a client that provides a default stream class (e.g. manually constructed responses or a misconfigured custom client), so MissingStreamClassError is raised.","triggerScenarios":"Calling response.parse() on an SSE response whose client lacks a default stream class — detached/manually built response objects, or a custom client subclass that overrode _default_stream_cls with None.","commonSituations":"Mocking or faking the client/response in tests without setting the stream class; custom client wrappers that reset internal defaults; upgrading across major versions where client internals changed.","solutions":["Use the real client returned by OpenAI()/AsyncOpenAI() rather than constructing response objects manually","In tests, mock at the HTTP transport layer instead of building bare response objects","If subclassing the client, don't set _default_stream_cls to None; leave the inherited Stream/AsyncStream default"],"exampleFix":"// before\nresp = construct_type(value=data, type_=APIResponse)\nresp.parse()  # client missing -> MissingStreamClassError\n// after\nresp = await client.chat.completions.with_raw_response.create(..., stream=True)\nresp.parse()  # client supplies default stream class","handlingStrategy":"try-catch","validationCode":"from openai._response import MissingStreamClassError\nif getattr(client, '_default_stream_cls', None) is None:\n    raise RuntimeError('client missing default stream class; use OpenAI()/AsyncOpenAI()')","typeGuard":"def client_has_stream_class(client) -> bool:\n    return getattr(client, '_default_stream_cls', None) is not None","tryCatchPattern":"from openai._response import MissingStreamClassError\n\ntry:\n    stream = response.parse()\nexcept MissingStreamClassError:\n    logger.error('response not bound to a real client')\n    raise","preventionTips":["Never construct APIResponse/stream objects manually; use the real client","Mock at the transport layer in tests","Don't override client internals like _default_stream_cls"],"tags":["python","streaming","sse","client-configuration","missing-dependency"],"backgroundTag":"missing-stream-class","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}