> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.getunleash.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.getunleash.io/_mcp/server.

# API tokens and client keys

> Unleash uses API tokens to authenticate SDKs, Unleash Edge, integrations, and automation. Learn about token types, how Unleash stores tokens, and how to create and rotate them.

Unleash uses API tokens to authenticate consuming clients such as [SDKs](/sdks), [Unleash Edge](/unleash-edge), and other tools and automation.

Unleash supports the following types of API tokens:

* [Backend tokens](#backend-tokens) for connecting [backend SDKs](/sdks#backend-sdks) or [Unleash Edge](/unleash-edge) to Unleash.
* [Frontend tokens](#frontend-tokens) for connecting [frontend SDKs](/sdks#frontend-sdks) to Unleash using the [Frontend API](/concepts/front-end-api) or [Unleash Edge](/unleash-edge).
* [Personal access tokens](#personal-access-tokens) for testing and debugging or providing temporary access to an automation tool.
* [Service account tokens](/concepts/service-accounts) for providing API access to integrations or automation tools.

Each token is either a secure token or a legacy token. See [Token versions](#token-versions) for the differences.

To connect a frontend SDK to Unleash using Unleash Edge, you need both a [backend](#backend-tokens) and [frontend token](#frontend-tokens). See [Connect a frontend SDK to Unleash using Edge](#connect-a-frontend-sdk-to-unleash-using-edge) for an example.

## API token types

### Backend tokens

Backend tokens are intended for use in [backend SDKs](/sdks#backend-sdks) or [Unleash Edge](/unleash-edge) to grant the permissions to:

* Reading feature flag information
* Registering applications with the Unleash server
* Sending usage metrics

Backend tokens are scoped to one or more projects and a single environment. When creating a backend token, you can give it access to a specific list of projects or to all current or future projects. Backend tokens are secrets and must not be exposed to end users.

Backend tokens cannot be used in frontend SDKs; use [frontend tokens](#frontend-tokens) instead.

### Frontend tokens

Use frontend tokens for connecting [frontend SDKs](/sdks#frontend-sdks) to Unleash using the [Unleash Frontend API](/api) or [Unleash Edge](/unleash-edge). They grant the user permission to:

* Reading enabled flags for a given context
* Registering applications with the Unleash server
* Sending usage metrics

Frontend tokens are scoped to one or more projects and a single environment. When creating a frontend token, you can give it access to a specific list of projects or to all current or future projects. Frontend tokens are not considered secret and are safe to expose client-side, including [secure tokens](#token-versions).

Frontend tokens cannot be used in backend SDKs; use [backend tokens](#backend-tokens) instead.

### Personal access tokens

Personal access tokens reflect the permissions of the user who creates them. If the user's permissions change, such as through the addition of a custom role, the token automatically updates to match the new permissions.
You can use personal access tokens for testing, debugging, or giving temporary access to automation tools.

When you use a personal access token to modify resources, the events record the token creator's name for that operation.

Personal access tokens with a lifetime expire and stop working after their expiration date. Although you can set the token to not expire, we recommend using tokens with expiration dates to follow security best practices.

Personal access tokens are not suitable for use in SDKs, as they are not bound to an environment, they may expire, or their permissions may change.

### Service account tokens

Service account tokens provide API access to integration and automation tools. To learn more, go to [Service Accounts](/concepts/service-accounts).

### Admin tokens

> **Warning**
>
> Admin tokens are deprecated. Use other token types:
>
> * With [Open Source](https://www.getunleash.io/pricing); use [personal access tokens](#personal-access-tokens).
> * With [Enterprise](https://www.getunleash.io/pricing); use [service accounts](/concepts/service-accounts).

Admin tokens grant full read and write access to all resources in the Unleash server API. This includes all projects, all environments, and all [root resources](/concepts/rbac).

## Token versions

Each API token is either a secure token or a legacy token. The version determines what the token looks like, how Unleash stores it, and when you can view the complete token, meaning the full value you use to authenticate.

|                                 | Secure token                                                        | Legacy token                                                                        |
| ------------------------------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| Unleash version                 | Created in v8.3 or later                                            | Created in v8.2 or earlier                                                          |
| Token secret                    | Contains `v2_`                                                      | Doesn't contain `v2_`                                                               |
| Stored in the Unleash database  | A selector and a verifier. Unleash never stores the complete token. | The complete token                                                                  |
| Complete token shown            | Only once, when you create it                                       | When you create it, and from the [get API tokens](/api/get-all-api-tokens) endpoint |
| `secure` field in API responses | `true`                                                              | `false`                                                                             |

[Unleash Cloud](/support/availability#plans) always runs the latest version, so every token you create there is a secure token. If you self-host, your Unleash version determines which version of token you create.

Unleash shows a secure token only once, when you create it. Copy the token immediately and store it in a secrets manager.

Legacy tokens keep working after you upgrade. To replace them, see [How Unleash stores tokens](#how-unleash-stores-tokens) > **Legacy tokens** > **Upgrade to secure tokens**.

## How Unleash stores tokens

How Unleash stores a token depends on its [version](#token-versions):

#### Secure tokens

For a [secure token](#token-versions), Unleash stores two values instead of the complete token:

* A **selector**, which identifies the token's database record. The selector is part of the token, so Unleash can find the correct record during authentication. The selector isn't a secret.
* A **verifier**, which Unleash derives from the complete token and uses to verify it. Unleash stores the verifier in the database and never includes it in the token or in API responses.

When Unleash receives a secure token, it extracts the selector, retrieves the matching verifier, and verifies the token. Unleash can't reconstruct the complete token from these values, and the values alone can't authenticate a request. This limits the impact if someone gains read access to your database or its backups.

Because Unleash never stores the complete token:

* You can't retrieve a secure token after creation. If you lose one, [rotate it](#rotate-a-token).
* The [get API tokens](/api/get-all-api-tokens) endpoint returns the selector in the `secret` field and sets `secure: true`.
* The [update API token](/api/update-api-token) and [delete API token](/api/delete-api-token) endpoints accept either the selector or the complete token as the token identifier.
* [Events](/concepts/events) for secure token operations include the selector and `tokenVersion: 2`, never the complete token.

Secure storage applies to the Unleash database only. Other systems that hold your tokens store the complete token, including [Terraform state](/integrate/terraform) and Unleash Edge when you configure [persistent storage](/unleash-edge/configure#persistence) with Redis, S3, or a backup folder. Protect that storage and its backups as you would any other secret. For Edge, see [production deployment](/unleash-edge/deploy#production-deployment).

#### Legacy tokens

For a [legacy token](#token-versions), Unleash stores the complete token in its database. The [get API tokens](/api/get-all-api-tokens) endpoint returns the complete token in the `secret` field and sets `secure: false`.

Legacy tokens keep working after you upgrade to Unleash v8.3 or later. Unleash keeps the complete token in the database until you delete the token.

#### Upgrade to secure tokens

To replace your legacy tokens with secure tokens:

1. Find your legacy tokens. Their secret doesn't contain `v2_`, and the [get API tokens](/api/get-all-api-tokens) endpoint returns them with `secure: false`.
2. [Rotate](#rotate-a-token) each legacy backend, frontend, personal access, and service account token, including tokens created from the `INIT_*_API_TOKENS` environment variables.
3. If you use [Unleash Edge](/unleash-edge), upgrade to Edge v20.5.0 or later. Earlier versions work with secure tokens, but v20.5.0 improves the telemetry that Edge reports to Unleash about tokens in use.

## API token format

Backend, frontend, and deprecated admin tokens consist of three parts:

1. Project information
2. Environment
3. Secret

The parts are separated by two delimiters: a colon (`:`) between the projects and the environment, and a period (`.`) between the environment and the secret.

The project value can be one of:

* A single project ID, for example, `default`: the token can only access that project.
* `[]`: the token is valid for a specific set of projects. The project IDs are not shown in the token.
* `*`: the token is valid for all current and future projects.

The environment value is the name of an environment on your Unleash instance, such as `development`. Admin tokens use `*:*` as the project and environment value.

Personal access tokens and service account tokens start with `user:`, followed by the secret. They do not contain project or environment information.

The format of the secret depends on whether the token is a [secure token](#token-versions) or a [legacy token](#token-versions):

#### Secure tokens

The secret of a secure token starts with `v2_`, followed by the selector and a random string, both Base64 URL-encoded. Treat the complete token, including its selector, as a secret.

```
{{projects}}:{{environment}}.v2_{{selector}}_{{random}}
```

Personal access tokens and service account tokens use the same secret:

```
user:v2_{{selector}}_{{random}}
```

Some example API tokens are:

* A token with access to the `development` environment of a single project, `new-checkout-flow`:
  ```
  new-checkout-flow:development.v2_Y8mfumDNYCBPIzU_X48tyA_P3XdoA9Fel9KoioeVKw5FWmA-PGd2jxq9SYj2hqCwlk
  ```
* A token with access to the `production` environment in multiple projects:
  ```
  []:production.v2_jgjspSh-Z8ArlCHA91NDZQ_7o96eJAm7t1uJQFmT_Jzav5_MQv8yKjEpFmlsSYuP_M
  ```
* A token with access to the `development` environment in all current and future projects:
  ```
  *:development.v2_6mV-cGeq4amfxekzzk6nOA_H6QEoJKSQaqa66MxSyAz2lBvg1OlFxnTdHYAWOwIhHI
  ```
* A personal access token or service account token:
  ```
  user:v2_nn1XkimQkV8SSoUPEeuE3Q_48zN1UZIx-IPXr3vMB-8DS1zC-6LoZHtn0ara9dLTP4
  ```

#### Legacy tokens

The secret of a legacy token doesn't contain `v2_`. When Unleash creates a legacy token, the secret is a 56-character hexadecimal string. Tokens created from the `INIT_*_API_TOKENS` environment variables use the secret you provide, so their format can differ.

```
{{projects}}:{{environment}}.{{secret}}
```

For example:

```
new-checkout-flow:development.be44368985f7fb3237c584ef86f3d6bdada42ddbd63a019d26955178
```

Legacy personal access tokens and service account tokens use the same hexadecimal secret:

```
user:be7536c3a160ff15e3a92da45de531dd54bc1ae15d8455c0476f086b
```

In Unleash v4.3 or earlier, API tokens are a 56-character hexadecimal string with no additional information.

## API token permissions

v4.22

The following table provides a summary of what actions different roles can perform with API tokens:

| Role/Permission                               | Details                                                                                                                          |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Admin root role                               | Can view, create, update, or delete tokens for any project.                                                                      |
| Custom root role with API token permission    | Can view, create, update, or delete tokens for any project with the corresponding permission, such as `CREATE_CLIENT_API_TOKEN`. |
| Member project role                           | Can view, create, update, or delete tokens within the project.                                                                   |
| Custom project role with API token permission | Can view, create, update, or delete tokens within the project with the corresponding permission, `CREATE_PROJECT_API_TOKEN`.     |
| Viewer root role                              | Cannot view, create, update, or delete tokens.                                                                                   |
| Any role                                      | Can create personal access tokens.                                                                                               |

## Create an API token

Depending on your [permissions](#api-token-permissions), you can create API tokens in the Unleash Admin UI in four ways:

* **Admin settings > Access control > API access**: for backend or frontend tokens; requires the Admin root role, or a custom root role with [API token permissions](#api-token-permissions).
* **Admin settings > Service accounts > New service account**: for creating a service account and assigning a token.
* **Settings > API access** inside a project: for project-specific backend or frontend tokens; permitted for project Members or users with a [corresponding root role](#api-token-permissions).
* **Profile > View profile settings > Personal API tokens**: for [personal access tokens](#personal-access-tokens).

Unleash shows the complete token once, right after you create it. Copy it before you close the confirmation. Token lists show a token's name, type, and scope only.

To create tokens programmatically, use the [create API token](/api/create-api-token), [create project API token](/api/create-project-api-token), [create personal access token](/api/create-pat), or [create service account token](/api/create-service-account-token) endpoint. For [secure tokens](#token-versions), the create response is the only response that includes the complete token in the `secret` field.

## Token expiry and rotation

Requests with an expired token are rejected, so rotate tokens before they expire. How you set a token's expiration date depends on the token type:

| Token type                                                         | Admin UI                                                                                  | Admin API                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Backend](#backend-tokens) and [frontend](#frontend-tokens) tokens | By default, tokens are created without an expiration.                                     | Set the optional `expiresAt` property with the [create API token](/api/create-api-token) or [create project API token](/api/create-project-api-token) endpoint, or add an expiration date to an existing token with the [update API token](/api/update-api-token) endpoint. |
| [Personal access tokens](#personal-access-tokens)                  | Choose an expiration when creating the token: 7, 30, or 60 days, a custom date, or never. | Set the required `expiresAt` property with the [create personal access token](/api/create-pat) endpoint.                                                                                                                                                                    |
| [Service account tokens](#service-account-tokens)                  | Choose an expiration when creating the token: 7, 30, or 60 days, a custom date, or never. | Set the required `expiresAt` property with the [create service account token](/api/create-service-account-token) endpoint.                                                                                                                                                  |

> **Note**
>
> For [backend](#backend-tokens) and [frontend](#frontend-tokens) tokens, we recommend [rotating tokens](#rotate-a-token) on a regular schedule rather than setting an expiration date. This keeps token hygiene in your control without the risk of a token expiring unnoticed.

A token's access configuration, that is its type, projects, and environment, cannot be changed after creation. Unleash does not rotate tokens automatically.

### Rotate a token

To rotate a token:

1. Create a new token with the same type, project, and environment scope, and copy it.
2. Update your SDKs and integrations to use the new token.
3. Delete the old token once nothing is using it.

If you rotate a token in [Unleash Cloud](/support/availability#plans) or in a self-hosted instance running v8.3 or later, the new token is a [secure token](#token-versions). When you delete a [legacy token](#token-versions), Unleash removes the complete token from the database. Copies in existing database backups remain until your retention policy removes them, so keep protecting those backups.

### Expiration notifications

Beta

v8.1

Unleash notifies you before a [service account token](/concepts/service-accounts) or [personal access token](#personal-access-tokens) expires. The token's creator receives an email ahead of the expiration date, giving you time to rotate the token before your automations and integrations lose access.

## Connect a frontend SDK to Unleash using Edge

To connect a frontend SDK to Unleash using Unleash Edge, you need both a [backend](#backend-tokens) and [frontend token](#frontend-tokens):

* The frontend SDK needs a frontend token to communicate with Edge.
* Edge needs a backend token to communicate with the Unleash server.

Ensure that the backend token has at least the same project and environment scope as the frontend token.

![Diagram showing the types of tokens needed to connect a frontend SDK with Edge, and Edge with Unleash](/_fern-files/_img/794cb1c9c09dce923695e1ed380aa11098bb0cb1feb880b6b703df6130f3a94e.webp)

## Proxy client keys

> **Warning**
>
> Unleash Proxy is in maintenance mode. Use [Unleash Edge](/unleash-edge) instead.

You can use proxy client keys to connect [frontend SDKs](/sdks#frontend-sdks) to Unleash Proxy. Proxy client keys are not considered a secret and are safe to expose client-side.

Proxy client keys are arbitrary strings that you provide the Unleash proxy with on startup. They can be any string you choose, and you create them yourself.

> **Note**
>
> **Creating proxy client keys**
>
> To designate a string as a proxy client key, add it to the `clientKeys` list when starting the proxy. Connecting clients should then specify the same string as their client key.

Proxy client keys cannot be used to connect to the Unleash API; use API tokens instead.