API Keys
Create and use project API keys for your app's server-side BillStack calls. Setup work uses a personal access token.
Project API keys are the runtime credential: your product app's server uses one for checkout, the customer portal, entitlements, subscriptions and customers. Creating or changing products, prices and projects is setup work and needs a personal access token instead.
Changed on 2026-12-01. New secret keys (bs_test_, bs_live_) are app-runtime keys. They can no longer create, change or archive products and prices, change projects, or manage API keys and IAM; those calls return 403 USER_TOKEN_REQUIRED. Create products and prices with a personal access token (bsu_), which acts as you. Keys created before this date keep working unchanged and show Full access (legacy). A team admin can narrow one with Restrict to app runtime. The scopes field on key creation is ignored, and the dashboard no longer offers a scopes checklist.
API keys belong to a team and are usually limited to one project. You create them from the project's Settings > Keys page. The team Settings > API Keys page lists every key of the team with its project, environment and access. Keys need the API key permission (apikey:ListApiKeys to see the pages, apikey:CreateApiKey and apikey:RevokeApiKey to change keys). They are not in your Account settings. If you need a credential that acts as you, for a script, a coding agent or an MCP client, create a personal access token instead.
The v2 API uses the same private key as a Bearer token. See Multi-provider v2 API reference for its versioned routes.
Test and live keys
Every key belongs to one environment, and the prefix tells you which:
| Key | Prefix | Sees |
|---|---|---|
| Private test key | bs_test_ | Test data only, through your test payment-provider account |
| Private live key | bs_live_ | Live data only, through your live payment-provider account |
| Publishable test key | pk_test_ | Test data, public endpoints |
| Publishable live key | pk_live_ | Live data, public endpoints |
A test key can never read or write live data, and a live key can never read or write test data. There is no environment switch on a request: the key decides. Customers, products, prices, subscriptions, invoices, checkouts, portal sessions, entitlements and referrals created with a test key stay in the test environment.
- Keys created before environments existed (
bs_orpk_followed directly by hex characters) keep working unchanged and are live keys. - A team that has not been promoted to live yet only has a test environment. A live key for such a team is refused with
LIVE_ENVIRONMENT_NOT_ENABLED, and the dashboard will not create one. - In v2, a
modeyou send must match the key's environment. A test key that asks formode: "live"gets403 ENVIRONMENT_MISMATCH; omitmodeand the key's environment is used. The same applies the other way round: a live key that sendsmode: "test"gets403 ENVIRONMENT_MISMATCH, so send test traffic with abs_test_key. - The synced Stripe mirror endpoints (customers, invoices, payments, payouts, metrics and similar under
/stripe/...) and the matching MCP tools read the mirror of the key's environment: a test key sees your Stripe account's test-mode data (filled by the/api/webhooks/stripe/{teamId}/testwebhook and a test-mode backfill), a live key sees live data.
How API keys work
- New keys are prefixed with
bs_test_orbs_live_followed by hex characters - The raw key is shown once at creation — store it securely
- Keys are SHA-256 hashed before storage
- Keys belong to one project (or, for older keys, the whole team)
- Keys can have optional expiration dates
- New secret keys are marked as app-runtime keys (see What a key can do)
Create an API key
Dashboard
- Open your project, then Project > Keys
- Click Create secret key (or Create publishable key). The key is created in the environment you are viewing
- Copy the raw key and the env line (
BILLING_PORTAL_API_KEY=...) immediately
Only team admins can create, restrict or revoke API keys. Members with the Developer role can see the key list but not create keys; they can create a personal access token instead.
New secret keys are app runtime keys: they take payments and read the catalog, but cannot create or change products, prices or projects. See What a key can do. Keys created before this split are labelled Full access (legacy); see Legacy keys.
API
curl -X POST "https://billing.w3dev.app/api/billstack/teams/{teamId}/api-keys" \
-H "Content-Type: application/json" \
-H "Cookie: <session-cookie>" \
-d '{
"name": "My SaaS Production",
"projectId": "proj_abc123",
"environment": "test"
}'environment is test or live. Leave it out to use the environment of the dashboard page you create the key from (/v2/{team}/test/... is test, /v2/{team}/... is live; the legacy dashboard uses the same split under /dashboard/{team}); the dashboard creates keys in the environment you are viewing. scopes is ignored: a new secret key is always an app-runtime key. See Test and live environments. Add "kind": "publishable" for a pk_ key. The rawKey field is only returned in the creation response, and the response carries the key's environment.
Use the key
const response = await fetch(
`${BILLING_PORTAL_URL}/api/billstack/v2/teams/${TEAM_ID}/projects/${PROJECT_ID}/customers`,
{
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
},
);See Authentication for private vs publishable key rules, and Personal access tokens for the user-owned bsu_ Bearer token. The same key also works on the legacy routes under /api/billstack/teams/{teamId}/projects/{projectId}/..., which existing integrations still call; use the private bs_ Bearer key with the v2 API reference for anything new.
What a key can do
A new secret key carries an internal profile:runtime marker. It is not a scope you choose and the dashboard never shows it as one. A key with the marker is limited to this policy, whichever other policies are attached to it:
| Allowed | Actions |
|---|---|
| Payments and customers | checkout:*, portal:*, entitlement:*, subscription:*, customer:*, paymentMethod:*, referral:* |
| Reads | Invoices, products and prices (List*, Get*), project:GetProject, project:ListProjects, team:GetTeam, billing:GetProviders, analytics:GetAnalytics, BillingQL (query:Execute), diagnostics:GetProjectDiagnostics |
| Billing settings | billing:GetBilling and billing:UpdateBilling, which cover webhook endpoint registration and the native sandbox simulate and test-clock routes |
| Always denied | Actions |
|---|---|
| Catalog writes | product:Create*, product:Update*, product:Delete*, price:Create*, price:Update*, price:Delete* |
| Projects | project:CreateProject, project:UpdateProject, project:DeleteProject |
| Keys and access | apikey:*, iam:*, team:Update*, team:Delete*, team:TransferOwnership |
| Provider setup | billing:ManageProviders, billing:ManagePaymentProvider, billing:ConnectStripe, billing:DisconnectStripe, billing:BackfillStripe, billing:PromoteEnvironment, billing:ManageSandboxes |
| Invoice actions | invoice:VoidInvoice, invoice:MarkUncollectible, invoice:BackfillInvoices |
An explicit deny wins over any allow, so attaching the Admin policy to a runtime key does not bring these actions back. A refused catalog write returns 403 with the code USER_TOKEN_REQUIRED and the message "Project API keys cannot change products, prices or projects. Use a personal access token (bsu_) for setup."
Project provider setup (PUT .../providers), invoice backfills and the routing rule and routing settings writes check the denied actions above, so a runtime key is refused there with a plain 403. A few older project routes check only that the key belongs to the project, not an individual action (for example the referral program configuration). Use a runtime key for the calls in your app and do not rely on the marker to block every admin-like route.
Legacy keys (full access)
A key created before 2026-12-01 has no marker. It keeps working unchanged with an admin-equivalent fallback when it has no IAM attachments, and the dashboard labels it Full access (legacy). To narrow one, a team admin opens Settings > API Keys and clicks Restrict to app runtime, then confirms. The secret stays the same, only its access changes, and it cannot be undone. Anything that still uses a legacy key to write the catalog must move to a personal access token first. Calling the restrict route again on a restricted key changes nothing.
To restrict by API, call POST /api/billstack/teams/{teamId}/api-keys/{keyId}/restrict with a signed-in team admin session. It answers 200 with the key, 404 API_KEY_NOT_FOUND for an unknown, other-team or revoked key, and 400 PUBLISHABLE_KEY for a publishable key.
Payout request and partner session routes (.../referrals/payouts*, .../referrals/partner-portal/sessions) are checked against the IAM actions referral:ListPayouts, referral:ReviewPayout and referral:CreatePartnerSession, which referral:* covers. Partner sessions need a live key.
Catalog permissions
The project catalog routes check product:* and price:* IAM actions, for API keys, personal access tokens and dashboard sessions alike. App-runtime keys pass the read rows and fail the write rows with USER_TOKEN_REQUIRED; write with a personal access token. Paths are relative to /api/billstack/v2/teams/{teamId}/projects/{projectId} (v2, recommended) and /api/billstack/teams/{teamId}/projects/{projectId} (legacy v1).
| Route | IAM actions |
|---|---|
GET /products, GET /v2/.../catalog/products | product:ListProducts |
GET /products/{productId} | product:GetProduct |
POST /products, POST /v2/.../catalog/products | product:CreateProduct |
PATCH /products/{productId}, PATCH /v2/.../catalog/products/{productId} | product:UpdateProduct |
DELETE /products/{productId} (deprecated) | product:DeleteProduct and price:DeletePrice (it also deletes the product's prices) |
GET /prices, GET /v2/.../catalog/price-variants | price:ListPrices |
GET /prices/{priceId}, GET /prices/resolve | price:GetPrice |
POST /prices, POST /v2/.../catalog/price-variants | price:CreatePrice |
PATCH /prices/{priceId}, POST /v2/.../catalog/price-variants/{priceVariantId}/links | price:UpdatePrice |
DELETE /prices/{priceId} (deprecated) | price:DeletePrice |
POST /v2/.../catalog/products/{productId}/archive | product:UpdateProduct and price:UpdatePrice |
POST /v2/.../catalog/price-variants/{priceVariantId}/archive | price:UpdatePrice |
POST /v2/.../catalog/price-variants/{priceVariantId}/publish | price:CreatePrice |
POST /prices/{priceId}/archive-and-replace | price:CreatePrice and price:UpdatePrice |
GET /tiers | product:ListProducts and price:ListPrices |
POST /tiers, POST /tiers/from-template | product:CreateProduct and price:CreatePrice |
GET /tiers/public takes a publishable key and is unchanged. Lifetime deal campaigns create their own step prices; creating or editing a campaign still needs project:UpdateProject rather than price:CreatePrice.
Revoking a lifetime entitlement (POST /customers/{customerId}/lifetime-entitlements/{entitlementId}/revoke), which refunds a Stripe purchase in full, needs project:UpdateProject for keys as well as sessions. Changed on 2026-10-21: it used to accept any API key of the team. Owner, Admin and Developer allow it; a key with the Billing, ReadOnly or ExternalDeveloper policy now gets 403. A runtime key (created since 2026-12-01) is refused too and needs a personal access token or a session.
The built-in Owner, Admin, Billing and Developer policies allow all of these. ReadOnly allows only the reads. ExternalDeveloper allows none. Legacy keys without IAM attachments keep their admin-equivalent fallback. A key with the runtime marker is refused the write rows whatever policy is attached.
Changed on 2026-10-20. Catalog writes used to accept any API key of the team, and sessions needed project:UpdateProject. A key or role with a custom policy now needs the actions above. Add them to the policy before upgrading, or catalog calls return 403. The Billing role gains catalog writes, and the Developer role keeps them.
The DELETE routes for products and prices are deprecated. They deactivate the object in Stripe and then delete the BillStack row, which cannot be undone. Archive instead with PATCH and { "isActive": false }, which keeps the row.
Best practices
- Use a test key for development and staging and a live key for production; a test key cannot touch live data
- One key per deployment (development, staging, production)
- Keep new keys as app-runtime keys, and use a personal access token (not a key) for scripts and agents that create products and prices
- Restrict legacy full-access keys once nothing writes the catalog with them
- Set expiration dates and rotate before they expire
- Store keys in environment variables — never hardcode them
- Legacy keys without IAM attachments have an admin-equivalent fallback; handle their revocation and rotation as you would for an admin credential
Next step
With your API key ready, follow the quickstart or migrate from Stripe.