Skip to content

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

@adtyavrdhn

Description

@adtyavrdhn

Confirmation of Request Source

  • I confirm that this feature request is for the xAI SDK Python library (e.g., client features, SDK methods, or documentation) and not for the xAI API itself (e.g., model capabilities or API changes).

Describe the feature you'd like

While working on pydantic/pydantic-ai#1524 I hit: Chat.stream() (in xai_sdk.aio.chat) only exposes the async generator, so cancelling it from another task while we're iterating raises RuntimeError: aclose(): asynchronous generator is already running.

A transport handle we could close/cancel directly — exposing the underlying UnaryStreamCall (or a wrapper with cancel() / close() on it), like the OpenAI (AsyncStream.close()) and
Anthropic (AsyncStream.close()) SDKs do. Would be nice to be able to do the same here.

Parallel issue on google-genai: googleapis/python-genai#2425

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions