Every request to the Bonsai API v1 needs an API token, sent as a Bearer token in the Authorization header:
Only one operation takes no token: GET /v1.
Tokens
A token looks like bonsai_<key>_<secret>. The key is its public half, which the dashboard's API Tokens list shows so you can tell tokens apart. The secret is shown once, when the token is created. Creating an API token covers making one in the dashboard, its expiration, and keeping it safe.
v1 takes Bearer authentication only. Basic authentication works on the legacy API only, but the same token works on both.
Tokens created before the bonsai_ format
Tokens from before the bonsai_ format have a separate key and secret. They keep working. On v1, send them joined by a dot:
Authorization: Bearer <key>.<secret>
Who a token belongs to
A token belongs to the account, not to the person who created it. It keeps working, with its scopes, if that person leaves the account or changes role, until an Admin revokes it.
The calling token
GET /v1/token shows the token making the request: its key, name, account, scopes and expiry. DELETE /v1/token revokes it, as revoking it in the dashboard does. Neither needs a scope, since a token only ever reaches itself. See Account and tokens.
Scopes
A token's scopes decide which operations it can call. Each operation that takes a token needs one scope, except GET /v1/token and DELETE /v1/token, which any valid token can call on itself:
| Scope | What it allows | Operations |
|---|---|---|
account:read | Read the account, and list the plans, regions, spaces and releases available to it. | GET /v1/account, GET /v1/plans, GET /v1/plans/{plan_id}, GET /v1/regions, GET /v1/spaces, GET /v1/releases |
clusters:read | List and read the account's clusters, with their Actions, usage and metrics. | GET /v1/clusters, GET /v1/clusters/{cluster_id}, GET .../actions, GET /v1/actions/{action_id}, GET .../usage, GET .../metrics |
clusters:write | Create, rename and delete clusters, and change their plans. | POST /v1/clusters, PATCH /v1/clusters/{cluster_id}, DELETE /v1/clusters/{cluster_id}, POST .../plan_changes |
credentials:read | List and read the account's cluster credentials, passwords included. | GET .../credentials, GET .../credentials/{credential_id} |
credentials:write | Create and revoke cluster credentials. | POST .../credentials, DELETE .../credentials/{credential_id} |
query_logs:read | Read the top search queries sent to the account's clusters. | GET .../queries |
.../ stands for /v1/clusters/{cluster_id}/. clusters:write needs the Admin role on the account.
The first three scopes also cover the matching calls of the legacy API. The last three work on v1 only. Tokens made before they existed don't have them, and new tokens get them only when picked. Give each token only the scopes it needs: credentials carry passwords, and query logs hold your users' search terms.
When authentication fails
- A request without a valid token gets a
401 unauthorized: the header is missing or doesn't useBearer, or the token is unknown, revoked or expired. - A request the token has no scope for gets a
403 missing_scope. Itsdetails[].scopenames the scope it needs. - Too many failed authentications from one IP address get a
429 too_many_failed_authentications.
Ready to power your search with AI?
Launch a fully managed Elasticsearch or OpenSearch cluster, with built-in vector search and AI capabilities.