Skip to main content
@meetdarwin/api is the TypeScript client for the Darwin REST API. It covers every resource in the API, with types for every object and parameter.
  • No runtime dependencies. It uses the global fetch, so it runs on Node 18+, Deno, Bun, Cloudflare Workers and Vercel Edge.
  • ESM, with type declarations for every object and parameter.
  • Retries, idempotency keys, cursor pagination and webhook verification built in.

Install

Quickstart

Create a secret key in Darwin under Integrations → API (how). Keep it on your server.
quickstart.ts
new Darwin() with no apiKey reads the DARWIN_API_KEY environment variable.
The client refuses to start in a browser, because a secret key there is visible to every visitor. Call Darwin from your server. To control the chat on your website, use the Browser SDK.

Options

Every method also takes a last options argument for that one call: { idempotencyKey, signal, timeoutMs, maxRetries, headers }.

Resources

Parameters and fields use the API’s own names (has_lead, created_since, next_cursor), so the API reference applies word for word. Anywhere a parameter takes a time you may pass a Date or an ISO string. Responses carry timestamps as ISO strings. For an endpoint this version does not wrap yet, darwin.request(method, path, { query, body }) gets the same auth, retries and errors.

Requirements

Node 18.17 or later, or any runtime with fetch, Web Crypto and ReadableStream. MIT licensed. Release notes are in the changelog.

Next

Pagination

One page, every item, or whole pages with a ceiling.

Errors and retries

Error classes, automatic retries and idempotency keys.

Verify webhooks

Express and Next.js receivers in a few lines.

Stream chat replies

Talk to your agent and stream its answer.