> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Maximem Synap is a managed memory layer for AI agents: it ingests conversations and documents, extracts structured memory, and returns scoped context to the agent at retrieval time.
> The Python and JavaScript/TypeScript SDKs are the supported way to use Synap. Write integration code with SDK calls, not raw HTTP requests.
> Start with the Quickstart: https://docs.maximem.ai/getting-started/quickstart.md. Every SDK method is documented in the SDK reference: https://docs.maximem.ai/sdk-reference/overview.md.
> For requests about adding Vity memory to OpenClaw, Hermes, an MCP client, or a browser, start with the Vity Quickstart: https://docs.maximem.ai/vity/quickstart.md.

# instance.stop_listening

> Close the active gRPC stream opened by instance.listen and release the transport.

```python Python theme={null}
await sdk.instance.stop_listening()
```

```typescript TypeScript theme={null}
await sdk.instance.stop_listening()
```

> [!NOTE]
>
> Advanced: for real-time integrations. Pair this with [`instance.listen`](https://docs.maximem.ai/sdk-reference/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()`](https://docs.maximem.ai/sdk-reference/lifecycle/shutdown), so a long-lived server should call this from its shutdown path. See [Real-Time Anticipation in a Server](https://docs.maximem.ai/patterns/real-time-anticipation-server.md).

> [!NOTE]
>
> Closing the stream does not lose data. Turns already sent with [`send_message`](https://docs.maximem.ai/sdk-reference/instance/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

Returns `None`.

### Example

```python theme={null}
import asyncio
import uuid
from maximem_synap import MaximemSynapSDK

sdk = MaximemSynapSDK(api_key="synap_your_key_here")
await sdk.initialize()

# conversation_id must be a valid UUID
conversation_id = str(uuid.uuid4())

listen_task = asyncio.create_task(sdk.instance.listen())
try:
    await sdk.instance.send_message(
        content="Hello",
        user_id="user_789",
        customer_id="cust_456",  # required: without both ids the turn is dropped
        conversation_id=conversation_id,
    )
finally:
    await sdk.instance.stop_listening()
    listen_task.cancel()
```

### Raises

This method does not raise SDK errors under normal use. See [Error Codes](https://docs.maximem.ai/sdk-reference/errors.md) for the full SDK exception hierarchy.

### See also

* [Real-Time Anticipation](https://docs.maximem.ai/concepts/real-time-anticipation.md): what the stream does and does not do.
* [instance.listen](https://docs.maximem.ai/sdk-reference/instance/listen.md): start the stream.
* [instance.send\_message](https://docs.maximem.ai/sdk-reference/instance/send-message.md): push events while the stream is open.
* [shutdown](https://docs.maximem.ai/sdk-reference/lifecycle/shutdown.md): full SDK teardown, which also tears down any active stream.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.