MemorySyncMemorySync
Node SDK

Install & Auth

The memorysync-sdk package installs from the public npm registry under that exact name. This page covers the install command, every constructor option (with defaults), and a one-liner you can run in production to confirm a key is reaching the right environment.

Install

BASH
# npm
npm install memorysync-sdk
# pnpm
pnpm add memorysync-sdk
# yarn
yarn add memorysync-sdk
Watch the package name
The npm package is memorysync-sdk, not memorysync. The unsuffixed name on npm is not us. The Python package is memorysync; only Node has the suffix.

Verify the install

BASH
node -e "const {MemorySyncClient}=require('memorysync-sdk'); const v=require('memorysync-sdk/package.json').version; console.log('OK', v);"

Every constructor option

OptionTypeDefaultWhen to set it
apiKeystring— (required)Always.
baseUrlstring— (required)Per-environment URL.
projectIdstringundefinedLock this client to one project.
endUserIdstringundefinedRequired when authenticating with an API key. Identifies which of your end users the request belongs to; sent as the X-End-User-ID header. The server returns 400 MISSING_END_USER_ID without it. Can be overridden per call on add().
timeoutMsnumber30000Per-request ceiling in milliseconds.
fetchtypeof fetchglobalThis.fetchPass a custom fetch (e.g. an instrumented one).

Building the client

TYPESCRIPT
import { MemorySyncClient } from "memorysync-sdk";
const client = new MemorySyncClient({
apiKey: process.env.MEMORYSYNC_API_KEY!,
baseUrl: "https://api.memorysync.io",
endUserId: "user_123", // required for API-key auth
projectId: process.env.MEMORYSYNC_PROJECT_ID,
timeoutMs: 15_000,
});

Splitting environments

BASH
# .env.local
MEMORYSYNC_API_KEY=ms_test_...
MEMORYSYNC_BASE_URL=https://staging.api.memorysync.io
# .env.production
MEMORYSYNC_API_KEY=ms_live_...
MEMORYSYNC_BASE_URL=https://api.memorysync.io

A safe “hello world”

Run this once after wiring credentials. It does not write anything; it only confirms the client can reach the API and the key is valid.

TYPESCRIPT
// Reuses the client from the snippet above (with endUserId set).
try {
const exp = await client.exportAll();
console.log("OK userId =", exp.userId);
} catch (e: any) {
if (e?.name === "AuthError") console.error("Invalid key");
else throw e;
}

Plugging in a custom fetch

Inject your own fetch if you want to attach tracing, add a corporate proxy, or run inside an environment with a non-standard global.

TYPESCRIPT
const traced: typeof fetch = (url, init) => {
console.log("[memorysync]", init?.method ?? "GET", url);
return fetch(url, init);
};
const client = new MemorySyncClient({
apiKey: ..., baseUrl: ..., fetch: traced,
});

Rotating a leaked key

  1. Create a new key in the dashboard.
  2. Roll it out to your secret manager and restart your services.
  3. Confirm the new key is in use, then delete the old key. The dashboard revokes it immediately.