Headless TypeScript client for the AnySpend Platform API
The AnySpend Platform SDK client is a headless (no React dependency) TypeScript client for the full AnySpend Platform API. It works everywhere modern JavaScript runs — Node.js, browsers, Cloudflare Workers, Deno, and Bun.
import { AnySpendPlatformClient } from "@b3dotfun/sdk/anyspend/platform";const platform = new AnySpendPlatformClient(process.env.ANYSPEND_API_KEY!, { // All options below are optional baseUrl: "https://platform-api.anyspend.com/api/v1", // default timeout: 30_000, // request timeout in ms (default: 30s) maxRetries: 3, // auto-retry count for 5xx / network errors idempotencyKeyGenerator: () => crypto.randomUUID(), // custom generator});
You can obtain an API key from the AnySpend Dashboard under Settings > API Keys. Keys are scoped to your organization and can have read-only or read-write permissions.
For convenience, every list method has a corresponding listAutoPaginate helper that returns an async iterator. It fetches pages behind the scenes as you consume items.
Copy
Ask AI
for await (const txn of platform.transactions.listAutoPaginate({ status: "completed",})) { console.log(txn.id, txn.amount);}
Auto-pagination respects rate limits automatically. If the API returns a 429, the iterator waits for the Retry-After duration before fetching the next page.
You can also collect all results into an array:
Copy
Ask AI
const allCustomers = [];for await (const c of platform.customers.listAutoPaginate()) { allCustomers.push(c);}
All POST and PATCH requests automatically include an Idempotency-Key header. This ensures that if a request is retried (due to a network error, for example), the server will not process it twice.The default generator uses crypto.randomUUID(). You can supply your own:
Copy
Ask AI
const platform = new AnySpendPlatformClient("asp_key", { idempotencyKeyGenerator: () => `my-app-${Date.now()}-${Math.random()}`,});
You can also pass a specific idempotency key per-request:
Using a deterministic idempotency key (like an order ID) is recommended for critical operations. If you accidentally send the same request twice, the second call returns the original response instead of creating a duplicate.