# Agent tokens

An _agent token_ is a long-lived credential that a Buildkite agent running in a [self-hosted architecture](/docs/pipelines/architecture#self-hosted-hybrid-architecture) can use to connect to Buildkite and register for work. Stack controllers also use agent tokens to access the [Stacks API](/docs/apis/agent-api/stacks). Agent tokens connect to Buildkite using a [cluster](/docs/pipelines/security/clusters), and can be accessed from the cluster's **Agent Tokens** page.

For stack-managed ephemeral agents, use a short-lived [job acquisition token](/docs/agent/self-hosted/job-acquisition-tokens) as the registration credential. This keeps the agent token in the stack controller and out of job workloads.

A user who is a Buildkite organization administrator or a [maintainer of a cluster](/docs/pipelines/security/clusters/manage#manage-maintainers-on-a-cluster) within the organization can manage agent tokens for that cluster.

If you are managing agents in an unclustered environment, refer to [Working with unclustered agent tokens](/docs/agent/self-hosted/tokens#working-with-unclustered-agent-tokens) instead.

## The initial agent token

When you create a new organization in Buildkite, and visit the [**Default cluster**](/docs/pipelines/security/clusters/manage#setting-up-clusters) for the first time, an initial agent token is created (called **Initial agent token** within this cluster). This token can be used for testing and development and is only revealed once during this process. It's recommended that you [create new, specific tokens](#create-a-token) for each new environment.

## Using and storing tokens

An agent token is used by the Buildkite agent's [start](/docs/agent/cli/reference/start#starting-an-agent) command, and can be provided on the command line, set in the [configuration file](/docs/agent/self-hosted/configure), or provided using the [environment variable](/docs/pipelines/configure/environment-variables) `BUILDKITE_AGENT_TOKEN`.

It's recommended you use your platform's secret storage (such as the [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html)) to allow for easier rollover and management of your agent tokens.

## Create a token

New agent tokens can be created by a [cluster maintainer](/docs/pipelines/security/clusters/manage#manage-maintainers-on-a-cluster) or Buildkite organization administrator using the [**Agent Tokens** page of a cluster](#create-a-token-using-the-buildkite-interface), as well as Buildkite's [REST API](#create-a-token-using-the-rest-api) or [GraphQL API](#create-a-token-using-the-graphql-api).

For these API requests, the _cluster ID_ value submitted as part of the request is the target cluster the token is associated with.

> 📘 An agent token's value is only displayed once
> As soon as the agent token's value is displayed, copy its value and save it in a secure location.
> If you forget to do this, you'll need to create a new token to obtain its value.

It is possible to create multiple agent tokens (for your Default cluster or any other cluster in your Buildkite organization) using the processes described in this section.

### Using the Buildkite interface

To create an agent token for a cluster using the Buildkite interface:

1. Select **Agents** in the global navigation to access the **Clusters** page.
1. Select the cluster that will be associated with this agent token.
1. Select **Agent Tokens** > **New Token**.
1. In the **Description** field, enter an appropriate description for the agent token.

    **Note:** The token description should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent Tokens** page of your specific cluster the agent connects to. This page can be accessed by selecting **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.

1. If you need to restrict which network addresses are allowed to use this agent token, enter these addresses (using [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing)) into the **Allowed IP Addresses** field.

    **Note:** Leave this field empty if there is no need to restrict the use of this agent token by network address. Learn more about this feature in [Restrict an agent token's access by IP address](/docs/pipelines/security/clusters/manage#restrict-an-agent-tokens-access-by-ip-address).

1. Select **Create Token**.

    Follow the instructions to copy and save your token to a secure location and select **Okay, I'm done!**. The new agent token appears on the cluster's **Agent Tokens** page.

### Using the REST API

To [create an agent token](/docs/apis/rest-api/clusters/agent-tokens#create-a-token) using the [REST API](/docs/apis/rest-api), run the following example `curl` command:

```bash
curl -H "Authorization: Bearer $TOKEN" \
  -X POST "https://api.buildkite.com/v2/organizations/{org.slug}/clusters/{cluster.id}/tokens" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "A description",
    "expires_at": "2026-01-01T00:00:00Z",
    "allowed_ip_addresses": "0.0.0.0/0"
  }'
```

where:

- `$TOKEN` is an [API access token](https://buildkite.com/user/api-access-tokens) scoped to the relevant **Organization** and **REST API Scopes** that your request needs access to in Buildkite.

- `{org.slug}` can be obtained:

    * From the end of your Buildkite URL, after accessing **Pipelines** in the global navigation of your organization in Buildkite.

    * By running the [List organizations](/docs/apis/rest-api/organizations#list-organizations) REST API query to obtain this value from `slug` in the response. For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations"
        ```

- `{cluster.id}` can be obtained:

    * From the **Cluster Settings** page of your target cluster. To do this:
        1. Select **Agents** (in the global navigation) > the specific cluster > **Settings**.
        1. Once on the **Cluster Settings** page, copy the `id` parameter value from the **GraphQL API Integration** section, which is the `{cluster.id}` value.

    * By running the [List clusters](/docs/apis/rest-api/clusters#clusters-list-clusters) REST API query and obtain this value from the `id` in the response associated with the name of your target cluster (specified by the `name` value in the response). For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations/{org.slug}/clusters"
        ```

- `description` (required) should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent tokens** page of your specific cluster the agent connects to. To access this page, select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.

- `expires_at` (optional) is the date and time at which the token expires and prevents agents configured with this token from re-connecting to their Buildkite cluster. If not provided, the token will never expire. The timestamp for `expires_at` must be in ISO8601 format (2025-01-01T00:00:00Z) and must be at least 10 minutes in the future at the moment of token creation. Once set, `expires_at` cannot be updated.

- `allowed_ip_addresses` (optional) is/are the IP addresses that agents must be accessible through, to access this token and connect to your Buildkite cluster. Use space-separated [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) to enter IP addresses for this field value.

The new agent token appears on the cluster's **Agent Tokens** page.

### Using the GraphQL API

To [create an agent token](/docs/apis/graphql/cookbooks/clusters#create-agent-token-with-an-expiration-date) using the [GraphQL API](/docs/apis/graphql-api), run the following example mutation:

```graphql
mutation {
  clusterAgentTokenCreate(
    input: {
      organizationId: "organization-id"
      clusterId: "cluster-id"
      description: "A description"
      expiresAt: "2026-01-01T00:00:00Z"
      allowedIpAddresses: "0.0.0.0/0"
    }
  ) {
    clusterAgentToken {
      id
      uuid
      description
      allowedIpAddresses
      cluster {
        id
        uuid
        organization {
          id
          uuid
        }
      }
      createdBy {
        id
        uuid
        email
      }
    }
    tokenValue
  }
}
```

where:

- `organizationId` (required) can be obtained:

    * From the **GraphQL API Integration** section of your **Organization Settings** page, accessed by selecting **Settings** in the global navigation of your organization in Buildkite.

    * By running a `getCurrentUsersOrgs` GraphQL API query to obtain the organization slugs for the current user's accessible organizations, followed by a [getOrgId](/docs/apis/graphql/schemas/query/organization) query, to obtain the organization's `id` using the organization's slug. For example:

        Step 1. Run `getCurrentUsersOrgs` to obtain the organization slug values in the response for the current user's accessible organizations:

        ```graphql
        query getCurrentUsersOrgs {
          viewer {
            organizations {
              edges {
                node {
                  name
                  slug
                }
              }
            }
          }
        }
        ```

        Step 2. Run `getOrgId` with the appropriate slug value above to obtain this organization's `id` in the response:

        ```graphql
        query getOrgId {
          organization(slug: "organization-slug") {
            id
            uuid
            slug
          }
        }
        ```

        **Note:** The `organization-slug` value can also be obtained from the end of your Buildkite URL, by selecting **Pipelines** in the global navigation of your organization in Buildkite.

- `clusterId` (required) can be obtained:

    * From the **Cluster Settings** page of your target cluster. To do this:
        1. Select **Agents** (in the global navigation) > the specific cluster > **Settings**.
        1. Once on the **Cluster Settings** page, copy the `cluster` parameter value from the **GraphQL API Integration** section, which is the `cluster.id` value.

    * By running the [List clusters](/docs/apis/graphql/cookbooks/clusters#list-clusters) GraphQL API query and obtain this value from the `id` in the response associated with the name of your target cluster (specified by the `name` value in the response). For example:

        ```graphql
        query getClusters {
          organization(slug: "organization-slug") {
            clusters(first: 10) {
              edges {
                node {
                  id
                  name
                  uuid
                  color
                  description
                }
              }
            }
          }
        }
        ```

- `description` (required) should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent tokens** page of your specific cluster the agent connects to. To access this page, select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.

- `expiresAt` (optional) is the date and time at which the token expires and prevents agents configured with this token from re-connecting to their Buildkite cluster. The timestamp for `expiresAt` must be in ISO8601 format (2025-01-01T00:00:00Z) and must be at least 10 minutes in the future at the moment of token creation. Once set, `expiresAt` cannot be updated.

- `allowedIpAddresses` (optional) is/are the IP addresses that agents must be accessible through, to access this token and connect to your Buildkite cluster. Use space-separated [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) to enter IP addresses for this field value.

The new agent token appears on the cluster's **Agent Tokens** page.

## Update a token

Agent tokens can be updated by a [cluster maintainer](/docs/pipelines/security/clusters/manage#manage-maintainers-on-a-cluster) or Buildkite organization administrator using the [**Agent Tokens** page of a cluster](#update-a-token-using-the-buildkite-interface), as well as Buildkite's [REST API](#update-a-token-using-the-rest-api) or [GraphQL API](#update-a-token-using-the-graphql-api).

Only the **Description** and **Allowed IP Addresses** of an existing agent token can be updated. **Expiration date** for a token cannot be updated.

For these API requests, the _cluster ID_ value submitted as part of the request is the target cluster the token is associated with.

### Using the Buildkite interface

To update a cluster's agent token using the Buildkite interface:

1. Select **Agents** in the global navigation to access the **Clusters** page.
1. Select the cluster containing the agent token to update.
1. Select **Agent Tokens** and on this page, expand the agent token to update.
1. Select **Edit** and update the following fields as required:
    * **Description** should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent tokens** page of your specific cluster the agent connects to. This page can be accessed by selecting **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.
    * **Allowed IP Addresses** is/are the IP addresses which agents must be accessible through to access this agent token and be able to connect to Buildkite using your cluster. Use space-separated [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) to enter IP addresses for this field value.

        Leave this field empty if there is no need to restrict the use of this agent token by network address. Learn more about this feature in [Restrict an agent token's access by IP address](/docs/pipelines/security/clusters/manage#restrict-an-agent-tokens-access-by-ip-address).

1. Select **Save Token** to save your changes.

    The agent token's updates will appear on the cluster's **Agent Tokens** page.

### Using the REST API

To [update an agent token](/docs/apis/rest-api/clusters/agent-tokens#update-a-token) using the [REST API](/docs/apis/rest-api), run the following example `curl` command:

```bash
curl -H "Authorization: Bearer $TOKEN" \
  -X PUT "https://api.buildkite.com/v2/organizations/{org.slug}/clusters/{cluster.id}/tokens/{id}" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "A description",
    "allowed_ip_addresses": "202.144.0.0/24 198.51.100.12"
  }'
```

where:

- `$TOKEN` is an [API access token](https://buildkite.com/user/api-access-tokens) scoped to the relevant **Organization** and **REST API Scopes** that your request needs access to in Buildkite.

- `{org.slug}` can be obtained:

    * From the end of your Buildkite URL, after accessing **Pipelines** in the global navigation of your organization in Buildkite.

    * By running the [List organizations](/docs/apis/rest-api/organizations#list-organizations) REST API query to obtain this value from `slug` in the response. For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations"
        ```

- `{cluster.id}` can be obtained:

    * From the **Cluster Settings** page of your target cluster. To do this:
        1. Select **Agents** (in the global navigation) > the specific cluster > **Settings**.
        1. Once on the **Cluster Settings** page, copy the `id` parameter value from the **GraphQL API Integration** section, which is the `{cluster.id}` value.

    * By running the [List clusters](/docs/apis/rest-api/clusters#clusters-list-clusters) REST API query and obtain this value from the `id` in the response associated with the name of your target cluster (specified by the `name` value in the response). For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations/{org.slug}/clusters"
        ```

- `{id}` is that of the agent token, whose value can be obtained:

    * From the Buildkite URL path when editing the agent token. To do this:

        - Select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens** > expand the agent token > **Edit**.
        - Copy the ID value between `/tokens/` and `/edit` in the URL.

    * By running the [List tokens](/docs/apis/rest-api/clusters/agent-tokens#list-tokens) REST API query and obtain this value from the `id` in the response associated with the description of your token (specified by the `description` value in the response). For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \\
          -X GET "https://api.buildkite.com/v2/organizations/{org.slug}/clusters/{cluster.id}/tokens"
        ```

- `description` (optional) should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent tokens** page of your specific cluster the agent connects to. To access this page, select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.

- `allowed_ip_addresses` (optional) is/are the IP addresses that agents must be accessible through, to access this token and connect to your Buildkite cluster. Use space-separated [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) to enter IP addresses for this field value.

    This field can be omitted (where the default value is `0.0.0.0/0`) if there is no need to restrict the use of this agent token by network address, or change the field's current value. Learn more about this feature in [Restrict an agent token's access by IP address](/docs/pipelines/security/clusters/manage#restrict-an-agent-tokens-access-by-ip-address).

### Using the GraphQL API

To [update an agent token](/docs/apis/graphql/schemas/mutation/clusteragenttokenupdate) using the [GraphQL API](/docs/apis/graphql-api), run the following example mutation:

```graphql
mutation {
  clusterAgentTokenUpdate(
    input: {
      organizationId: "organization-id"
      id: "token-id"
      description: "A description"
      allowedIpAddresses: "202.144.0.0/24 198.51.100.12"
    }
  ) {
    clusterAgentToken {
      id
      uuid
      description
      allowedIpAddresses
      cluster {
        id
        uuid
        organization {
          id
          uuid
        }
      }
      createdBy {
        id
        uuid
        email
      }
    }
  }
}
```

where:

- `organizationId` (required) can be obtained:

    * From the **GraphQL API Integration** section of your **Organization Settings** page, accessed by selecting **Settings** in the global navigation of your organization in Buildkite.

    * By running a `getCurrentUsersOrgs` GraphQL API query to obtain the organization slugs for the current user's accessible organizations, followed by a [getOrgId](/docs/apis/graphql/schemas/query/organization) query, to obtain the organization's `id` using the organization's slug. For example:

        Step 1. Run `getCurrentUsersOrgs` to obtain the organization slug values in the response for the current user's accessible organizations:

        ```graphql
        query getCurrentUsersOrgs {
          viewer {
            organizations {
              edges {
                node {
                  name
                  slug
                }
              }
            }
          }
        }
        ```

        Step 2. Run `getOrgId` with the appropriate slug value above to obtain this organization's `id` in the response:

        ```graphql
        query getOrgId {
          organization(slug: "organization-slug") {
            id
            uuid
            slug
          }
        }
        ```

        **Note:** The `organization-slug` value can also be obtained from the end of your Buildkite URL, by selecting **Pipelines** in the global navigation of your organization in Buildkite.

- `id` (required) is that of the agent token, whose value can only be obtained using the APIs, by running a [getClustersAgentTokenIds](/docs/apis/graphql/schemas/query/organization) query, to obtain the organization's clusters and each of their agent tokens' `id` values in the response. For example:

      ```graphql
      query getClustersAgentTokenIds {
        organization(slug: "organization-slug") {
          clusters(first: 10) {
            edges {
              node {
                name
                id
                agentTokens(first: 10) {
                  edges {
                    node {
                      description
                      id
                    }
                  }
                }
              }
            }
          }
        }
      }
      ```

- `description` (required) should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), as it is listed on the **Agent tokens** page of your specific cluster the agent connects to. To access this page, select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens**.

    If you do not need to change the existing `description` value, specify the existing field value in the request.

- `allowedIpAddresses` (optional) is/are the IP addresses that agents must be accessible through, to access this token and connect to your Buildkite cluster. Use space-separated [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) to enter IP addresses for this field value.

    This field can be omitted (where the default value is `0.0.0.0/0`) if there is no need to restrict the use of this agent token by network address, or change the field's current value. Learn more about this feature in [Restrict an agent token's access by IP address](/docs/pipelines/security/clusters/manage#restrict-an-agent-tokens-access-by-ip-address).

The agent token's updates will appear on the cluster's **Agent Tokens** page.

## Revoke a token

Agent tokens can be revoked by a [cluster maintainer](/docs/pipelines/security/clusters/manage#manage-maintainers-on-a-cluster) or Buildkite organization administrator using the [**Agent Tokens** page of a cluster](#revoke-a-token-using-the-buildkite-interface), as well as Buildkite's [REST API](#revoke-a-token-using-the-rest-api) or [GraphQL API](#revoke-a-token-using-the-graphql-api).

For these API requests, the _cluster ID_ value submitted as part of the request is the target cluster the token is associated with.

Once a token is revoked, no new agents will be able to start with that token. Revoking a token does not affect any connected agents.

### Using the Buildkite interface

To revoke a cluster's agent token using the Buildkite interface:

1. Select **Agents** in the global navigation to access the **Clusters** page.
1. Select the cluster containing the agent token to revoke.
1. Select **Agent Tokens** and on this page, expand the agent token to revoke.
1. Select **Revoke** > **Revoke Token** in the confirmation message.

### Using the REST API

To [revoke an agent token](/docs/apis/rest-api/clusters/agent-tokens#revoke-a-token) using the [REST API](/docs/apis/rest-api), run the following example `curl` command:

```bash
curl -H "Authorization: Bearer $TOKEN" \
  -X DELETE "https://api.buildkite.com/v2/organizations/{org.slug}/clusters/{cluster.id}/tokens/{id}"
```

where:

- `$TOKEN` is an [API access token](https://buildkite.com/user/api-access-tokens) scoped to the relevant **Organization** and **REST API Scopes** that your request needs access to in Buildkite.

- `{org.slug}` can be obtained:

    * From the end of your Buildkite URL, after accessing **Pipelines** in the global navigation of your organization in Buildkite.

    * By running the [List organizations](/docs/apis/rest-api/organizations#list-organizations) REST API query to obtain this value from `slug` in the response. For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations"
        ```

- `{cluster.id}` can be obtained:

    * From the **Cluster Settings** page of your target cluster. To do this:
        1. Select **Agents** (in the global navigation) > the specific cluster > **Settings**.
        1. Once on the **Cluster Settings** page, copy the `id` parameter value from the **GraphQL API Integration** section, which is the `{cluster.id}` value.

    * By running the [List clusters](/docs/apis/rest-api/clusters#clusters-list-clusters) REST API query and obtain this value from the `id` in the response associated with the name of your target cluster (specified by the `name` value in the response). For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \
          -X GET "https://api.buildkite.com/v2/organizations/{org.slug}/clusters"
        ```

- `{id}` is that of the agent token, whose value can be obtained:

    * From the Buildkite URL path when editing the agent token. To do this:

        - Select **Agents** (in the global navigation) > the specific cluster > **Agent Tokens** > expand the agent token > **Edit**.
        - Copy the ID value between `/tokens/` and `/edit` in the URL.

    * By running the [List tokens](/docs/apis/rest-api/clusters/agent-tokens#list-tokens) REST API query and obtain this value from the `id` in the response associated with the description of your token (specified by the `description` value in the response). For example:

        ```bash
        curl -H "Authorization: Bearer $TOKEN" \\
          -X GET "https://api.buildkite.com/v2/organizations/{org.slug}/clusters/{cluster.id}/tokens"
        ```

### Using the GraphQL API

To [revoke an agent token](/docs/apis/graphql/cookbooks/clusters#revoke-an-agent-token) using the [GraphQL API](/docs/apis/graphql-api), run the following example mutation:

```graphql
mutation {
  clusterAgentTokenRevoke(
    input: {
      organizationId: "organization-id"
      id: "token-id"
    }
  ) {
    deletedClusterAgentTokenId
  }
}
```

where:

- `organizationId` (required) can be obtained:

    * From the **GraphQL API Integration** section of your **Organization Settings** page, accessed by selecting **Settings** in the global navigation of your organization in Buildkite.

    * By running a `getCurrentUsersOrgs` GraphQL API query to obtain the organization slugs for the current user's accessible organizations, followed by a [getOrgId](/docs/apis/graphql/schemas/query/organization) query, to obtain the organization's `id` using the organization's slug. For example:

        Step 1. Run `getCurrentUsersOrgs` to obtain the organization slug values in the response for the current user's accessible organizations:

        ```graphql
        query getCurrentUsersOrgs {
          viewer {
            organizations {
              edges {
                node {
                  name
                  slug
                }
              }
            }
          }
        }
        ```

        Step 2. Run `getOrgId` with the appropriate slug value above to obtain this organization's `id` in the response:

        ```graphql
        query getOrgId {
          organization(slug: "organization-slug") {
            id
            uuid
            slug
          }
        }
        ```

        **Note:** The `organization-slug` value can also be obtained from the end of your Buildkite URL, by selecting **Pipelines** in the global navigation of your organization in Buildkite.

- `id` (required) is that of the agent token, whose value can only be obtained using the APIs, by running a [getClustersAgentTokenIds](/docs/apis/graphql/schemas/query/organization) query, to obtain the organization's clusters and each of their agent tokens' `id` values in the response. For example:

      ```graphql
      query getClustersAgentTokenIds {
        organization(slug: "organization-slug") {
          clusters(first: 10) {
            edges {
              node {
                name
                id
                agentTokens(first: 10) {
                  edges {
                    node {
                      description
                      id
                    }
                  }
                }
              }
            }
          }
        }
      }
      ```

## Scope of access

An agent token is specific to the cluster it was associated with when created (within a Buildkite organization), and can be used to register an agent with any [queue](/docs/agent/queues) defined in that cluster. Agent tokens can not be shared between different clusters within an organization, or between different organizations.

## Agent token lifetime

Agent tokens [created using the Buildkite interface](#create-a-token-using-the-buildkite-interface) do not expire and need to be rotated manually.

However, using Buildkite's APIs, you can specify an optional expiration date attribute with a timestamp value in your API call to create an agent token—[`expires_at` using the REST API](#create-a-token-using-the-rest-api) or [`expiresAt` using the GraphQL API](#create-a-token-using-the-graphql-api). The ability to set an expiration timestamp on an agent token is a security compliance and token lifecycle management feature, which allows you to implement an automated token rotation process using the Buildkite API, replacing any previous, more manual rotation processes for long-lived agent tokens. Note that the existing agent tokens will continue to work without expiration, unless they are manually revoked.

There is no maximum expiration duration for an agent token, although a minimum of 10 minutes from the current time is required. After an agent token has expired, it is displayed with the following message in the Buildkite interface:

⚠️ **This token expired on ...**

An expired agent token will prevent agents configured with this token from being able to re-connect to its Buildkite cluster. However, agents currently connected to their cluster at the time of expiration won't be affected.

> 📘 Agent token expiration format
> The timestamp must be set in ISO8601 format (for example, `2025-01-01T00:00:00Z`). This timestamp value cannot be changed on an existing agent token. An error is returned if an attempt is made to update the expiration date field of an existing agent token.

## Additional agent tokens

In addition to the agent token, the Buildkite agent automatically generates and manages two internal types of tokens during its operation—[session tokens](#additional-agent-tokens-session-tokens) and [job tokens](#additional-agent-tokens-job-tokens).

### Session tokens

Session tokens are internal tokens that last for the lifetime of the agent connection. They are used by the agent to request and start new jobs, and remain valid until the agent disconnects from Buildkite.

### Job tokens

Job tokens are internal agent access tokens generated when each job starts. They expire when the job finishes. The job receives its token through the [environment variable](/docs/pipelines/configure/environment-variables) `BUILDKITE_AGENT_ACCESS_TOKEN`. The Buildkite agent uses the token to manage the job's lifecycle in the Buildkite control plane. CLI commands, including [annotate](/docs/agent/cli/reference/annotate), [artifact](/docs/agent/cli/reference/artifact), [meta-data](/docs/agent/cli/reference/meta-data), and [pipeline](/docs/agent/cli/reference/pipeline), also use the token for authorization.

You can set a default or maximum [command timeout](/docs/pipelines/configure/build-timeouts#command-timeouts) to further limit a job token's lifetime.

In most cases, job tokens can only be used to perform operations on the job they refer to. For example, you couldn't use a job token to issue an OIDC token pretending to be another job, or to emit logs to another job.

That said, certain operations can be used for cross-job and cross-build coordination. Job tokens are, by default, permitted to perform the following operations on any job in the same cluster:

- Create, read, and update metadata
- Create, update, and remove annotations
- Upload and download artifacts

At present, job tokens can create (push) metadata, annotations, and artifacts to other jobs. However, where possible, we recommend pulling data from other jobs rather than pushing data to them. Buildkite may further restrict job token permissions in the future by allowing only read access to other jobs' data.

### Token exchange process

When an agent starts, it follows the token exchange process:

1. The agent connects to the Buildkite agent API to register itself using its configured _agent token_ (`BUILDKITE_AGENT_TOKEN`).
1. The Agent API generates and returns a [session token](#additional-agent-tokens-session-tokens) to the agent.
1. The agent uses this session token to poll for available jobs and manage its connection to Buildkite.
1. When the agent accepts a job, Buildkite generates a [job token](#additional-agent-tokens-job-tokens) specific to that job.



| Token type | Generated by | Use | Lifetime |
| --- | --- | --- | --- |
| Agent token | Buildkite organization admin or cluster maintainer | Initial agent registration and authentication. | Forever unless expiration date is set during creation with GraphQL or REST API, or is manually revoked. |
| Session token (internal) | Buildkite agent API during registration | Agent lifecycle APIs, polling for jobs, and starting jobs. | Until the agent disconnects. |
| Job token (internal) | Buildkite agent API when job is accepted | Local Job API access for CLI commands (including [annotate](/docs/agent/cli/reference/annotate), [artifact](/docs/agent/cli/reference/artifact), [meta-data](/docs/agent/cli/reference/meta-data), and [pipeline](/docs/agent/cli/reference/pipeline) commands). | Until the job finishes. |



>📘 Job tokens are not supported in agents prior to v3.39.0
> Agents prior to v3.39.0 use the session token for the `BUILDKITE_AGENT_ACCESS_TOKEN` environment variable and the job APIs.

## Working with unclustered agent tokens

> 🚧 This section documents a deprecated Buildkite feature
> _It is not possible to create and work with unclustered agents for any Buildkite organizations created after the official release of clusters on February 26, 2024._ Therefore, unclustered agent tokens are not relevant to these organizations, including this section of the Agent tokens page.
> Previously, agents only connected directly to Buildkite using a token which was created and managed by the processes described in this page section. These tokens are now a deprecated feature of Buildkite, and are referred to as _unclustered agent tokens_. Unclustered agent tokens, however, are still available to customers who have not yet migrated their pipelines to a [cluster](/docs/pipelines/security/clusters).
> _Agent tokens_ are now associated with clusters, and connect to Buildkite through a specific cluster within an organization. Learn more about how to manage agent tokens for clusters from the top of this main [Agent tokens](/docs/agent/self-hosted/tokens) page and how to [migrate your unclustered agents across to a cluster](/docs/pipelines/security/clusters/migrate-from-unclustered-to-clustered-agents).

Any Buildkite organization created before February 26, 2024 has an **Unclustered** area for managing _unclustered agents_, accessible through **Agents** (from the global navigation) > **Unclustered** of the Buildkite interface, where an _unclustered agent_ refers to any agent that is not associated with a cluster.

A Buildkite agent requires a token to connect to Buildkite and register for work. If you need to connect an _unclustered agent_ to Buildkite, then you need to create an _unclustered agent token_ to do so.

### The default token

Your Buildkite organization's unclustered agent tokens page, accessible through **Agents** (from the global navigation) > **Unclustered** > **Agent Tokens**, may have the **Default agent registration token**, which is the original default token when your organization was created. If you had previously saved this token's value in a safe place, this token can be used for testing and development. However, it's recommended that you [create new, specific tokens](#working-with-unclustered-agent-tokens-create-a-token) for each new environment.

### Using and storing tokens

The requirements for using and storing unclustered agent tokens are similar to those for [agent tokens associated with a cluster](#using-and-storing-tokens).

### Create a token

New unclustered agent tokens can be created using the [GraphQL API](/docs/apis/graphql-api) with the `agentTokenCreate` mutation.

For example:

```graphql
mutation {
  agentTokenCreate(input: {
    organizationID: "organization-id",
    description: "A description"
  }) {
    tokenValue
    agentTokenEdge {
      node {
        id
      }
    }
  }
}
```

> 📘 An unclustered agent token's value is only displayed once
> As soon as the unclustered agent token's value is displayed, copy its value and save it in a secure location.
> If you forget to do this, you'll need to create a new token to obtain its value.

You can find your `organization-id` in your Buildkite organization settings page, or by running the following GraphQL query:

```graphql
query GetOrgID {
  organization(slug: "organization-slug") {
    id
  }
}
```

The token description should clearly identify the environment the token is intended to be used for (for example, `Read-only token for static site generator`), and is listed on the **Agent tokens** page of the **Agents** (from the global navigation) > **Unclustered** area.

It is possible to create multiple unclustered agent tokens using the GraphQL API.

### Revoke a token

Unclustered agent tokens can be revoked using the [GraphQL API](/docs/apis/graphql/cookbooks/agents#revoke-an-unclustered-agent-token) query with the `agentTokenRevoke ` mutation.

You need to pass your unclustered agent token as the ID in the mutation.

First, you can retrieve a list of agent token IDs using this query:

```graphql
query GetAgentTokenID {
  organization(slug: "organization-slug") {
    agentTokens(first:50) {
      edges {
        node {
          id
          uuid
          description
        }
      }
    }
  }
}
```

Then, using the token ID, revoke the unclustered agent token:

```graphql
mutation {
  agentTokenRevoke(input: {
    id: "token-id",
    reason: "A reason"
  }) {
    agentToken {
      description
      revokedAt
      revokedReason
    }
  }
}
```

Once a token is revoked, no new agents will be able to start with that token. Revoking a token does not affect any connected agents.

### Scope of access

Unclustered agent tokens are specific to each Buildkite organization (created before February 26, 2024), and can be used to register an agent with any [unclustered queue](/docs/agent/queues#setting-up-queues-for-unclustered-agents). Unclustered agent tokens can not be shared between Buildkite organizations.

### Additional agent tokens

In addition to the unclustered agent token (and as is the case for [agent tokens associated with a cluster](#additional-agent-tokens)), the Buildkite agent automatically generates and manages two internal types of tokens during its operation—[session tokens](#additional-agent-tokens-session-tokens) and [job tokens](#additional-agent-tokens-job-tokens).

#### Token exchange process

When an agent starts, it follows the token exchange process:

1. The agent connects to the Buildkite agent API to register itself using its configured _unclustered agent token_ (`BUILDKITE_AGENT_TOKEN`).
1. The Agent API generates and returns a _session token_ to the agent.
1. The agent uses this session token to poll for available jobs and manage its connection to Buildkite.
1. When the agent accepts a job, Buildkite generates a _job token_ specific to that job.



| Token type | Generated by | Use | Lifetime |
| --- | --- | --- | --- |
| Unclustered agent token | Buildkite organization administrator | Initial agent registration and authentication. | Forever unless manually revoked. |
| Session token (internal) | Buildkite agent API during registration | Agent lifecycle APIs, polling for jobs, and starting jobs. | Until the agent disconnects. |
| Job token (internal) | Buildkite agent API when job is accepted | Local Job API access for CLI commands (including [annotate](/docs/agent/cli/reference/annotate), [artifact](/docs/agent/cli/reference/artifact), [meta-data](/docs/agent/cli/reference/meta-data), and [pipeline](/docs/agent/cli/reference/pipeline) commands). | Until the job finishes. |



> 📘 Job tokens not supported in agents prior to v3.39.0
> Agents prior to v3.39.0 use the session token for the `BUILDKITE_AGENT_ACCESS_TOKEN` environment variable and the job APIs.
