Skip to main content
The TypeScript SDK ships full type definitions for every endpoint, request payload, and response object, so your editor catches mistakes before they hit production. It runs in Node.js 18+ and any modern bundler-based environment. This page covers installing @surgeapi/node, sending your first request, paginating list endpoints, narrowing typed errors, and verifying webhook signatures in your handler.

Install and authenticate

Set your API key as an environment variable:

Your first request

Type imports

Every resource and parameter has a corresponding TypeScript type:

Pagination

The SDK returns auto-paginating iterators using async iteration:
Page manually when you need cursor control:

Retries and timeouts

The SDK retries transient failures automatically. Configure on the client:

Error handling

Errors are typed exceptions:

Webhooks

Use the SDK’s built-in webhook helper to verify signatures and parse events:
Pass the raw request body (string) to surge.webhooks.unwrap, not the parsed JSON. Signature verification requires the exact byte sequence that was signed. Use express.raw() or your framework’s equivalent. The webhook secret is passed to the Surge client constructor as webhookSigningSecret, or it can be passed per-call as the key option.