Skip to content

About

The official Whop API SDK for Rust, generated by Fern from sdks/fern in whopio/whop-monorepo.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Whop Rust Library

crates.io shield

The Whop SDK gives you typed access to the Whop API. Pass your API key to the client explicitly: the client reads no key from the environment, so a client built without a key sends unauthenticated requests and the API answers 401.

Table of Contents

Documentation

API reference documentation is available here.

Installation

Add this to your Cargo.toml:

[dependencies]
whop_sdk = "2.8.1"

Or install via cargo:

cargo add whop_sdk

The crate needs Rust 1.88 or newer. Moving from 1.x? See MIGRATING.md.

The client is generated for the whole API, so compiling it takes a lot of memory: one compile of the crate peaks near 15 GB. Turning off its debug info in your own build trims that a little:

[profile.dev.package.whop_sdk]
debug = 0

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

use whop_sdk::prelude::*;

#[tokio::main]
async fn main() {
    let config = ClientConfig {
        token: Some("<token>".to_string()),
        ..Default::default()
    };
    let client = Whop::new(config).expect("Failed to build client");
    let user = client
        .users
        .retrieve("user_xxxxxxxxxxxxx", &UsersRetrieveQueryRequest::default(), None)
        .await;
}

Environments

A client calls production unless you pick another environment. Each environment carries the URL of the API and of the vault that card details are posted to, and every request goes to the one its operation is served on:

use whop_sdk::prelude::*;

let client = ApiClientBuilder::default()
    .environment(Environment::sandbox())
    .token("<token>")
    .build()?;

A base_url you set yourself takes every request, the vault-only operations included:

let config = ClientConfig {
    base_url: "https://sandbox-api.whop.com/api/v1".to_string(),
    token: Some("<token>".to_string()),
    ..Default::default()
};

Errors

A non-success status returns the error its status declares, such as ApiError::NotFoundError, or ApiError::Http with the status for one the API does not declare.

match client.users.retrieve("user_xxxxxxxxxxxxx", &UsersRetrieveQueryRequest::default(), None).await {
    Ok(user) => println!("{user:?}"),
    Err(ApiError::NotFoundError { message, .. }) => println!("No such user: {message}"),
    Err(error) => println!("{error}"),
}

Live Reads

A read the API can stream has watch and wait_for beside it on its client (watch_<read> and wait_for_<read> for a read not named retrieve). They take exactly the read's parameters, then their own options. watch is a futures::Stream of the read's answer now and each time it changes; dropping it closes its connection:

use std::time::Duration;

use futures::StreamExt;
use whop_sdk::live::{WaitForOptions, WatchOptions};
use whop_sdk::prelude::*;

let request = StatsTimeSeriesRetrieveQueryRequest {
    account_id: Some("biz_xxxxxxxxxxxxx".to_string()),
    from: "2026-11-01".to_string(),
    to: "2026-11-30".to_string(),
    ..Default::default()
};

let mut series = client.stats.time_series.watch("gmv_usd", &request, None, WatchOptions::default());
let stop = series.stop_handle();
while let Some(answer) = series.next().await {
    println!("{:?}", answer?.data.points);
}

let series = client
    .stats
    .time_series
    .wait_for(
        "gmv_usd",
        &request,
        None,
        |series| series.data.complete == Some(true),
        WaitForOptions::default().timeout(Duration::from_secs(120)),
    )
    .await?;

stop.stop() ends the stream from any thread or task, closing its connection, and a loop waiting on it ends. WatchOptions takes max_backoff and on_disconnect; WaitForOptions also takes fail_when and timeout. A stream reconnects on its own after a drop, and ends when the read stops being live. whop_sdk::live has the details.

OIDC Federation

A workload can trade its cloud provider's OIDC identity token for a short-lived Whop access token instead of holding an API key. The client takes its token when it is built:

use whop_sdk::oidc::{self, IdentityToken};
use whop_sdk::ApiClientBuilder;

let token = oidc::access_token("aurl_xxxxxxxxxxxxx", IdentityToken::github_actions()).await?;
let client = ApiClientBuilder::default().token(token).build()?;

IdentityToken::github_actions() asks GitHub for the job's token through the ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN variables that a job with id-token: write has.

Verify a Webhook

helpers::verify_webhook checks the signature Whop sends with every webhook delivery and returns the parsed body. Pass the raw request body, its headers and the endpoint's ws_ signing secret exactly as Whop shows it:

use whop_sdk::helpers::verify_webhook;

let event = verify_webhook(&body, headers, &webhook_secret)?;
println!("{}", event["type"]);

A missing signature header, a signature that does not match, or a timestamp more than five minutes from now returns a WebhookVerificationError.

Advanced

Retries

A request is retried with exponential backoff when it answers 408, 429 or a 5xx status, up to the client's max_retries (default 3). Set it per request with RequestOptions:

let user = client
    .users
    .retrieve(
        "user_xxxxxxxxxxxxx",
        &UsersRetrieveQueryRequest::default(),
        Some(RequestOptions::new().max_retries(5)),
    )
    .await;

Additional Headers

let options = RequestOptions::new().additional_header("X-Custom-Header", "custom-value");

Additional Query String Parameters

let options = RequestOptions::new().additional_query_param("filter", "active");

Additional Body Properties

A property set here is sent as-is in a JSON or form body and overrides a field of the same name; an endpoint with no body sends a JSON object of these properties alone.

let options = RequestOptions::new().additional_body_param("beta_feature", true);

Custom Client

The SDK builds its own reqwest client unless ClientConfig.reqwest_client (or ApiClientBuilder::reqwest_client) supplies one, for custom root certificates, client certificates, proxies or connection tuning. It is used as-is; authentication, headers and retries are still the SDK's.

let reqwest_client = reqwest::Client::builder()
    .add_root_certificate(reqwest::Certificate::from_pem(&std::fs::read("ca.pem")?)?)
    .build()?;
let config = ClientConfig {
    reqwest_client: Some(reqwest_client),
    ..Default::default()
};

Contributing

This repository is built from Whop's monorepo: the client is generated from the Whop API's OpenAPI document, and every build replaces this repository's contents. Open an issue here to report a problem or ask for a change.

About

The official Whop API SDK for Rust, generated by Fern from sdks/fern in whopio/whop-monorepo.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages