Authorization: Bearer <access_token>.
The authentication process differs for a user account and a service account.
Authentication for a user account
- Install and configure the Nebius AI Cloud CLI.
-
Create an access token:
An access token is valid for 12 hours. After it expires, create a new one.
-
Add the token to your API request. For example:
Authentication for a service account
To authenticate a service account, create an authorized key for it and then convert this key into an access token by using a JSON Web Token. Next, use the obtained access token for the authentication.Steps
Prepare a service account
- Create a service account if you have not already.
- Add the service account to a group to grant it necessary permissions. In most cases, a group with the
editorrole should be enough; add the account to a group with theadminrole only if you want to manage other accounts’ group memberships through the API. Learn more about groups and their permissions.
Prepare an authorized key
-
Create an authorized key:
This command creates the
public.pemandprivate.pemcertificates in a local directory. -
Upload the key to the service account profile:
- Web console
- CLI
- In the sidebar, go to
Administration → IAM.
- Open the Service accounts tab.
- Open the page of the required service account.
- Click
Upload authorized key.
- To attach the
public.pemfile, clickAttach file and then select
public.pem. - (Optional) Set an expiration date.
- Click Upload key.
- From the service account page, copy and save the account ID and the authorized key ID. You need them for the JSON Web Token.
Create a JSON Web Token
- Install jwt-cli, the CLI for the JSON Web Token management.
-
Create the JSON Web Token:
In the command, specify the copied authorized key ID and the service account ID. Also, specify the current path to the
private.pemfile created earlier. The JSON Web Token is based on the RS256 signing algorithm. The token expires five minutes after its creation. The lifetime is short because the JSON Web Token is only used to create an access token.
Get an access token
-
To exchange the JSON Web Token for an access token, send the following API request:
Specify the JSON Web Token in the request. The output is the following:The access token expires 12 hours after its creation. The
expiresInvalue from the output is specified in seconds. -
Add the token to your API request. For example: