Before your application can ingest memories or retrieve context, you must initialize the Synap SDK. Initialization validates your API key, establishes a secure connection, and prepares local caching. The SDK follows a strict initialize, use, shutdown lifecycle.
The simplest way to get started requires only your SYNAP_API_KEY environment variable. Generate an API key from the Synap Dashboard and set it in your environment.
from synap import MaximemSynapSDKsdk = MaximemSynapSDK( api_key="synap_your_key_here")await sdk.initialize()
You must call await sdk.initialize() before invoking any SDK operations. Calling methods like sdk.memories.create() before initialization raises an AuthenticationError.
When you call initialize(), the SDK performs the following steps in order:
1
Resolve API Key
The SDK picks up the API key from the api_key= argument (if passed) or the SYNAP_API_KEY environment variable.
2
Connection Establishment
The SDK opens an authenticated REST connection to Synap Cloud and, if streaming is configured, a gRPC channel. Both send the API key as Authorization: Bearer synap_....
3
Cache Initialization
If a cache_backend is configured (default: sqlite), the SDK sets up the local cache database at the storage path.
By default, the SDK maintains a single instance per instance_id. If you construct a second MaximemSynapSDK with the same instance_id, you receive a reference to the existing instance rather than creating a new one.
sdk_a = MaximemSynapSDK(api_key="synap_key_1")sdk_b = MaximemSynapSDK(api_key="synap_key_1")# sdk_a and sdk_b point to the same SDK instanceassert sdk_a is sdk_b
This prevents accidental duplication of connections and caches in applications that construct the SDK from multiple modules.
The _force_new parameter is intended for testing only. Using it in production can lead to multiple SDK instances competing for the same credential files and cache database.
Call await sdk.shutdown() to gracefully tear down the SDK.
await sdk.shutdown()
Always call shutdown() before your application exits to ensure pending telemetry is flushed and active gRPC streams are closed cleanly. Failing to call shutdown() may result in lost telemetry data and lingering connections.
The API key is read fresh on every start. There is no one-time setup step — the same SYNAP_API_KEY works forever (until you revoke it in the Dashboard).