Skip to Content
SDKJavaScript / TypeScript

The @canarygate/sdk package is the official client for integrating CanaryGate into JavaScript and TypeScript applications. It is split into two entry points:

  • @canarygate/sdk/client — for browsers. Always uses the snapshot request and never opens SSE; it polls the snapshot every pollIntervalMs.
  • @canarygate/sdk/server — for server runtimes (Node.js, Deno, Bun, Edge). Real-time SSE streaming for server runtimes (always-on after init).

There is no root entry point (@canarygate/sdk); always import one of the two paths above.

More SDKs coming soon — Python, C#, and Java are in the works.

Compatibility

EnvironmentSupport
Browser (modern)✓
Node.js 18+✓
Deno✓ (via npm)
Bun✓
Edge Runtime (Cloudflare Workers, Vercel Edge)Partial*

*The client entry (@canarygate/sdk/client) always uses the snapshot request and never opens SSE — it refreshes via polling. The server entry (@canarygate/sdk/server) always streams over SSE after init(). Each entry throws an error if used in the wrong environment.

Installation

npm install @canarygate/sdk

Full API

MethodDescription
new CanaryGate(apiKey, options?)Creates the client
init()Loads flags via snapshot; the server entry opens SSE, the browser entry starts polling
getFlag(key)Returns FlagData | undefined
getFlags()Returns FlagData[] (all flags)
isStale()true if the connection is degraded
getLastSyncAt()string | null of the last sync
disconnect()Closes the stream connection (if any) and releases resources

Next steps

Last updated on