Overview of authentication methods on Blaxel
Blaxel employs two main authentication paradigms: short-lived tokens (OAuth) and long-lived tokens (API keys). Long-lived tokens are easier to use but are less secure as their validity can go from multiple days to infinite. They are generated as API keys from the Blaxel console. OAuth tokens are recommended for security reasons, as their duration is only of 2 hours (short-lived). They are generated through OAuth 2.0 authentication endpoints.API keys
Long-lived authentication tokens are called API keys on Blaxel. Their validity duration is infinite.Using API keys
API keys can be used in the Blaxel APIs, CLI and SDK. To authenticate in the SDKs, use the following two variablesBL_WORKSPACE
and BL_API_KEY
, which can be set in one of these sources:
- your
.env
file - your machine’s environment variables
- the local configuration file created when you log in through the CLI (see below)
Authorization
or X-Blaxel-Authorization
in any call to the Blaxel APIs. For example, to list models:
Manage API keys
You can create private API keys for your Blaxel account to authenticate directly when using the Blaxel APIs or CLI. Your permissions in each workspace will be the ones given to your account in each of them. API keys can be managed from the Blaxel console in Profile > Security.
OAuth 2.0 tokens
These short-lived tokens are based on the OAuth 2.0 authentication protocol, and have a validity period of 2 hours.Use OAuth tokens in the CLI
Usebl login
command.
You will then be redirected to the Blaxel console to finish logging in. Sign in using your Blaxel account if you aren’t already.
Once this is done, return to your terminal: the login will be finalized and you will then be able to run CLI commands.
Your permissions in each workspace will be the ones given to your account in each of them.
Use OAuth tokens in the API via service accounts
Service accounts can retrieve a short-lived token via the OAuth client credentials grant type in the authentication API, using their client ID and client secret. These two keys are generated automatically when creating a service account. Make sure to copy the secret at its generation as you will never be able to see it again after.
Service accounts can also connect to the API using a long-lived API key, as detailed in the section below.
/oauth/token
endpoint.
Authorization
or X-Blaxel-Authorization
, as such:
(Advanced) Use OAuth tokens in the APIs
This section assumes you are a developer experienced with OAuth 2.0. For a simpler guide of how to use short-lived tokens in Blaxel APIs, read the section on authenticating service accounts.
Authorization
or X-Blaxel-Authorization
.
Alternatively, you can retrieve a token using the SDK: