Repository navigation
Stream responses.create - #17
Merged
Merged
Conversation
responses.create(stream=True), sync and async, sends "stream": true and returns a Stream of ResponseStreamEvent through the shared SSE reader. Events keep their type and every field; the stream ends at [DONE] or at the end of the body. An error event raises the APIError subclass for its code and closes the response. Sync and async now share one request-body builder. Refs #15 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uy5vXsRpMhug7v3XwTMZHv
An error whose code is not in the table now falls back to its type, so
{"type": "invalid_request_error", "code": "model_not_found"} is a 400, not a 500.
delta is typed Any so an event with a non-string delta cannot end the stream.
Tests lock response.failed as an ordinary event.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uy5vXsRpMhug7v3XwTMZHv
theQuert
force-pushed
the
claude/responses-stream
branch
from
October 7, 2026 04:36
81dbfef to
f889e0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #15.
responses.create(stream=True)(sync and async) sends"stream": trueand returnsStream[ResponseStreamEvent](AsyncStreamfor the async client).typeand every field the API sent.deltais typedAny, so an unforeseen shape cannot end the stream. Other common fields are declared:text,item,part,response,sequence_number,item_id. The last two are optional, because the gateway's own events do not carry them yet.data: [DONE](the gateway's own streams) or at the end of the body (passed-through OpenAI streams).errorevent raises the matchingAPIErrorsubclass and closes the response. The SDK picks the subclass from the error'scode, falling back to itstype(for exampleRateLimitErrorforrate_limit_exceeded).response.failedis still yielded as an ordinary event. Both shapes are handled: OpenAI's{"type": "error", ...}and a gateway-style{"error": {...}}.add-responses-stream.Proof
pytest: 132 passed (8 new) on Python 3.13, 3.9, and 3.9 with minimum dependencies.mypy apertis: the same 12 errors asmain, none new.event: <type>\ndata: <json>\n\n…data: [DONE]\n\n) and covers:RateLimitErroris raised and the response is closed🤖 Generated with Claude Code
https://claude.ai/code/session_01Uy5vXsRpMhug7v3XwTMZHv