The Bonsai API supports two methods of authenticating requests: Bearer authentication, and HTTP Basic Auth.
Every request to the API must carry an API token in its Authorization header, using one of two schemes:
- Bearer authentication:
Authorization: Bearer bonsai_<key>_<secret>. This is the simplest option for a new token. - HTTP Basic Auth: the token's key and secret as the username and password. Most HTTP clients support it out of the box.
Both schemes accept new bonsai_ tokens as well as the key and secret pairs of tokens created before that format. Send one credential per request: a request with more than one, such as both a Basic and a Bearer credential, is refused.
Both schemes send the token as it is, so only use them over https. Requests to https://api.bonsai.io are encrypted with TLS.
Failed Authentication
Requests that do not have the proper authentication will receive an HTTP 401: Unauthorized response. This can happen for a variety of reasons, including (but not limited to):
- The
Authorizationheader is missing, or uses a scheme other thanBasicorBearer - The token key can not be found (perhaps due to a typo)
- The token secret does not match the key
- The token has been revoked
- The token has expired
A token that authenticates but lacks the scope an API call needs gets an HTTP 403: Forbidden response instead. See scopes.
If you are having trouble authenticating your requests to the API, please reach out to support@bonsai.io.
Ready to power your search with AI?
Launch a fully managed Elasticsearch or OpenSearch cluster, with built-in vector search and AI capabilities.