Skip to main content
Use @unprice/api to put the customer money path inside your server request path: create or map a customer, check access, consume usage, reserve budgeted runs, inspect wallet credits, and explain usage or ingestion evidence. The SDK returns typed results instead of throwing for expected API errors, so every request has an explicit result or error branch.

Install

Unprice API key

Create a project API key in the project settings, then provide it to the client from server-side code:
Always keep your API key on the server and reset it if you suspect it has been compromised.

First runtime call

For a read-only shadow check:
For request-path enforcement when the usage amount is known:
Read Choose the runtime call before wiring a production path.

Response format

Every method returns either an error or a result field, never both and never neither.

Checking for errors

Check the error property before using result. API errors include a docs link and request ID for support lookup.

Options

The constructor accepts some options to customize the behavior:

Base Url

Run all requests against your own Unprice instance.
string
default:"https://api.unprice.dev"

Retries

By default the client will retry on network errors, you can customize this behavior:

Cache

Configure the fetch cache behavior.
As of October 2023, the cache option is not yet implemented in cloudflare workers and will throw an error if used.
string
Available options are: default, force-cache, no-cache, no-store, only-if-cached or reload.

Disable telemetry

By default, Unprice collects anonymous telemetry data to help us understand which versions of our SDK is being used, and in which environment. If you wish to disable this, you can do so by passing a boolean flag to the constructor: