Skip to main content
The Rust SDK gives async Rust applications typed access to the Dodo Payments REST API. It’s built on Tokio and reqwest, uses typed request and response structs, streams paginated results, and retries failed requests.

Installation

Add the SDK to your project with Cargo:
Or add it to your Cargo.toml manually:
The SDK requires Rust 1.75 or later.

Quick Start

Client::from_env() reads your API key from the DODO_PAYMENTS_API_KEY environment variable. Create a client, then create a checkout session:
If DODO_PAYMENTS_API_KEY isn’t set, Client::from_env() returns an Error::Config. The client connects to live mode unless you choose another environment, as shown in Environments. A test mode API key works only in test mode.
Keep API keys in environment variables or a secrets manager. Never hardcode them in your source code.

Core Features

Async First

Built on Tokio and reqwest, with async/await for every request.

Strong Typing

Typed request and response structs for compile-time checks.

Auto-Pagination

Stream every item across pages, or move one page at a time.

Configurable

Set the environment, base URL, timeout, and retry count for each client.

Configuration

Environment Variables

Client::from_env() reads your API key from DODO_PAYMENTS_API_KEY. It uses the live mode URL unless you set DODO_PAYMENTS_BASE_URL:
The Rust SDK doesn’t read DODO_PAYMENTS_WEBHOOK_KEY and has no method that verifies webhook signatures. To verify them, follow Webhooks. You can also configure the client explicitly. Client::new returns a Result, so unwrap it with ? inside a function that returns dodopayments::Result:

Environments

The SDK has two environments: The default base URL is https://live.dodopayments.com. To select another environment, use the Environment enum instead of a hard-coded URL:
To keep reading the API key from DODO_PAYMENTS_API_KEY with from_env() but target another environment, override the environment on the config:

Timeouts

The default request timeout is 30 seconds. Override it for a client with with_timeout:
The client retries connection errors and responses with status 408, 409, 429, or 500 and above. It retries twice by default, with exponential backoff, and waits for the Retry-After header when the API sends one. To change the retry count, call with_max_retries on the ClientConfig, for example .with_max_retries(0) to turn retries off.

Common Operations

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

Create a Checkout Session

Create a checkout session with a return URL:
Redirect the customer to session.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 for an existing customer.
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 CountryCode enum variant such as CountryCode::Us. customer is a CustomerRequest enum: pass AttachExistingCustomer for an existing customer or NewCustomer to create one. To charge an on-demand subscription, call client.subscriptions().charge().subscription_id(...) with a SubscriptionsChargeParams body. Amount fields such as product_price are in the smallest currency unit (for example, 2500 is $25.00).

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 timestamp is None, the event uses the current time.

List Usage Events

List events filtered by customer and event name. The filters go in a JSON query object:

Pagination

List endpoints return a typed page whose items field holds the current page of results. To stream every item across all pages, call into_stream:
To move one page at a time, call get_next_page. It returns None after the last page:

Error Handling

Every method returns a dodopayments::Result<T>. Failures are variants of the dodopayments::Error enum: Api for an error status from the API, Http for transport errors, Json for serialization errors, Config for configuration errors, and MissingPathParam or MissingBody for incomplete requests. Match on it to handle API errors separately from transport errors:

Undocumented Endpoints

To call an endpoint that has no typed method, use the low-level request builder. It applies authentication and the base URL. To name reqwest::Method, add reqwest 0.12 to your dependencies:

Resources

GitHub Repository

Source code, releases, and the full method list.

Crates.io

The published crate and its versions.

API Reference

Every endpoint, parameter, and response.

Discord Community

Ask questions and talk with other developers.

Support

For help with the Rust SDK:

Contributing

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