Authenticated access to the Stripe REST API: form encoding, the Stripe-Version / Idempotency-Key / Stripe-Account headers, error handling, and auto-pagination. The typed modules (::stripe::customers, ::stripe::payment-intents, ...) are built on call; use it directly for any endpoint they don't cover.
Per-call credentials. Every API-calling function takes an optional trailing options argument, a Map or a RequestOptions, resolved by resolve: options first, then the stripe.* context variables, then the defaults. Nothing from it is written to ctx, and a per-call key is masked in call records, so one run can act for many Stripe accounts.
api-key: the secret or restricted key for this callapi-version: theStripe-Versionfor this callstripe-account: the connected account to act for (Connect)idempotency-key: theIdempotency-Keyfor this write
An api-key, stripe-account or idempotency-key that is present but blank or null is an Err naming the key, never a fallback: a tenant whose key is missing must not run on the project's account, and a retry whose key is missing must not charge twice.
Context Vars
stripe.api.keystripe.api.version
Values
OPTION_KEYS
OPTION_KEYS: Map {
api_key: "api-key",
idempotency_key: "idempotency-key",
stripe_account: "stripe-account",
stripe_version: "api-version"
}
REQUIRED_WHEN_PRESENT
REQUIRED_WHEN_PRESENT: Vec [
"api-key",
"stripe-account",
"idempotency-key"
]
Functions
api-version
fn (): Str
The Stripe-Version sent when a call doesn't override it: the
stripe.api.version context variable when set, otherwise
::stripe/API_VERSION.
Example
// The version a call sends unless its options override it
version ::stripe::api/api-version()
stripe.api.version
blank-option
fn (opts: Map, names: Vec): Str?
The first of names that opts has with a blank or null value, else
null.
Example
::stripe::api/blank-option({stripe-account: " "}, ["api-key", "stripe-account"]) // "stripe-account"
::stripe::api/blank-option({stripe-account: "acct_123"}, ["api-key", "stripe-account"]) // null
build-request
fn (method: Str, url: Str, additional-headers: Map, body: Any, api-key: Str): ::hot::http/HttpRequest
fn (method: Str, url: Str, additional-headers: Map, body: Any, resolved: Map): ::hot::http/HttpRequest
Build (without sending) the HttpRequest for a Stripe call. GET and DELETE parameters go in the query string and POST parameters in a form-encoded body, as Stripe's SDKs do. Every request carries Authorization and Stripe-Version; additional-headers are merged last, so they can override either.
Example
req ::stripe::api/build-request("POST", `${::stripe/BASE_URL}/v1/customers`, {Idempotency-Key: "k1"}, {name: "Alice"}, "sk_test_123")
req.headers.Stripe-Version // => "2026-10-28.endive"
req.body // => "name=Alice"
call
fn (method: Str, path: Str): Any
fn (method: Str, path: Str, params: Any): Any
fn (method: Str, path: Str, params: Any, options: RequestOptions | Map): Any
Call a Stripe endpoint by path (relative to ::stripe/BASE_URL) and return the decoded JSON body, or an Err carrying HttpError for non-2xx responses. params are sent as the query string for GET/DELETE and as the form body for POST; null values are omitted. options is a Map or RequestOptions with the call's key, version, Connect account and idempotency key (see resolve).
Example
// Endpoints without a typed wrapper
clock ::stripe::api/call("POST", "/v1/test_helpers/test_clocks", {frozen_time: 1767225600})
::stripe::api/call("DELETE", `/v1/test_helpers/test_clocks/${clock.id}`)
// With an idempotency key
::stripe::api/call("POST", "/v1/customers", {email: "alice@example.com"},
::stripe::api/RequestOptions({idempotency_key: "signup-alice"}))
// For another account
::stripe::api/call("GET", "/v1/balance", "", {api-key: "sk_test_tenant"})
encode-id
fn (id: Str): Str
Percent-encode an object ID for use as a URL path segment, so an ID taken from user input can't change which endpoint is called.
Example
::stripe::api/encode-id("cus 1/2") // "cus%201%2F2"
form-encode
fn (data: Map): Str
Encode a Map as application/x-www-form-urlencoded using Stripe's bracket syntax: nested maps become metadata[order_id]=6735 and arrays become expand[0]=customer. Null values are omitted. Stripe does not accept JSON request bodies.
Example
::stripe::api/form-encode({amount: 2000, currency: "usd", metadata: {order_id: "6735"}})
// => "amount=2000¤cy=usd&metadata%5Border_id%5D=6735"
list-all
fn (path: Str): Vec
fn (path: Str, params: Map): Vec
fn (path: Str, params: Map, max-items: Int): Vec
fn (path: Str, params: Map, max-items: Int, options: RequestOptions | Map): Vec
Auto-paginate a list or search endpoint: follows has_more (with starting_after, or page for /search endpoints) and returns every object as one Vec. max-items caps the total (default 1000; 0 means no cap). Pages are fetched 100 at a time unless params.limit says otherwise. An error on any page returns that page's Err.
Example
// Every active subscription for a customer
subs ::stripe::api/list-all("/v1/subscriptions", {customer: "cus_...", status: "active"})
// Search results, capped at 250
hits ::stripe::api/list-all("/v1/customers/search", {query: `email:"alice@example.com"`}, 250)
// For another account
subs ::stripe::api/list-all("/v1/subscriptions", {}, 1000, {api-key: "sk_test_tenant"})
next-page-params
fn (params: Map, page: Map): Map?
The params for the page after page, or null when page is the last one. List pages (object: "list") continue with starting_after set to the last object's ID (or ending_before with the first, when paging backwards); search pages (object: "search_result") continue with page: next_page.
Example
::stripe::api/next-page-params({limit: 2}, {object: "list", has_more: true, data: [{id: "cus_1"}, {id: "cus_2"}]})
// => {limit: 2, starting_after: "cus_2"}
option-headers
fn (options: RequestOptions | Map): Map
The headers an options value adds to a request: Idempotency-Key, Stripe-Account, and Stripe-Version (only those that are set).
Example
::stripe::api/option-headers(::stripe::api/RequestOptions({idempotency_key: "k1"}))
// => {Idempotency-Key: "k1"}
query-string
fn (params: Map): Str
Build a query string (?limit=10&starting_after=cus_123) from a Map.
Null values are omitted; returns an empty string when no parameters
remain. Uses the same bracket syntax as form-encode, so expand: ["customer"] becomes expand[0]=customer.
Example
::stripe::api/query-string({limit: 10, email: null}) // "?limit=10"
::stripe::api/query-string({expand: ["customer"]}) // "?expand%5B0%5D=customer"
::stripe::api/query-string({}) // ""
request
fn (method: Str, url: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, api-key: Str): ::hot::http/HttpResponse
fn (method: Str, url: Str, additional-headers: Map, body: Any, options: RequestOptions | Map): ::hot::http/HttpResponse
Make an authenticated HTTP request to the Stripe API and return the raw HttpResponse. Supports multiple arities for convenience.
The API key comes from stripe.api.key by default, or from the 5-arity form: a key, or an options Map or RequestOptions (see resolve). Stripe-Version is always sent. Additional headers are merged over the defaults.
A url outside ::stripe/BASE_URL needs an api-key in the call: stripe.api.key is only ever sent to Stripe.
Parameters are form-encoded with Stripe's bracket syntax (see form-encode): in the body for POST, in the query string for GET and DELETE.
Prefer call, which also unwraps the body and turns non-2xx responses into err(HttpError).
Example
// GET request — fetch balance
response ::stripe::api/request("GET", `${::stripe/BASE_URL}/v1/balance`)
response.status // => 200
response.body.available // => [{amount: 1000, currency: "usd"}]
// POST request — create a customer (body is form-encoded automatically)
response ::stripe::api/request("POST", `${::stripe/BASE_URL}/v1/customers`, {}, {name: "Alice Smith"})
// With an explicit API key
response ::stripe::api/request("GET", `${::stripe/BASE_URL}/v1/balance`, {}, "", "sk_test_...")
response ::stripe::api/request("GET", `${::stripe/BASE_URL}/v1/balance`, {}, "", {api-key: "sk_test_..."})
resolve
fn (options: RequestOptions | Map): Map
Credentials and settings for one call (see resolve-from). The API key is masked in this run's call records, and nothing from options is written to ctx.
Example
::stripe::api/resolve({api-key: "sk_test_tenant"}).api-version // => "2026-10-28.endive"
stripe.api.key, stripe.api.version
resolve-from
fn (options: RequestOptions | Map, ctx-values: Map): Map
The one resolver, pure: {api-key, api-version}, plus stripe-account
and idempotency-key when set, from options first, then ctx-values
(a Map of context variables), then ::stripe/API_VERSION. An Err when
no API key is set, or when api-key, stripe-account or
idempotency-key is in options but blank or null. Exposed for
testing; resolve feeds it the context.
Example
ctx-values {"stripe.api.key": "key-1"}
::stripe::api/resolve-from({stripe-account: "acct_123"}, ctx-values).api-key // "key-1"
::stripe::api/resolve-from({stripe-account: "acct_123"}, ctx-values).stripe-account // "acct_123"
is-err(::stripe::api/resolve-from({stripe-account: ""}, ctx-values)) // true
to-opts
fn (options: RequestOptions | Map): Map
The options Map for a RequestOptions or a Map. RequestOptions field names become their Map keys. An unset record field is simply absent; a Map key set to null stays present, so resolve can refuse it.
Example
::stripe::api/to-opts(::stripe::api/RequestOptions({idempotency_key: "k1"}))
// => {idempotency-key: "k1"}
Types
HttpError
HttpError type {
status: Int,
headers: Map,
body: Any
}
Represents an error response from the Stripe API. Wraps the HTTP status code, response headers, and error body returned by a failed request. Stripe's structured details (type, code, message, param, ...) are in body.error; see ::stripe/Error.
Example
response ::stripe::api/request("GET", `${::stripe/BASE_URL}/v1/balance`)
error ::stripe::api/HttpError(response)
error.status // => 401
error.body.error.type // => "invalid_request_error"
RequestOptions
RequestOptions type {
api_key: Str?,
idempotency_key: Str?,
stripe_account: Str?,
stripe_version: Str?
}
Per-request options, the typed form of the options Map every API-calling function takes last (see this namespace's doc). Field names match Stripe's official SDKs; in a plain Map use api-key, api-version, stripe-account and idempotency-key. The two forms mean the same thing.
api_key: the secret or restricted key for this call, instead ofstripe.api.key.idempotency_key: sent asIdempotency-Key. Stripe returns the stored result for a repeated key (within 24 hours) instead of performing the write again, so a retried create/confirm/capture/refund can never double-charge. Use a value tied to your own record, e.g.order-42-charge. Only POST requests use it.stripe_account: sent asStripe-Accountto act on behalf of a connected account (Connect).stripe_version: overrides theStripe-Versionfor this call.
Example
::pi ::stripe::payment-intents
request ::pi/CreatePaymentIntentRequest({amount: 2000, currency: "usd"})
::pi/create-payment-intent(request, ::stripe::api/RequestOptions({idempotency_key: "order-42-payment"}))
// The same call for another account, as a Map
::pi/create-payment-intent(request, {api-key: "sk_test_tenant", idempotency-key: "order-42-payment"})