Skip to main content
The TypeScript SDK gives server-side TypeScript and JavaScript code typed access to the Dodo Payments REST API. It includes type definitions for every request and response, typed errors, automatic retries, timeouts, and auto-pagination.

Installation

Install the dodopayments package with your package manager:

Quick Start

Create a client, then create a checkout session:
If you omit bearerToken, the client reads the DODO_PAYMENTS_API_KEY environment variable. If you omit environment, the client connects to live mode. A test mode API key works only with environment: 'test_mode'.
Keep API keys in environment variables or a secrets manager. Never commit them to version control or expose them in client-side code.

Core Features

TypeScript First

Type definitions for every request parameter and response field, shown in your editor.

Auto-Pagination

List methods fetch the next page for you when you iterate with for await...of.

Error Handling

A typed error class for each HTTP error status, with the status, headers, and response body.

Smart Retries

Two retries by default, with exponential backoff, for connection errors and retryable status codes.

Configuration

Environment Variables

Store your API key in an environment variable:
.env
The client reads these variables when you don’t pass the matching option: If a base URL is set and you also pass environment, the constructor throws an “Ambiguous URL” error. To use environment in that case, pass baseURL: null. To verify a webhook, pass the raw request body and headers to client.webhooks.unwrap(rawBody, { headers }). It checks the signature with your webhook key and returns the parsed event. client.webhooks.unsafeUnwrap(rawBody) parses the body without verifying it, so use it only for testing. See Webhooks.

Timeout Configuration

Requests time out after 1 minute by default. Set timeout, in milliseconds, on the client or on a single request:
When a request times out, the SDK throws APIConnectionTimeoutError. Timed-out requests are retried, so a call can take longer than timeout before it fails.

Retry Configuration

Set maxRetries on the client or on a single request:
The SDK retries connection errors and responses with status 408, 409, 429, or 500 and above. It retries twice by default, with exponential backoff.
When a request still fails, the SDK throws a subclass of DodoPayments.APIError. Each error has status, headers, and error (the response body) properties. Check for a specific class with instanceof, for example err instanceof DodoPayments.RateLimitError:

Common Operations

The examples in this section use the client from Quick Start.

Create a Checkout Session

Create a checkout session, then redirect the customer to the returned checkout_url:
Each checkout_url works once and expires after 24 hours. For every session option, see Checkout Sessions.

Manage Customers

Create a customer with an email address and name, then retrieve it by ID:

Handle Subscriptions

Create a subscription, charge an on-demand subscription, and read a subscription’s usage history.
POST /subscriptions (the SDK’s subscriptions.create method) is deprecated. It still works for existing integrations, but new integrations should create subscriptions through a Checkout Session.
billing requires only country, a two-letter ISO country code. customer takes { customer_id } to attach an existing customer or { email, name? } to create one. charge is for on-demand subscriptions, and product_price is in the smallest currency unit. retrieveUsageHistory returns a paginated list, which you can iterate as shown in Auto-Pagination.

Usage-Based Billing

Ingest Usage Events

Send usage events for a customer:
The event_id is the idempotency key, so give each event a unique value. If the same event_id appears twice in one request, the whole request is rejected. If an event_id was already ingested, the new event is ignored. A request accepts up to 1,000 events. timestamp defaults to the current time and is rejected if it’s more than 1 hour in the past or more than 5 minutes in the future.

Retrieve Usage Events

Retrieve a single event by its event_id, or list events filtered by customer, event name, and time range:
usageEvents.list also accepts meter_id, and returns a paginated list.

Proxy Configuration

To send requests through a proxy, pass your runtime’s proxy settings in fetchOptions.

Node.js (Using Undici)

Pass an undici ProxyAgent as the dispatcher:

Bun

Set the proxy option:

Deno

Create an HTTP client with Deno.createHttpClient and pass it as client:

Logging

Set the log level with the logLevel client option or the DODO_PAYMENTS_LOG environment variable. The client option overrides the environment variable.
At the debug level, the SDK logs every HTTP request and response, including headers and bodies. Some authentication headers are redacted, but sensitive data in bodies may still be visible.
The log levels, from most to least verbose, are:
  • 'debug': Debug messages, info, warnings, and errors.
  • 'info': Info messages, warnings, and errors.
  • 'warn': Warnings and errors. This is the default.
  • 'error': Errors only.
  • 'off': No logging.
The SDK logs to console by default. To use pino, winston, or another logging library, pass your logger as the logger option; logLevel still controls which messages reach it. Log messages are for debugging only, and their format can change between releases.

Migration from Node.js SDK

If you use the legacy Node.js SDK, follow the migration guide to upgrade. The current SDK uses the built-in fetch API instead of node-fetch, requires Node.js 20, TypeScript 4.9, and Jest 28 or later, and includes a migration tool that updates most of your code.

View Migration Guide

Learn how to migrate from the Node.js SDK to the TypeScript SDK

Auto-Pagination

List methods return paginated results. Iterate with for await...of to get items from every page. The SDK requests the next page when it needs it:
To work with one page at a time, read page.items and call hasNextPage() and getNextPage():
To set the page size, pass page_size to the list method, for example client.payments.list({ page_size: 50 }).

Requirements

The SDK supports TypeScript 4.9 or later and these runtimes:
  • Web browsers (up-to-date Chrome, Firefox, Safari, Edge, and others)
  • Node.js 20 LTS or later (non-EOL) versions
  • Deno 1.28.0 or later
  • Bun 1.0 or later
  • Cloudflare Workers
  • Vercel Edge Runtime
  • Jest 28 or later with the "node" environment (the "jsdom" environment isn’t supported)
  • Nitro 2.6 or later
React Native isn’t supported.

Resources

GitHub Repository

Source code, releases, and the full method list.

API Reference

Every endpoint, parameter, and response.

Discord Community

Ask questions and talk with other developers.

Report Issues

Report bugs or request features.

Support

For help with the TypeScript SDK:

Contributing

To contribute, read the contributing guidelines.
Last modified on September 25, 2026