Skip to content

Add cancelable async chat streams#143

Open
Jaksenc wants to merge 1 commit into
xai-org:mainfrom
Jaksenc:codex/async-stream-close
Open

Add cancelable async chat streams#143
Jaksenc wants to merge 1 commit into
xai-org:mainfrom
Jaksenc:codex/async-stream-close

Conversation

@Jaksenc
Copy link
Copy Markdown

@Jaksenc Jaksenc commented May 13, 2026

Summary

  • return cancelable async stream objects from async chat stream APIs instead of bare async generators
  • cancel the underlying grpc aio call from aclose()/close()/cancel(), so a consumer task can be stopped while another task is awaiting the next chunk
  • preserve telemetry span lifecycle and accumulated streaming responses, including batch streaming behavior
  • add a regression test for closing a stream while iteration is blocked

Fixes #142.

Testing

  • .venv/bin/python -m ruff format src/xai_sdk/aio/chat.py tests/aio/chat_test.py
  • .venv/bin/python -m ruff check src/xai_sdk/aio/chat.py tests/aio/chat_test.py
  • .venv/bin/python -m pytest tests/aio/chat_test.py -q
  • .venv/bin/pyright --pythonpath .venv/bin/python src/xai_sdk/aio/chat.py
  • .venv/bin/pyright --pythonpath .venv/bin/python src/xai_sdk
  • git diff --check

@Jaksenc Jaksenc requested a review from a team as a code owner May 13, 2026 15:13
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