Authentication
API key types and request authentication.
BillStack API routes use Bearer tokens. There are two kinds of private Bearer token, with different jobs:
| Credential | Prefix | Job |
|---|---|---|
| Project API key | bs_test_, bs_live_ | Runtime. Your app's server (and the SDK) calls checkout, portal, entitlements, subscriptions, customers, payment methods, referrals, webhook endpoints, and invoice and catalog reads. |
| Personal access token | bsu_test_, bsu_live_ | Setup. You, your scripts and your coding agent list and create projects, and create, update, archive, link and publish products and prices. |
Private API keys
Private API keys are server-only keys for your app's runtime calls.
Authorization: Bearer <private-api-key>Keep private keys in server environment variables only.
Changed on 2026-12-01. A secret key created from now on is an app-runtime key. It cannot write the catalog (create, update, archive or publish products and prices), change projects, or manage API keys, IAM and provider connections. A refused catalog write or project create returns 403 with the code USER_TOKEN_REQUIRED; repeat it with a personal access token. Other refused calls return a plain 403. Keys created before this date keep working unchanged and are shown as Full access (legacy) in the dashboard; a team admin can restrict one with Restrict to app runtime. See API keys.
Personal access tokens
A personal access token (bsu_test_<48 hex> or bsu_live_<48 hex>) is the setup credential. It authenticates as the person who created it, limited to one team or one project. Its permissions are that person's current permissions in the team, and it stops working when they leave the team. Older unscoped bsu_<48 hex> tokens have been invalidated; create a replacement under Account > Access tokens.
Authorization: Bearer bsu_test_...Create one under Account > Access tokens. A new token is fixed to the selected environment; the UI defaults to Test and offers Live only for a team with Live enabled. An X-BillStack-Environment header, v2 mode, or MCP environment argument cannot switch a personal token to the opposite environment; use a matching token instead. A token limited to a project is refused on other projects and on team-wide endpoints. Both v1 and v2 routes that accept a private API key accept a token, as does the MCP server. Listing and creating projects (GET and POST /v2/teams/{teamId}/projects) accepts only a dashboard session or a whole-team token. Dashboard and MCP OAuth sessions keep their existing environment behavior. See Personal access tokens.
Test and live environments
Keys carry their environment in the prefix: bs_test_ / pk_test_ for test, bs_live_ / pk_live_ for live. Legacy bs_ and pk_ keys without an environment segment are live keys. A key only reads and writes data of its own environment; there is no per-request switch. See API keys.
Publishable keys
Publishable keys are read-only keys for browser-safe public endpoints.
Authorization: Bearer <publishable-key>or:
?pk=<publishable-key>Use publishable keys only for endpoints explicitly documented as public.
Project scope
Most routes include both teamId and projectId. v2 (recommended):
/api/billstack/v2/teams/{teamId}/projects/{projectId}/...Legacy (v1), for integrations that already call it:
/api/billstack/teams/{teamId}/projects/{projectId}/...The project ID scopes customers, prices, subscriptions, referrals, invoices, entitlements, and portal sessions.
Errors
Common auth errors:
| Status | Meaning |
|---|---|
401 | Publishable key is missing or invalid for a public endpoint. A personal access token that is unknown, revoked, expired or invalidated (INVALID_ACCESS_TOKEN, ACCESS_TOKEN_EXPIRED) |
403 | Private API key is missing, invalid, expired, revoked, or not allowed. USER_TOKEN_REQUIRED: a project API key tried a setup call (catalog write or project list or create) that needs a personal access token. A personal access token for another team or project, from someone who is no longer a member, or without the permission. A live key for a team with no live environment returns code LIVE_ENVIRONMENT_NOT_ENABLED |
404 | The resource does not exist in this project |