This walks through the life of a cluster with the Bonsai API v1: pick a plan and a region, create the cluster, wait for it, connect to it, and delete it. It uses curl and jq.
1. Create a token
In the dashboard, open your account's settings, then the API Tokens tab, and create a token with these scopes:
account:read, to list plans and regions.clusters:readandclusters:write, to create, watch and delete the cluster.credentials:read, to get the cluster's URL.
clusters:write needs the Admin role on the account. Copy the token when it's shown, since it's shown only once, and put it in an environment variable:
Check that it works:
|
2. Pick a plan and a region
Plans differ by account. List the ones yours can use:
|
Each plan lists the regions it can be created in, and its offers list the releases available in each region. GET /v1/regions lists the regions themselves. See the Plan object for every field.
3. Create the cluster
name, plan and region are required. Add release to choose the engine and version, from the plan's offers for that region; without it, you get the first one offered. Accounts with private spaces can add space.
The Idempotency-Key header makes the request safe to retry: if the connection drops before you see the answer, send the same request with the same key, and you get the same Action back instead of a second cluster. See Retrying safely.
Creating a cluster takes a few seconds, so the API answers 202 Accepted with an Action, plus a Location header pointing at it:
HTTP/2 202
location: https://api.bonsai.io/v1/actions/act_3k9x0q2m7v1c8b4n
retry-after: 5
The cluster's ID is in subject.id.
A paid plan needs a payment method on the account, unless the account is billed by invoice. Without one, the create is refused at once with 422 payment_method_required, and the error's action_url is a page where a card can be added. Nothing is created, and the same request with the same Idempotency-Key works once the card is in.
4. Wait for it
Poll the Action until its state is success or error, waiting the number of seconds in its Retry-After header between polls:
|
On success, result names the new cluster and its first credential. If the build fails, state is error, error.code says why, and Bonsai stops billing for the cluster. See Actions.
5. Connect to it
A credential holds the username and password for the cluster. Get the first one, with its URL:
|
https://<username>:<password>@my-search-4823919.us-east-1.bonsaisearch.net
That URL includes the password, so keep it out of logs and source control. Use it as your Elasticsearch or OpenSearch client's URL, or check the cluster with:
To give an app its own credential, with read-only access for example, create one with POST /v1/clusters/{cluster_id}/credentials. That needs the credentials:write scope.
6. Delete it
Deleting a cluster takes its current name as a confirmation:
A missing name is a 400 name_confirmation_required, and a different one is a 422 name_mismatch. Like the create, a delete answers 202 with an Action, of type cluster.deprovision, that you can poll.
Deleting a cluster deletes its data, and can't be undone.
Next steps
- Actions: polling, failures, and the Actions Bonsai starts on its own.
- Retrying safely: idempotency keys.
- Errors: every error code, and what to do about it.
- API reference: every operation, parameter and field.
Ready to power your search with AI?
Launch a fully managed Elasticsearch or OpenSearch cluster, with built-in vector search and AI capabilities.