Skip to content

Conversation

@JaredConover
Copy link
Contributor

@JaredConover JaredConover commented Sep 24, 2025

What

Enable the parsing of type property inside of the event.data object for mapping model responses.

Why

Parsing of streamed events from /responses endpoint only looks at the type property of the SSE event itself, and not at the type property inside the events data payload. As a result it is not possible to parse properly formed events.

When attempting to stream events from the /responses api using OpenAI.responses.createResponseStreaming() it seems there is a bug that prevents the events from being processed.

Despite receiving properly formatted events, ie:

data: {"type":"response.output_text.delta","sequence_number":0,"delta":"#", ...}

ModelResponseEventsStreamInterpreter.processEvent for:

Printing description of event:
▿ Event
  - id : nil
  ▿ data : 69 bytes
    - count : 69
    ▿ pointer : 0x000000011450ec90
      - pointerValue : 4635815056
  - decodedData : "{\"type\":\"response.output_text.delta\",\"sequence_number\":0,\"delta\":\"#\"}"
  - eventType : "message"
  - retry : nil

Produces error:

Printing description of error:
▿ InterpreterError
  - unknownEventType : "message"

The "message" event type is not present in the event received and seems to come from line 207 of the ServerSentEventsStreamParser that sets a default event type (for the sse event) to "message" by default if there is no value in the event field of the sse event.

I believe the bug is that ModelResponseEventsStreamInterpreter.processEvent refers to this default value for the SSE event field when attempting to parse a ModelResponseStreamEventType when it should be using the type property inside the SSE event's data object as per the openAI spec. We can see is "response.output_text.delta" in the example above.

Affected Areas

This updates how streamed model responses are parsed and processed.

@JaredConover JaredConover force-pushed the fix/responses-api-type-parsing branch from bbacc68 to 629b8b6 Compare September 25, 2025 02:02
@JaredConover JaredConover marked this pull request as ready for review September 25, 2025 14:42
@JaredConover JaredConover changed the title use event type in payload Consider event type in data payload when processing model response streams Sep 25, 2025
@JaredConover JaredConover changed the title Consider event type in data payload when processing model response streams Bug: Consider event type in data payload when processing model response streams Sep 25, 2025
@JaredConover
Copy link
Contributor Author

@nezhyborets what do you think?

@JaredConover JaredConover changed the title Bug: Consider event type in data payload when processing model response streams Fix: Consider event type in data payload when processing model response streams Sep 25, 2025
@JaredConover JaredConover force-pushed the fix/responses-api-type-parsing branch from 702a361 to 0840940 Compare September 25, 2025 15:20
@nezhyborets
Copy link
Collaborator

Hi @JaredConover , I'm looking into the issue. Thanks for the provided solution, but I want to look into parser first. It's strange that it doesn't parse the type if the data is there.

@nezhyborets
Copy link
Collaborator

BTW I don't know why but it doesn't happen for me, can't reproduce

@nezhyborets
Copy link
Collaborator

Do you use some other server/provider than OpenAI, that doesn't set SSE event type?

@JaredConover
Copy link
Contributor Author

JaredConover commented Sep 25, 2025

Yes exactly, the type is not set at the level of the SSE event - just in the data object.

This should still work no? I didn't see anywhere in the OpenAI api spec where specifying the type in two places (ie payload data object and top level of the SSE event) is necessary

@nezhyborets nezhyborets merged commit c8b02fc into MacPaw:main Sep 25, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants