Advanced: for real-time integrations. Pair this with
instance.listen and call it during shutdown (or in a finally block) so the stream is closed cleanly.stop_listening() ends the bidirectional gRPC stream that listen() established, cancels the underlying transport, and clears the SDK’s reference to it. After this call returns, instance.is_listening is False and any subsequent instance.send_message calls raise ListeningNotActiveError. Calling stop_listening() when no stream is active is a safe no-op.
Your application owns the stream’s lifecycle. Nothing closes it for you except shutdown(), so a long-lived server should call this from its shutdown path. See Real-Time Anticipation in a Server.
Closing the stream does not lose data. Turns already sent with
send_message are persisted server-side and still reach long-term memory when the conversation compacts, whether or not the stream is open. Closing ends anticipation only; fetch() continues to work over the normal request-response path.Parameters
This method takes no parameters.Returns
ReturnsNone.
Example
Raises
This method does not raise SDK errors under normal use. See Error Codes for the full SDK exception hierarchy.See also
- Real-Time Anticipation: what the stream does and does not do.
- instance.listen: start the stream.
- instance.send_message: push events while the stream is open.
- shutdown: full SDK teardown, which also tears down any active stream.