Personal access tokens
The setup credential. Create a token that acts as you to create projects, products and prices from scripts, coding agents and MCP clients.
A personal access token (bsu_...) is a Bearer credential that belongs to you, not to a team. A request made with it is treated as if you had made it yourself, inside the team or project you chose when you created the token.
A token is the setup credential. Use it to list your team and projects, create projects, and create, update, archive, link and publish products and prices. Your own scripts, a coding agent or an MCP client should use one.
For the app that calls BillStack from its server at runtime (checkout, portal, entitlements, subscriptions, customers), use a project API key instead. Since 2026-12-01 a new project key cannot write the catalog or projects; it gets 403 USER_TOKEN_REQUIRED.
Tokens and API keys
| Personal access token (setup) | Project API key (runtime) | |
|---|---|---|
| Prefix | bsu_test_<48 hex> or bsu_live_<48 hex> | bs_test_, bs_live_ (secret), pk_test_, pk_live_ (publishable) |
| Belongs to | A person | A team, usually one project |
| Created in | Account > Access tokens | A project's Settings > Keys page (team admins only) |
| Used by | You, your scripts and your agent | Your app's server, through the SDK |
| Can do | Everything you may do in the team: list and create projects, write the catalog, read billing data | Checkout, portal, entitlements, subscriptions, customers, payment methods, referrals, webhook endpoints, invoice and catalog reads |
| Cannot do | Anything your role cannot do; manage keys or tokens (dashboard session only) | Create or change products, prices and projects; manage keys, IAM and provider connections |
| Permissions | Your own current permissions, within the token's scope | A fixed runtime policy. Older keys without it have an admin-equivalent fallback |
| Environment | Fixed when the token is created | Fixed by the key (test or live) |
| Scope | One team, or one project of it | One team, optionally one project |
| Ends when | It expires, you revoke it, or you leave the team | It expires or a team admin revokes it |
A token stops when its owner leaves the team, so an automation that must outlive a person cannot rely on one. That is a known limitation for now: run such a job under a person who stays on the team.
A token never has more access than you do. It cannot be used on a team it was not created for, and it has no admin fallback: if your role in the team has no permission for an action, the token does not have it either.
Create a token
- Open Account > Access tokens. The same page is linked from a project's Settings > Keys page, the team Settings > API Keys page and a project's Settings page; those links can preselect that team, project and environment. When you open Account directly, choose a team before choosing a scope or environment.
- Click Create token, enter a name (1 to 80 characters), and choose a team you belong to.
- Choose Test or Live. Test is selected by default. Live is offered only when Live is enabled for the selected team.
- Choose the scope: the whole team, or one project of that team. You can only pick projects you can access. Changing teams resets the scope to the whole team and the environment to Test.
- Choose an expiry: 30, 90 or 365 days, or no expiry.
- Copy the token immediately. It is shown once; BillStack stores only a SHA-256 hash and a short display prefix, which the list shows so you can tell tokens apart.
The list shows each token's team, scope, environment, last use, expiry and status (active, expired, revoked or invalidated). Older unscoped tokens (bsu_<48 hex>) have been invalidated; they appear as Invalidated and Unscoped. Create a new environment-specific token and replace the old secret in your scripts and integrations. Tokens cannot be edited or rotated: to change a token's team, scope, environment or expiry, create a new one and revoke the old one. You can hold at most 50 active tokens at once; invalidated legacy tokens do not count toward that limit.
Tokens are managed only from a signed-in dashboard session. A token cannot list, create or revoke tokens, and a request to the management endpoints that carries an Authorization header is refused with 403.
Scope
| Scope | Reaches |
|---|---|
| Whole team | Every team-level route and every project you can access in that team |
| One project | That project's routes only |
A project token is strict:
- It is refused on any other project of the team (
403). - It is refused on team-wide endpoints, such as the team's Stripe mirror reads, provider connections and team-level queries, because those cover every project (
403). The exception is a team-level route that is explicitly filtered to the token's own project. - It is refused by team-wide MCP tools. Tools that take a
projectIdwork for the token's own project only.
If you need both team-wide and project calls, create a whole-team token. Listing and creating projects needs a whole-team token.
Permissions
A token's permissions are your permissions in that team at the time of each request, not a snapshot from when it was created. Change your role, or have an admin change it, and the next request reflects it. There is no read-only token: if you want less access, use a role with less access.
Routes check the same IAM actions as for a dashboard session (for example product:ListProducts or customer:ListCustomers). A route that is available only from a signed-in dashboard session, such as API key management and provider connection setup, does not accept a token.
Set up a project from code
A whole-team token can list the team's projects and create a new one over v2. Both routes need a dashboard session or a bsu_ token; any bs_ or pk_ key gets 403 USER_TOKEN_REQUIRED. A project-scoped token is refused too.
# List the projects you may see in the team (needs project:ListProjects)
curl "https://billing.w3dev.app/api/billstack/v2/teams/$TEAM_ID/projects" \
-H "Authorization: Bearer $BILLSTACK_SETUP_TOKEN"
# Create a project (needs project:CreateProject)
curl -X POST "https://billing.w3dev.app/api/billstack/v2/teams/$TEAM_ID/projects" \
-H "Authorization: Bearer $BILLSTACK_SETUP_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "name": "My app", "slug": "my-app", "description": "Optional" }'GET answers { "projects": [...] }. POST answers 201 { "project": {...} }. slug is optional: lowercase letters, digits and single hyphens, up to 63 characters, and it defaults to one built from the name. A taken slug is 409 PROJECT_SLUG_TAKEN, a reserved one is 400 PROJECT_SLUG_RESERVED, and a name that yields no slug is 400 INVALID_REQUEST. See the v2 reference.
Then create products and prices in the project with the catalog routes and the same token. The runtime key for the app comes from the project's Settings > Keys page.
From the setup wizard
The team setup wizard's agent prompt carries two test credentials: a runtime bs_test_ app key for your app's server, and a bsu_test_ setup token for the whole team that lasts 7 days, so the agent can create products and prices from its own shell. Generating the prompt again revokes your earlier unused setup tokens. Keep the setup token in the agent's shell, never in the app's code or environment file.
Use a token
Send it as a Bearer token, exactly like a project API key:
curl "https://billing.w3dev.app/api/billstack/v2/teams/$TEAM_ID/projects/$PROJECT_ID/catalog/products" \
-H "Authorization: Bearer bsu_test_..."A token works on the v1 and v2 API routes that accept a project API key or a dashboard session, and on the MCP server. In the URL, use the team the token was created for. New tokens begin with bsu_test_ or bsu_live_, matching the selected environment.
Keep tokens in an environment variable or a secret manager. Never put one in a browser bundle, a repository or a chat message.
Choose the environment
A personal access token is fixed to the environment selected when it was created. Test is the default; Live is available only for a team with Live enabled. Later team promotion does not change an existing token's environment. Dashboard and MCP OAuth sessions keep their existing session environment behavior.
Use a token whose environment matches the data you want to access. A REST X-BillStack-Environment header or v2 mode must match the token; an opposite value is rejected with 403 ENVIRONMENT_MISMATCH.
curl "https://billing.w3dev.app/api/billstack/v2/teams/$TEAM_ID/projects/$PROJECT_ID/catalog/products" \
-H "Authorization: Bearer bsu_test_..."The v2 mode parameter must also match a personal access token's environment, for reads and writes. For a team API key, mode must match the key's environment. See Test and live environments.
MCP
Connect an MCP client to https://billing.w3dev.app/mcp with Authorization: Bearer bsu_test_... or bsu_live_... instead of the OAuth sign-in. The token identifies you and its team, so teamId can be left out of tool calls (a different teamId is refused) and list_teams returns just that team. MCP has no request header for the environment: omitting an environment argument uses the token's environment, while an opposite value is rejected. MCP OAuth sessions keep their existing behavior.
Expiry and revocation
A token stops working when:
- it expires: the expiry you chose at creation, if any;
- you revoke it from Account > Access tokens, which takes effect on the next request;
- you leave the team, or an admin removes you from it: your tokens for that team are revoked automatically, and a token also stops working as soon as you are no longer a member;
- the project a project token is limited to is deleted.
Re-joining a team does not bring old tokens back. Revoked tokens stay in the list for your records.
Errors
| Status | Meaning |
|---|---|
401 | The token is unusable: unknown, revoked, expired or an invalidated legacy token. The code is INVALID_ACCESS_TOKEN or ACCESS_TOKEN_EXPIRED. On MCP, a 401 comes with the usual authentication challenge. Create a new token. |
403 | The token is valid but the request is not allowed: another team or project, a team-wide endpoint with a project token, you are no longer a member, you lack the permission, or an environment problem (LIVE_ENVIRONMENT_NOT_ENABLED, INVALID_ENVIRONMENT, ENVIRONMENT_MISMATCH). |
A project API key that tries a setup call, such as creating a product, a price or a project, gets 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." Retry the call with a token.
A 401 means fix the credential; a 403 means the credential is fine but needs a different scope, role or environment, so retrying with the same token will not help.
Next step
Create a token for your agent or script, then follow the quickstart. For your app's server, create a project API key.