TypeScript
The official TypeScript server SDK for the Bias API. It ships with fully typed resources and parameters, type-safe expansion generics, cursor pagination, async-iterator event streaming, and idiomatic error handling. The package is generated from the Bias OpenAPI specification.
Installation
Requires a JavaScript runtime with a global fetch implementation — Node.js 18+, Bun, Deno, or any modern browser.
Usage
Construct a client with your API key and call resource methods directly. Models are returned as fully typed objects.
Pagination
List methods return a page object with object: "list", an items array, and a has_more boolean. Pass starting_after (the last item’s id) to fetch the next page.
Single page
To walk every page transparently, pass the list method to iterateListPages. It yields each page in turn, following the cursor until has_more is false.
Auto pagination
If you want every item collected into a single list, use fetchListPages. Pass maxItems to limit the total length.
Expanding related objects
Pass an expand parameter to inline related objects instead of receiving bare IDs. The object shape mirrors the resource tree, and the return type is narrowed to the expanded form automatically — no casts required. See expansion for the full list of expandable fields.
Nested expansions are typed too — pass an object instead of true to expand deeper.
If a field was not expanded, assertExpanded narrows it at runtime and throws a BiasError if it is still an id string. Use getId to accept either an id or an object holding an id.
Streaming events
The events resource can return a long-lived stream of events instead of a single page. Set stream: true and treat the result as an async iterator; heartbeats sent to keep the connection alive are skipped automatically.
See the event streaming guide for more.
Error handling
API errors are returned, not thrown — they are part of every method’s return type as a discriminated union with object: "error". Narrow on object before reading the result.
Every error object exposes error.type, error.message, error.param, and error.code. The error.type discriminates the category:
| Error type | Happens when |
|---|---|
invalid_request_error | The request was malformed, failed validation, or referenced a missing resource (400/404/422). |
payment_error | A payment was declined or could not be processed. |
idempotency_error | An idempotency key was reused with a different request. |
rate_limit_error | Too many requests (429). |
server_error | The API returned a 5xx response. |
Client-side failures — no API key, no fetch implementation, or an unexpected request parameter — throw a BiasError. Network and timeout failures throw the underlying fetch error (or an AbortError when the request exceeds the timeout). Wrap calls in try/catch to handle these.
Idempotency
Every POST and PATCH request automatically sends an idempotency-key header, generated as a UUID. To reuse a key across retries, pass idempotencyKey in the request config.
See idempotency for details.
Configuration
Pass a Config object as the second argument to the constructor to override defaults.
To customize transport, inject your own fetch implementation:
| Option | Default | Description |
|---|---|---|
baseURL | https://api.biaspay.com | API base URL. |
timeout | 30_000 | Max request duration in milliseconds before aborting. |
networkRetries | 1 | Number of retries on 429 and 5xx responses. |
headers | {} | Additional headers sent with every request. |
fetch | globalThis.fetch | A custom fetch implementation. |
Resources
The client exposes every API resource as a typed namespace. Each method maps to an API reference endpoint.
| Resource | Methods |
|---|---|
checkoutSessions | create, publicKey, get, update, list, expire |
creditNotes | create, list, get, update, void |
customers | create, list, delete, get, update |
discounts | create, list, delete, get, update |
disputes | get, update, list |
events | get, list |
files | get, update, list, create, view |
invoices | create, list, delete, get, update, finalize, markPaid, markUncollectible, pdf, receipt, send, void |
paymentMethods | get, update, list, deactivate |
payments | create, list, get, update, capture, cancel |
prices | create, list, get, update |
products | create, list, delete, get, update |
refunds | get, list, create |
requests | get |
stats | (params) |