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

# Syncing a Local Instance

> Connect your local Cognee SDK to Cognee Cloud

The Cognee Python SDK can connect to a remote Cognee instance using `cognee.serve()`. Once connected, all operations (`remember`, `recall`, `forget`, `improve`) route to the remote instance instead of running locally.

## Connect to Cognee Cloud

```bash theme={null}
pip install cognee
```

```python theme={null}
import cognee

# Opens browser for authentication; discovers your cloud tenant automatically
await cognee.serve()
```

After login, the SDK stores credentials at `~/.cognee/cloud_credentials.json`. Subsequent calls to `cognee.serve()` reconnect without re-authenticating until the token expires.

## Connect to any instance

For self-hosted or staging environments, pass the URL and API key directly:

```python theme={null}
await cognee.serve(
    url="https://your-instance.cognee.ai",
    api_key="your-api-key"
)
```

Or use environment variables:

```bash theme={null}
export COGNEE_SERVICE_URL="https://your-instance.cognee.ai"
export COGNEE_API_KEY="your-api-key"
```

```python theme={null}
await cognee.serve()  # Reads from environment
```

## Local-to-local connections

Connect to a Cognee backend on the same machine or local network:

```python theme={null}
# Same machine
await cognee.serve(url="http://localhost:8000")

# Local network
await cognee.serve(url="http://192.168.1.50:8000")
```

Start the local server with `cognee serve` before connecting.

## Usage after connection

Once connected, all SDK operations execute on the remote instance:

```python theme={null}
# Ingested into the remote tenant
await cognee.remember("Einstein developed general relativity in 1915.")

# Queries the remote knowledge graph
results = await cognee.recall("What did Einstein develop?")

# Disconnect when done
await cognee.disconnect()
```

<Note>
  The local UI in Cognee Cloud automatically detects running local instances on `localhost:8000` and shows their connection status.
</Note>
