Skip to content

feat: expose async stream cancel handle#148

Open
MukundaKatta wants to merge 1 commit into
xai-org:mainfrom
MukundaKatta:codex/async-stream-cancel-handle
Open

feat: expose async stream cancel handle#148
MukundaKatta wants to merge 1 commit into
xai-org:mainfrom
MukundaKatta:codex/async-stream-cancel-handle

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

  • return a cancelable async iterator handle from chat.stream() while preserving existing async for usage
  • expose cancel() and aclose() so callers can stop the underlying gRPC stream early
  • document the early-stop pattern and add a regression test for transport cancellation

Closes #142

Tests

  • uv run pytest tests/aio/chat_test.py -q
  • uv run pytest tests/aio/chat_test.py::test_stream_cancel_cancels_underlying_rpc tests/aio/chat_test.py::test_streaming tests/aio/chat_test.py::test_stream_creates_span_with_correct_attributes -q
  • uv run ruff check src/xai_sdk/aio/chat.py tests/aio/chat_test.py
  • uv run pyright src/xai_sdk/aio/chat.py tests/aio/chat_test.py
  • uv run ruff format --check src/xai_sdk/aio/chat.py tests/aio/chat_test.py
  • git diff --check

@MukundaKatta MukundaKatta requested a review from a team as a code owner May 15, 2026 20:35
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.

[FEATURE] Expose a transport-level cancel/close handle on async streaming responses

1 participant