Skip to content

Expose a transport-level cancel/close handle on async streaming responses (so they can be cancelled from another task) #2425

Open

Description

@adtyavrdhn

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

Describe the solution you'd like
A transport handler we could close with or cancel with would be great

Describe alternatives you've considered
There are some things we could do to maybe mimic this but given that most SDKs have this it would be nice if genai did too

Additional context
I have just added a small warning for now.
https://pydantic.dev/docs/ai/models/google/#streaming-cancellation

Activity

  1. added
    type: feature request
    priority: p3
    on May 13, 2026
  2. self-assigned this
    on May 14, 2026
  3. Venkaiahbabuneelam commented on May 14, 2026

    @Venkaiahbabuneelam

    Hi @adtyavrdhn, Thanks for reaching out us!

    Thank you for your feedback. We appreciate you taking the time to share your thoughts with us, and we'll be filing a feature request.

    Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p3type: feature request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions