Skip to main content
Use @unprice/api in your server request path to authorize customer spend before paid work runs. Create or map a customer, check access, consume usage, reserve a workload budget, and inspect usage or wallet evidence. The SDK returns typed results for expected API failures. Each call returns either result or error.

Install

Configure the client

Create a project API key in the project settings. Keep the key in server-side configuration. Do not send it to a browser or commit it to a repository.
Rotate the key if you believe it was exposed.

First runtime call

Use access.check for a read-only shadow check:
Use usage.consume when known usage must be authorized before paid work runs:
For variable provider usage — an LLM call whose cost is not known until it returns — hold a maximum before the work and settle what it actually cost after:
reservations is a helper over the runs operations, not a separate API. Read the reservations helper for what each call maps to, and use runs.start / runs.consume / runs.settle / runs.end directly for multi-step workloads. Read Choose the runtime call before you connect a production path.
The client also carries the budget client: unprice.budgets and unprice.budget(key). It is published on its own as @unprice/budgets. See Unprice Budgets.

Response format

Every method returns one of these shapes:
Check error before you use result. The error includes a documentation link and request ID.

Client options

Base URL

Use baseUrl to send requests to your own Unprice deployment.
string
default:"https://api.unprice.dev"

Retries

The SDK retries network and server errors by default. Configure the retry count and backoff when your request path needs a different policy.

Cache

Use cache to configure the standard fetch cache behavior for SDK requests.
string
Use a RequestCache value such as default, no-store, or reload.

Disable telemetry

By default, the SDK sends anonymous telemetry: runtime, platform, and SDK version. Set disableTelemetry to disable this telemetry.