Whop Ruby Library
The Whop SDK gives you typed access to the Whop API. Pass your API key to the client explicitly — the SDK reads no environment variables, so a client built without a key sends unauthenticated requests and the API answers 401.
Table of Contents
- Mcp Server
- Documentation
- Installation
- Reference
- Usage
- Advanced Concepts
- Sorbet
- Versioning
- Requirements
- Environments
- Errors
- Advanced
- Contributing
MCP Server
Use the Whop MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.
Note: You may need to set environment variables in your MCP client.
Documentation
API reference documentation is available here.
Installation
To use this gem, install via Bundler by adding the following to your application's Gemfile:
gem "whop_sdk"
Reference
A full reference for this library is available here.
Usage
Instantiate and use the client with the following:
require "whop_sdk"
client = Whop_sdk::Client.new(token: "<token>")
client.access_tokens.create
Advanced concepts
BaseModel
All parameter and response objects inherit from WhopSDK::Internal::Type::BaseModel, which provides several conveniences, including:
-
All fields, including unknown ones, are accessible with
obj[:prop]syntax, and can be destructured withobj => {prop: prop}or pattern-matching syntax. -
Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
-
Both instances and the classes themselves can be pretty-printed.
-
Helpers such as
#to_h,#deep_to_h,#to_json, and#to_yaml.
Making custom or undocumented requests
Undocumented properties
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
Note: the extra_ parameters of the same name overrides the documented parameters.
page =
whop.payments.list(
company_id: "biz_xxxxxxxxxxxxxx",
request_options: {
extra_query: {my_query_parameter: value},
extra_body: {my_body_parameter: value},
extra_headers: {"my-header": value}
}
)
puts(page[:my_undocumented_property])
Undocumented request params
If you want to explicitly send an extra param, you can do so with the extra_query, extra_body, and extra_headers under the request_options: parameter when making a request, as seen in the examples above.
Undocumented endpoints
To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using client.request, like so:
response = client.request(
method: :post,
path: '/undocumented/endpoint',
query: {"dog": "woof"},
headers: {"useful-header": "interesting-value"},
body: {"hello": "world"}
)
Concurrency & connection pooling
The WhopSDK::Client instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
Each instance of WhopSDK::Client has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
Sorbet
This library provides comprehensive RBI definitions, and has no dependency on sorbet-runtime.
You can provide typesafe request parameters like so:
whop.payments.list(company_id: "biz_xxxxxxxxxxxxxx")
Or, equivalently:
# Hashes work, but are not typesafe:
whop.payments.list(company_id: "biz_xxxxxxxxxxxxxx")
# You can also splat a full Params class:
params = WhopSDK::PaymentListParams.new(company_id: "biz_xxxxxxxxxxxxxx")
whop.payments.list(**params)
Enums
Since this library does not depend on sorbet-runtime, it cannot provide T::Enum instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
# :b2b_app
puts(WhopSDK::AppType::B2B_APP)
# Revealed type: `T.all(WhopSDK::AppType, Symbol)`
T.reveal_type(WhopSDK::AppType::B2B_APP)
Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
# Using the enum constants preserves the tagged type information:
whop.apps.update(
app_type: WhopSDK::AppType::B2B_APP,
# …
)
# Literal values are also permissible:
whop.apps.update(
app_type: :b2b_app,
# …
)
Versioning
This package follows SemVer conventions. As the library is in initial development and has a major version of 0, APIs may change at any time.
This package considers improvements to the (non-runtime) *.rbi and *.rbs type definitions to be non-breaking changes.
Requirements
Ruby 3.2.0 or higher.
Environments
This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
Environments
require "whop_sdk"
whop_sdk = Whop_sdk::Client.new(
base_url: Whop_sdk::Environment::DEFAULT
)
Custom URL
require "whop_sdk"
client = Whop_sdk::Client.new(
base_url: "https://example.com"
)
Errors
Failed API calls will raise errors that can be rescued from granularly.
require "whop_sdk"
client = Whop_sdk::Client.new(
base_url: "https://example.com"
)
begin
result = client.access_tokens.create
rescue Whop_sdk::Errors::TimeoutError
puts "API didn't respond before our timeout elapsed"
rescue Whop_sdk::Errors::ServiceUnavailableError
puts "API returned status 503, is probably overloaded, try again later"
rescue Whop_sdk::Errors::ServerError
puts "API returned some other 5xx status, this is probably a bug"
rescue Whop_sdk::Errors::ResponseError => e
puts "API returned an unexpected status other than 5xx: #{e.code} #{e.}"
rescue Whop_sdk::Errors::ApiError => e
puts "Some other error occurred when calling the API: #{e.}"
end
Advanced
Retries
The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
The retryStatusCodes configuration controls which 5XX status codes are retried:
legacy(default): Retries408,429,500,502,503,504,521,522,524recommended: Retries408,429,502,503,504only (excludes500 Internal Server Errorto avoid retrying non-idempotent failures)
Use the max_retries option to configure this behavior.
require "whop_sdk"
client = Whop_sdk::Client.new(
base_url: "https://example.com",
max_retries: 3 # Configure max retries (default is 2)
)
Timeouts
The SDK defaults to a 60 second timeout. Use the timeout option to configure this behavior.
require "whop_sdk"
response = client.access_tokens.create(
...,
timeout: 30 # 30 second timeout
)
Additional Headers
If you would like to send additional headers as part of the request, use the additional_headers request option.
require "whop_sdk"
response = client.access_tokens.create(
...,
request_options: {
additional_headers: {
"X-Custom-Header" => "custom-value"
}
}
)
Additional Query Parameters
If you would like to send additional query parameters as part of the request, use the additional_query_parameters request option.
require "whop_sdk"
response = client.access_tokens.create(
...,
request_options: {
additional_query_parameters: {
"custom_param" => "custom-value"
}
}
)
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!