> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to use authorized keys

To authenticate as a service account and perform operations on its behalf, use an *authorized key pair*.

## Prerequisites

> [tab] Web console
>
> 1. Make sure you are in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 2. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-web-console) if needed.

> [tab] CLI
>
> 1. [Install and configure](https://docs.nebius.com/cli/install.md) the Nebius AI Cloud CLI.
>
> 2. Check that your project ID is saved in the Nebius AI Cloud CLI profile configuration:
>    ```bash theme={null}
>    cat ~/.nebius/config.yaml
>    ```
>
> 3. Make sure that you or the service account that you use is in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 4. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-cli) if needed.
>
> 5. Get the ID of the service account for which you want to issue the key and save it to an environment variable:
>
>    ```bash theme={null}
>    export SA_ID=$(nebius iam service-account get-by-name \
>      --name <service_account_name> \
>      --format jsonpath='{.metadata.id}')
>    ```
>
> 6. To [list expiring keys](#listing-expiring-keys), install jq to filter and sort the JSON data returned by the Nebius AI Cloud CLI:
>
>    ```bash Ubuntu theme={null}
>    sudo apt-get install jq
>    ```
>
>    ```bash macOS theme={null}
>    brew install jq
>    ```

> [tab] Terraform
>
> 1. [Install and configure](https://docs.nebius.com/terraform-provider/install.md) the Nebius AI Cloud provider for Terraform.
>
> 2. Make sure that you or the service account that you use is in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 3. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-terraform) if needed.

> [tab] Go SDK
>
> 1. [Install and initialize the Nebius SDK for Go](https://docs.nebius.com/sdk/go/install-auth.md).
>
> 2. Make sure that you or the service account that you use is in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 3. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-go-sdk) if needed.
>
> 4. Get the ID of the service account for which you want to issue the key and save it to a variable:
>
>    ```go theme={null}
>    serviceAccount, err := sdk.Services().IAM().V1().
>        ServiceAccount().GetByName(
>            ctx,
>            &iam.GetServiceAccountByNameRequest{
>                Name: "<service_account_name>",
>            },
>        )
>    if err != nil {
>        return err
>    }
>    serviceAccountID := serviceAccount.GetMetadata().GetId()
>    if serviceAccountID == "" {
>        return errors.New("service account ID is missing")
>    }
>    fmt.Println(serviceAccountID)
>    ```

> [tab] Python SDK
>
> 1. [Install and initialize the Nebius SDK for Python](https://docs.nebius.com/sdk/python/install-auth.md).
>
> 2. Make sure that you or the service account that you use is in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 3. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-python-sdk) if needed.
>
> 4. Get the ID of the service account for which you want to issue the key and save it to a variable:
>
>    ```python theme={null}
>    service_account_service = ServiceAccountServiceClient(sdk)
>    service_account = await service_account_service.get_by_name(
>        GetServiceAccountByNameRequest(name="<service_account_name>"),
>    )
>    service_account_id = service_account.metadata.id
>    print(service_account_id)
>    ```

> [tab] JavaScript SDK
>
> 1. [Install and initialize the Nebius SDK for JavaScript](https://docs.nebius.com/sdk/javascript/install-auth.md).
>
> 2. Make sure that you or the service account that you use is in a [group](https://docs.nebius.com/iam/authorization/groups/index.md) that has the `admin` role within your tenant or project; for example, the default `admins` group. You can check this in the [Administration → IAM](https://console.nebius.com/iam) section of the web console.
>
> 3. [Create a new service account](https://docs.nebius.com/iam/service-accounts/manage.md#creating-a-service-account-javascript-sdk) if needed.
>
> 4. Get the ID of the service account for which you want to issue the key and save it to a variable:
>
>    ```ts theme={null}
>    const serviceAccountService =
>      new ServiceAccountService(sdk);
>    const serviceAccount = await serviceAccountService.getByName(
>      GetServiceAccountByNameRequest.create({
>        name: "<service_account_name>",
>      }),
>    );
>    const serviceAccountId = serviceAccount.metadata?.id;
>    if (!serviceAccountId) {
>      throw new Error("service account ID is missing");
>    }
>    console.log(serviceAccountId);
>    ```

## Creating a key pair

> [!NOTE]
>
> If you are using the CLI, this step is optional. If you use the `nebius iam auth-public-key generate` command in the [next step](#uploading-the-public-key), the CLI creates the key pair for you.

Create a key pair on your local machine:

```bash theme={null}
openssl genrsa -out private.pem 4096 && \
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
```

This command creates the `public.pem` and `private.pem` key files in your local directory where you run the command.

## Uploading the public key

> [!NOTE]
>
> To upload an authorized key with Terraform or one of the SDKs, the provider or SDK must already be authenticated with an existing authorized key. You cannot upload the first authorized key for a service account using Terraform or an SDK. If you already have an authorized key, for example, one created with the CLI, proceed to [update the configuration](#updating-the-configuration) to use your existing authorized key with Terraform or the SDK.

> [tab] Web console
>
> 1. In the [web console](https://console.nebius.com), go to  **Administration** → **IAM**.
> 2. Open the **Service accounts** tab.
> 3. Open the page of the required service account.
> 4. Click  **Upload authorized key**.
> 5. Click  **Attach file** and then select `public.pem`.
> 6. (Optional) Set an expiration date.
> 7. Click **Upload key**.
>
> The key is displayed on the **Authorized keys** tab.

> [tab] CLI
>
> Depending on whether you already [created a key pair](#creating-a-key-pair), run one of the following commands:
>
> * To upload the public key if you already created a key pair:
>
>   ```bash theme={null}
>   nebius iam auth-public-key create \
>     --account-service-account-id $SA_ID \
>     --data "$(cat public.pem)"
>   ```
>
> * To create a new key pair, upload the public key and create a local CLI configuration file in one step:
>
>   ```bash theme={null}
>   nebius iam auth-public-key generate \
>     --service-account-id $SA_ID \
>     --output ~/.nebius/$SA_ID-credentials.json
>   ```
>
> To set an expiration date for the key, add the `--expires-at` parameter to either command with a timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, for example `--expires-at 2026-04-01T20:00:00Z`.
>
> After you complete either option, you can find the authorized key in the [web console](https://console.nebius.com). In the sidebar, go to  **Administration** → **IAM** → **Service accounts**, and select the service account for which you created the authorized key.

> [tab] Terraform
>
> To upload a new authorized key with Terraform:
>
> 1. Inside the working directory, create a configuration file, for example `main.tf`:
>
>    ```hcl theme={null}
>    resource "nebius_iam_v1_auth_public_key" "sa_authorized_key" {
>      name      = "sa_authorized_key"
>      parent_id = "<project_ID>"
>
>      account = {
>        service_account = {
>          id = "<service_account_ID>"
>        }
>      }
>
>      data       = file("${path.module}/public.pem")
>      expires_at = "<expiration_date>"
>    }
>    ```
>
>    The resource contains the following parameters:
>
>    * `parent_id`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-terraform).
>    * `account.service_account.id`: ID of the service account. To copy the service account from the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, next to the ID, click .
>    * `data`: Contents of the `public.pem` file that you [created in the previous step](#creating-a-key-pair). In the example above, Terraform reads the contents of `public.pem` with the `file()` function. You can also use `trimspace(file(...))` to remove trailing whitespace.
>    * `expires_at` (optional): Date and time when the authorized key expires, in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format, for example `2026-04-01T20:00:00Z`.
>
> 2. Check that the configuration is correct:
>    ```bash theme={null}
>    terraform validate
>    ```
>
> 3. Apply the changes:
>    ```bash theme={null}
>    terraform apply
>    ```
>
> For all available arguments and attributes, see the [full reference](https://docs.nebius.com/terraform-provider/reference/resources/iam_v1_auth_public_key.md).

> [tab] Go SDK
>
> Upload the public key:
>
> ```go theme={null}
> publicKeyData, err := os.ReadFile("public.pem")
> if err != nil {
>     return err
> }
> authPublicKeyService := sdk.Services().IAM().V1().
>     AuthPublicKey()
> authPublicKeyOperation, err := authPublicKeyService.Create(
>     ctx,
>     &iam.CreateAuthPublicKeyRequest{
>         Spec: &iam.AuthPublicKeySpec{
>             Account: &iam.Account{
>                 Type: &iam.Account_ServiceAccount_{
>                     ServiceAccount: &iam.Account_ServiceAccount{
>                         Id: "<service_account_ID>",
>                     },
>                 },
>             },
>             Data: string(publicKeyData),
>         },
>     },
> )
> if err != nil {
>     return err
> }
> authPublicKeyOperation, err = authPublicKeyOperation.Wait(ctx)
> if err != nil {
>     return err
> }
> authorizedKeyID := authPublicKeyOperation.ResourceID()
> fmt.Println(authorizedKeyID)
> ```
>
> In the code, set the following parameters:
>
> * `Account.ServiceAccount.Id`: ID of the service account for which you want to issue the key.
> * `Spec.Data`: Contents of `public.pem` that you [created earlier](#creating-a-key-pair).
>
> After you complete this, you can find the authorized key in the [web console](https://console.nebius.com). In the sidebar, go to  **Administration** → **IAM** → **Service accounts**, and select the service account for which you created the authorized key.

> [tab] Python SDK
>
> Upload the public key:
>
> ```python theme={null}
> public_key = Path("public.pem").read_text()
> auth_public_key_service = AuthPublicKeyServiceClient(sdk)
> auth_public_key_operation = await auth_public_key_service.create(
>     CreateAuthPublicKeyRequest(
>         spec=AuthPublicKeySpec(
>             account=Account(
>                 service_account=Account__ServiceAccount(
>                     id="<service_account_ID>",
>                 ),
>             ),
>             data=public_key,
>         ),
>     ),
> )
> await auth_public_key_operation.wait()
> authorized_key_id = auth_public_key_operation.resource_id
> print(authorized_key_id)
> ```
>
> In the code, set the following parameters:
>
> * `account=Account__ServiceAccount(id=...)`: ID of the service account for which you want to issue the key.
> * `spec.data`: Contents of `public.pem` that you [created earlier](#creating-a-key-pair).
>
> After you complete this, you can find the authorized key in the [web console](https://console.nebius.com). In the sidebar, go to  **Administration** → **IAM** → **Service accounts**, and select the service account for which you created the authorized key.

> [tab] JavaScript SDK
>
> Upload the public key:
>
> ```ts theme={null}
> const publicKey = readFileSync("public.pem", "utf8");
> const authPublicKeyService =
>   new AuthPublicKeyService(sdk);
> const authPublicKeyOperation =
>   await authPublicKeyService.create(
>     CreateAuthPublicKeyRequest.create({
>       metadata: ResourceMetadata.create({
>         parentId: "<project_ID>",
>       }),
>       spec: AuthPublicKeySpec.create({
>         account: Account.create({
>           type: {
>             $case: "serviceAccount",
>             serviceAccount: Account_ServiceAccount.create({
>               id: "<service_account_ID>",
>             }),
>           },
>         }),
>         data: publicKey,
>       }),
>     }),
>   ).result;
> await authPublicKeyOperation.wait();
> const authorizedKeyId = authPublicKeyOperation.resourceId();
> console.log(authorizedKeyId);
> ```
>
> In the code, set the following parameters:
>
> * `metadata.parentId`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-javascript-sdk).
> * The service account for which you want to issue the key, via `Account_ServiceAccount.create({ id: ... })`.
> * `spec.data`: Contents of `public.pem` that you [created earlier](#creating-a-key-pair).
>
> After you complete this, you can find the authorized key in the [web console](https://console.nebius.com). In the sidebar, go to  **Administration** → **IAM** → **Service accounts**, and select the service account for which you created the authorized key.

## Updating the configuration

Update your configuration to use the authorized key you created:

> [!TIP]
>
> If you used the web console to upload the public key, you do not need to update any additional configuration.

> [tab] CLI
>
> Create a new CLI profile:
>
> 1. [Get the ID of the project](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-cli) that you want to work in and save it to an environment variable:
>
>    ```bash theme={null}
>    export PROJECT_ID=<project_ID>
>    ```
>
> 2. Initialize the Nebius AI Cloud CLI configuration:
>
>    ```bash theme={null}
>    nebius profile create \
>      --endpoint api.nebius.cloud \
>      --service-account-file ~/.nebius/$SA_ID-credentials.json \
>      --parent-id $PROJECT_ID \
>      --profile <profile_name>
>    ```
>
> 3. Check that your new profile has been created and set as default:
>
>    ```sh theme={null}
>    nebius profile list
>    ```
>
> Now you can run Nebius AI Cloud CLI commands on behalf of the service account. To do this, add `--profile <service_account_profile_name>` to the commands.

> [tab] Terraform
>
> Configure the Nebius AI Cloud provider for Terraform to use an authorized key. Inside your Terraform working directory, add the `service_account` block to the provider configuration, for example in `providers.tf`:
>
> ```hcl theme={null}
> provider "nebius" {
>   service_account = {
>     account_id       = "<service_account_ID>"
>     public_key_id    = "<authorized_key_ID>"
>     private_key_file = "<path_to_private_key>"
>   }
> }
> ```
>
> In this configuration:
>
> * `public_key_id`: ID of the authorized key that you uploaded. To copy the public key ID:
>   1. In the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, and select the service account.
>   2. Click **Authorized keys**, and then click  next to the ID of the public key you uploaded.
> * `private_key_file`: Path to the `private.pem` file you [created in the previous step](#creating-a-key-pair).
>
> You can also pass these values through environment variables:
>
> ```hcl theme={null}
> provider "nebius" {
>   service_account = {
>     account_id_env       = "SA_ID"
>     public_key_id_env    = "AUTHKEY_ID"
>     private_key_file_env = "AUTHKEY_PRIV_PATH"
>   }
> }
> ```
>
> ```bash theme={null}
> export SA_ID=<service_account_ID>
> export AUTHKEY_ID=<authorized_key_ID>
> export AUTHKEY_PRIV_PATH=<path_to_private_key>
> ```

> [tab] Go SDK
>
> Initialize the SDK using the authorized key you created:
>
> ```go theme={null}
> newSdk, err := gosdk.New(
>     ctx,
>     gosdk.WithParentID("<project_ID>"),
>     gosdk.WithCredentials(
>         gosdk.ServiceAccountReader(
>             auth.NewPrivateKeyFileParser(
>                 nil,
>                 "<path_to_private_key>",
>                 "<authorized_key_ID>",
>                 "<service_account_ID>",
>             ),
>         ),
>     ),
> )
> if err != nil {
>     return err
> }
> defer newSdk.Close()
> ```
>
> In the code, set the following parameters:
>
> * `WithParentID`'s argument: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-go-sdk).
> * `NewPrivateKeyFileParser`'s second argument: Path to the `private.pem` file you [created in the previous step](#creating-a-key-pair).
> * `NewPrivateKeyFileParser`'s third argument: ID of the authorized key that you uploaded. To copy the ID:
>   1. In the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, and select the service account.
>   2. Click **Authorized keys**, and then click  next to the ID of the public key you uploaded.
> * `NewPrivateKeyFileParser`'s fourth argument: ID of the service account.
>
> For more information about SDK initialization, see [Initialization and authentication](https://docs.nebius.com/grpc-api/sdk/go.md#initialization-and-authentication).

> [tab] Python SDK
>
> Initialize the SDK using the authorized key you created:
>
> ```python theme={null}
> new_sdk = SDK(
>     parent_id="<project_ID>",
>     service_account_private_key_file_name="<path_to_private_key>",
>     service_account_public_key_id="<authorized_key_ID>",
>     service_account_id="<service_account_ID>",
> )
> ```
>
> In the code, set the following parameters:
>
> * `parent_id`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-python-sdk).
> * `service_account_private_key_file_name`: Path to the `private.pem` file you [created in the previous step](#creating-a-key-pair).
> * `service_account_public_key_id`: ID of the authorized key that you uploaded. To copy the ID:
>   1. In the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, and select the service account.
>   2. Click **Authorized keys**, and then click  next to the ID of the public key you uploaded.
> * `service_account_id`: ID of the service account.
>
> For more information about SDK initialization, see [Initialization and authentication](https://docs.nebius.com/grpc-api/sdk/python.md#initialization-and-authentication).

> [tab] JavaScript SDK
>
> Initialize the SDK using the authorized key you created:
>
> ```ts theme={null}
> const newSdk = new SDK({
>   parentId: "<project_ID>",
>   credentials: new PkFileReader(
>     "<path_to_private_key>",
>     "<authorized_key_ID>",
>     "<service_account_ID>",
>   ),
> });
> ```
>
> In the code, set the following parameters:
>
> * `parentId`: [Project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-javascript-sdk).
> * `PkFileReader`'s first argument: Path to the `private.pem` file you [created in the previous step](#creating-a-key-pair).
> * `PkFileReader`'s second argument: ID of the authorized key that you uploaded. To copy the ID:
>   1. In the [web console](https://console.nebius.com), go to  **Administration** → **IAM** → **Service accounts**, and select the service account.
>   2. Click **Authorized keys**, and then click  next to the ID of the public key you uploaded.
> * `PkFileReader`'s third argument: ID of the service account.
>
> For more information about SDK initialization, see [Initialization and authentication](https://docs.nebius.com/grpc-api/sdk/javascript.md#initialization-and-authentication).

## Listing expiring keys

After an authorized key expires, you can't use it to authenticate as the service account. To find the keys that you need to replace soon, list the keys that expire within the next seven days, across all service accounts in your project.

> [tab] CLI
>
> List the expiring keys, sorted by expiration date:
>
> ```bash theme={null}
> nebius iam auth-public-key list --all --format json \
>   | jq '(now | todate) as $now
>       | (now + 7 * 86400 | todate) as $cutoff
>       | [.items[]?
>           | select(.spec.expires_at != null
>               and .spec.expires_at >= $now
>               and .spec.expires_at <= $cutoff)]
>       | sort_by(.spec.expires_at)
>       | .[]
>       | {
>           id: .metadata.id,
>           service_account_id: .spec.account.service_account.id,
>           expires_at: .spec.expires_at
>         }'
> ```
>
> For each key, the output contains the following fields:
>
> * `id`: ID of the key.
> * `service_account_id`: ID of the service account that the key belongs to.
> * `expires_at`: Date and time when the key expires.
>
> To adjust the command:
>
> * To change the period, replace `7` in `7 * 86400` with another number of days.
> * To list keys in a project other than the one saved in your CLI profile, add `--parent-id <project_ID>` to the command.

> [tab] Go SDK
>
> List the expiring keys, sorted by expiration date:
>
> ```go theme={null}
> keyListService := sdk.Services().IAM().V1().
>     AuthPublicKey()
> now := time.Now()
> cutoff := now.Add(7 * 24 * time.Hour)
> var expiringKeys []*iam.AuthPublicKey
> keyPageToken := ""
> for {
>     authPublicKeys, err := keyListService.List(
>         ctx,
>         &iam.ListAuthPublicKeyRequest{
>             ParentId:  "<project_ID>",
>             PageSize:  1000,
>             PageToken: keyPageToken,
>         },
>     )
>     if err != nil {
>         return fmt.Errorf("list authorized keys: %w", err)
>     }
>     for _, key := range authPublicKeys.GetItems() {
>         if key.GetSpec().GetExpiresAt() == nil {
>             continue
>         }
>         expiresAt := key.GetSpec().GetExpiresAt().AsTime()
>         if expiresAt.Before(now) || expiresAt.After(cutoff) {
>             continue
>         }
>         expiringKeys = append(expiringKeys, key)
>     }
>     keyPageToken = authPublicKeys.GetNextPageToken()
>     if keyPageToken == "" {
>         break
>     }
> }
> sort.Slice(expiringKeys, func(i, j int) bool {
>     first := expiringKeys[i].GetSpec().GetExpiresAt()
>     second := expiringKeys[j].GetSpec().GetExpiresAt()
>     return first.AsTime().Before(second.AsTime())
> })
> for _, key := range expiringKeys {
>     fmt.Println(
>         key.GetMetadata().GetId(),
>         key.GetSpec().GetAccount().GetServiceAccount().GetId(),
>         key.GetSpec().GetExpiresAt().AsTime().
>             Format(time.RFC3339),
>     )
> }
> ```
>
> In the code, set `ParentId` to the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-go-sdk).
>
> For each key, the code prints the following values:
>
> * ID of the key.
> * ID of the service account that the key belongs to.
> * Date and time when the key expires.
>
> To change the period, replace `7` in `7 * 24 * time.Hour` with another number of days.

> [tab] Python SDK
>
> List the expiring keys, sorted by expiration date:
>
> ```python theme={null}
> key_list_service = AuthPublicKeyServiceClient(sdk)
> now = datetime.now(timezone.utc)
> cutoff = now + timedelta(days=7)
> expiring_keys = []
> key_page_token = ""
> while True:
>     auth_public_keys = await key_list_service.list(
>         ListAuthPublicKeyRequest(
>             parent_id="<project_ID>",
>             page_size=1000,
>             page_token=key_page_token,
>         ),
>     )
>     for key in auth_public_keys.items:
>         expires_at = key.spec.expires_at
>         if expires_at and now <= expires_at <= cutoff:
>             expiring_keys.append(key)
>     key_page_token = auth_public_keys.next_page_token
>     if not key_page_token:
>         break
> expiring_keys.sort(key=lambda key: key.spec.expires_at)
> for key in expiring_keys:
>     service_account = key.spec.account.service_account
>     print(
>         key.metadata.id,
>         service_account.id if service_account else None,
>         key.spec.expires_at.isoformat(),
>     )
> ```
>
> In the code, set `parent_id` to the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-python-sdk).
>
> For each key, the code prints the following values:
>
> * ID of the key.
> * ID of the service account that the key belongs to.
> * Date and time when the key expires.
>
> To change the period, replace `7` in `timedelta(days=7)` with another number of days.

> [tab] JavaScript SDK
>
> List the expiring keys, sorted by expiration date:
>
> ```ts theme={null}
> const keyListService = new AuthPublicKeyService(sdk);
> const now = dayjs();
> const cutoff = now.add(7, "day");
> const expiringKeys = [];
> let keyPageToken = "";
> while (true) {
>   const authPublicKeys = await keyListService.list(
>     ListAuthPublicKeyRequest.create({
>       parentId: "<project_ID>",
>       pageSize: 1000,
>       pageToken: keyPageToken,
>     }),
>   ).result;
>   for (const key of authPublicKeys.items) {
>     const expiresAt = key.spec?.expiresAt;
>     if (
>       expiresAt &&
>       !expiresAt.isBefore(now) &&
>       !expiresAt.isAfter(cutoff)
>     ) {
>       expiringKeys.push(key);
>     }
>   }
>   if (!authPublicKeys.nextPageToken) {
>     break;
>   }
>   keyPageToken = authPublicKeys.nextPageToken;
> }
> expiringKeys.sort(
>   (first, second) =>
>     first.spec.expiresAt.valueOf() -
>     second.spec.expiresAt.valueOf(),
> );
> for (const key of expiringKeys) {
>   const account = key.spec.account?.type;
>   console.log({
>     id: key.metadata?.id,
>     serviceAccountId:
>       account?.$case === "serviceAccount"
>         ? account.serviceAccount.id
>         : undefined,
>     expiresAt: key.spec.expiresAt.toISOString(),
>   });
> }
> ```
>
> In the code, set `parentId` to the [project ID](https://docs.nebius.com/iam/manage-projects.md#how-to-get-a-project-id-javascript-sdk).
>
> For each key, the code prints an object with the following properties:
>
> * `id`: ID of the key.
> * `serviceAccountId`: ID of the service account that the key belongs to.
> * `expiresAt`: Date and time when the key expires.
>
> To change the period, replace `7` in `now.add(7, "day")` with another number of days.

The list doesn't include keys that have already expired or keys without an expiration date. If the list is empty, no keys expire within the next seven days.

To replace an expiring key, [upload a new public key](#uploading-the-public-key) and [update your configuration](#updating-the-configuration) to use it.
