Streaming a Responses request that surfaces an API error frame rejects
finalResponse() with a plain object instead of an OpenAIError, so
instanceof-based error handling misses it.
Repro against the shipped class — no network, replaying a captured frame
through ResponseStream.fromReadableStream:
finalResponse REJECTED: isError=false isOpenAIError=false
raw= {"type":"error","code":"server_error","message":"boom","sequence_number":1}
Cause: error is a legitimate member of ResponseStreamEvent, so
#addEvent's default: arm re-emits it as an ordinary listener payload, and
EventStream._emit then rejects with the raw frame. The Assistants helper
handles the same class explicitly (AssistantStream.ts:381, "errors should be
processed earlier"), and the realtime emitter converts properly — Responses is
the only stream helper that doesn't.
Sending a PR alongside this: convert the frame in ResponseStream's error path,
mirroring the Assistants handling. The alternative is a transport-layer fix in
core/streaming.ts (which carries an unresolved TODO asking exactly this
question) — happy to move it there instead if you'd rather weigh the
Chat-Completions blast radius.
Streaming a Responses request that surfaces an API
errorframe rejectsfinalResponse()with a plain object instead of anOpenAIError, soinstanceof-based error handling misses it.Repro against the shipped class — no network, replaying a captured frame
through
ResponseStream.fromReadableStream:Cause:
erroris a legitimate member ofResponseStreamEvent, so#addEvent'sdefault:arm re-emits it as an ordinary listener payload, andEventStream._emitthen rejects with the raw frame. The Assistants helperhandles the same class explicitly (AssistantStream.ts:381, "errors should be
processed earlier"), and the realtime emitter converts properly — Responses is
the only stream helper that doesn't.
Sending a PR alongside this: convert the frame in ResponseStream's error path,
mirroring the Assistants handling. The alternative is a transport-layer fix in
core/streaming.ts (which carries an unresolved TODO asking exactly this
question) — happy to move it there instead if you'd rather weigh the
Chat-Completions blast radius.