cognee.serve()
Description
Connect the local Cognee Python SDK to Cognee Cloud or another remote Cognee API server. Afterserve() connects, high-level SDK operations route to the remote instance instead of local storage. You can call methods on the returned CloudClient, or continue using top-level operations such as cognee.remember(), cognee.recall(), cognee.improve(), and cognee.forget().
Use cognee.disconnect() to clear the active remote client and return the SDK to local mode.
serve() changes where SDK operations execute. It does not copy existing local datasets to the remote instance. Use push() to upload an already-built local graph, or call remember() after connecting to ingest directly into the remote instance.Connection resolution
serve() resolves the remote target in this order:
- Explicit
urlandapi_keyarguments COGNEE_SERVICE_URLandCOGNEE_API_KEYenvironment variables- Saved credentials from a previous Cognee Cloud login
- Browser login flow when connecting to Cognee Cloud interactively
Parameters
Remote Cognee instance URL. When omitted, Cognee reads
COGNEE_SERVICE_URL, saved Cloud credentials, or starts the Cloud login flow.API key for the remote instance. When omitted, Cognee reads
COGNEE_API_KEY or saved Cloud credentials. Local unauthenticated servers may not require it.Returns
ACloudClient configured for the connected instance.
The returned client exposes the main remote operations:
Ingest data and build memory on the remote instance.
Query memory from the remote instance.
Run enrichment or session-bridging on remote memory.
Delete remote data, datasets, or memory state.
Examples
- Cognee Cloud
- Explicit credentials
- Environment variables
- Local server
Disconnecting
disconnect() closes the active remote connection for the current SDK process. Saved credentials are not deleted, so a later serve() call can reconnect without requiring a new login when the credentials are still valid.