Skip to content

Conversation

@stevenou
Copy link

@stevenou stevenou commented May 9, 2025

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?

So I based this off of #480 which seems like it might be abandoned at this point. I copy-pasted the spec minus a minor fix for splitting the json into 2 chunks (it was missing a character in the 2nd chunk).

The approach taken here assumes the error is parsable json. We accumulate the chunks until the message is parsable, then we raise an error. I don't really know enough about SSE/streaming to know whether this is definitely a bad idea but none of the existing specs broke so I'm hoping it's acceptable.

Not sure what would happen if, let's say, the stream disconnects midway so we never get the completed error message. I'm guessing in that case a different type of error (related to connection/streaming) will surface instead of the original error, which is probably ok?

Or if the error is never parsable - then possibly the whole thing fails silently?

Let me know your thoughts please.

stevenou added a commit to InvisibleCommerce/ruby-openai that referenced this pull request Jan 15, 2026
When the OpenAI API returns an error during streaming, the error JSON
body may be split across multiple HTTP chunks. Previously, the code
would immediately try to raise an error on the first chunk, which would
fail if the JSON was incomplete.

This change accumulates error chunks until a complete, parsable JSON
object is formed, then raises the appropriate Faraday error. It also
prevents the user proc from being called when an error status is
received.

Based on the approach from PR alexrudall#591.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant