Install & initialize
- Written for
- + Written for
- Deprecated
- + Deprecated
- Applies to
- + Applies to
Install & initialize
@cookiemunch/sdk is a small, fully-typed REST client over the /v1 developer API. It has zero required dependencies beyond a fetch implementation, works in Node, Deno, Bun, and the browser, and mirrors every route documented in the REST API section.
Install
npm install @cookiemunch/sdk
# or
pnpm add @cookiemunch/sdk
# or
yarn add @cookiemunch/sdkInitialize
import { createCookieMunch } from '@cookiemunch/sdk';
const client = createCookieMunch({
apiKey: process.env.COOKIEMUNCH_API_KEY!,
baseUrl: 'https://api.cookiemunch.net', // the /v1 prefix is appended automatically
});
const sites = await client.sites.list();CookieMunchOptions
Field | Type | Required | Description |
|---|---|---|---|
| string | yes | Your |
| string | yes | Your Cookie Munch server origin, e.g. |
|
| no | Inject a custom |
Note: the SDK never accepts or sends an
orgId. Every request is authenticated by the API key, and the server derives the org from that key — this makes cross-org access structurally impossible from client code.
Error handling
Every non-2xx response throws CookieMunchApiError:
import { CookieMunchApiError } from '@cookiemunch/sdk';
try {
await client.sites.get('unknown-cbid');
} catch (err) {
if (err instanceof CookieMunchApiError) {
console.error(err.status, err.message, err.code);
// 404 "site not found" undefined
}
throw err;
}Property | Type | Description |
|---|---|---|
| number | The HTTP status code. |
| string | The server's |
| string | undefined | The server's |
Injecting fetch (testing / non-browser runtimes)
import { createCookieMunch } from '@cookiemunch/sdk';
import { vi } from 'vitest';
const mockFetch = vi.fn(async () => new Response(JSON.stringify({ orgId: 'org_1', plan: 'free', keyPrefix: 'fck_test' }), { status: 200 }));
const client = createCookieMunch({ apiKey: 'fck_test', baseUrl: 'http://localhost:8787', fetch: mockFetch as unknown as typeof fetch });
await client.me();Next steps
Client reference — every
client.*method, with signatures and examples.MCP setup — expose the same API as tools an AI agent can call directly, built on this SDK.
REST API: authentication — how API keys and scopes work under the hood.