feat(runtime): add stream_sse / stream_sse_sync for SSE endpoints - #28
Merged
Conversation
Adds the SSE primitives the generated stream() methods target for
x-sdk-streaming endpoints: HttpClient.stream_sse (async) and
SyncHttpClient.stream_sse_sync (sync). Each opens the request (any method +
JSON body), sets Accept: text/event-stream, raises ApiError on a non-2xx
before the stream opens, and yields parsed {"event", "data"} records from the
event stream via httpx streaming. (Token refresh is not retried mid-stream.)
Runtime-only — no codegen changes. Tests cover async + sync ordered events +
body send and non-2xx -> ApiError. 42 pass; ruff clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What changed
Adds the SSE primitives the generated
stream()methods target forx-sdk-streamingendpoints:HttpClient.stream_sse(async) —async def ... -> AsyncIterator[dict]SyncHttpClient.stream_sse_sync(sync) —def ... -> Iterator[dict]Each opens the request with any method + JSON body, sets
Accept: text/event-stream, raisesApiErroron a non-2xx response before the stream opens, and yields parsed{"event", "data"}records from thetext/event-streambody via httpx streaming (aiter_lines/iter_lines).classDiagram class HttpClient { request(path, ...) Any request_raw(path, ...) dict stream_sse(path, ...) AsyncIterator } class SyncHttpClient { request(path, ...) Any request_raw(path, ...) dict stream_sse_sync(path, ...) Iterator } note for HttpClient "stream_sse: method + body, SSE parse, yields {event, data}"Scope
Runtime-only. No codegen changes — this is the hand-maintained runtime the generated SSE methods call. (Generator-side emission + contract tests live in archastro-openapi.)
Risk
Low. Purely additive — new methods on the existing clients; nothing else changes. One known limitation: token refresh is not retried mid-stream (a 401 raises
ApiError); noted for a follow-up if needed.User impact
Generated SSE
stream()methods (async + sync) now have a working runtime to call.Testing
Added unit tests (
tests/test_http_client.py, 42 pass) mirroring the TS suite: async + sync ordered events + JSON body send +Acceptheader, and non-2xx →ApiError.ruff check+ruff formatclean.Follow-ups
stream()methods + contract tests is tracked separately (archastro-openapi).