Skip to main content
@isnap/sdk is the TypeScript client of the iSnap API, published on npm under the MIT license. It runs in a server process, on Node.js or Bun. Read this page to install it, to check what it requires and to make a first call. These pages describe version 2.2.1.

Install

The package has no runtime dependency and no peer dependency. It contains compiled JavaScript, its own type declarations, and four short scripts in its examples directory. The examples of these pages are other scripts: copy them from here. The SDK follows Semantic Versioning. Its version is independent of the API version: see Versions.

Requirements

ESM and CommonJS

Import the SDK from an ECMAScript module:
In Node.js, require('@isnap/sdk') fails with ERR_PACKAGE_PATH_NOT_EXPORTED. CommonJS code loads the SDK with a dynamic import():

Server side only

The SDK is a server-side library. Its entry point imports node:crypto, so a browser bundle fails to build even when your code imports only the client. An API key is a secret: keep it on a server, and call the API from there.

TypeScript settings

The type declarations use the web platform types HeadersInit, Headers, RequestInit, Response, Blob and AbortSignal. A project therefore needs "lib": ["DOM"], or "skipLibCheck": true. Import the SDK from an ECMAScript module, with moduleResolution set to bundler, node16 or nodenext. A static import from a CommonJS file does not work:
  • Under node16, and under nodenext before TypeScript 5.8, it is a compile error (TS1479).
  • Under nodenext with TypeScript 5.8 or later, and under node10 with TypeScript 5, it compiles and then fails at run time with ERR_PACKAGE_PATH_NOT_EXPORTED. TypeScript 6 reports node10 as an error unless ignoreDeprecations is set, and TypeScript 7 refuses it.
Load the SDK from CommonJS with a dynamic import(), as in ESM and CommonJS. In TypeScript, this needs module set to node16 or nodenext: under commonjs, TypeScript compiles import() to a require(), which fails the same way. This tsconfig.json meets both requirements: it includes DOM, and it resolves modules with nodenext. It also loads the Node.js types, which TypeScript 6 and later do not load by default: install typescript and @types/node as development dependencies. With nodenext, a .ts file is an ECMAScript module when the nearest package.json has "type": "module":

Make a first call

Create an API key in the iSnap dashboard and put it in the ISNAP_API_KEY environment variable. The SDK reads no environment variable: your code passes the key to the client.
client.version() calls GET /v1/version, which needs no credential. client.lines.listMine() calls GET /v1/lines/my: when the API refuses the key, the call throws AuthenticationError. Authentication describes the keys and the refusals. Creating a client makes no network call. Every method returns a promise that resolves with the data of the response or throws: see Errors and retries. The four list iterators are the exception: they return an AsyncIterable, see Pagination.

What the SDK adds to plain HTTP

Help

Write to support@isnap.ai with the trace_id and request_id of the response. The SDK exposes them as traceId and requestId on the error it throws.