---
title: "Create an agent token"
method: POST
path: "/api/v4/projects/{id}/cluster_agents/{agent_id}/tokens"
tags: ["cluster_agents"]
---

# Create an agent token

`POST /api/v4/projects/{id}/cluster_agents/{agent_id}/tokens`

## Request

- Base URL: `https://gitlab.com`
- URL: `https://gitlab.com/api/v4/projects/{id}/cluster_agents/{agent_id}/tokens`
- Auth: none declared

Creates a token for an agent. You must have the Maintainer or Owner role to use this endpoint. An agent can have only two active tokens at one time.

## Path parameters

- `id` string, required
- `agent_id` integer, required

## Request body

- PostApiV4ProjectsIdClusterAgentsAgentIdTokens: Create an agent token
  - `name` string, required: The name for the token
  - `description` string: The description for the token

## Response `201`

Create an agent token

- APIEntitiesClustersAgentTokenWithToken: API_Entities_Clusters_AgentTokenWithToken model
  - `id` integer, required
  - `name` string, required
  - `description` string, required
  - `agent_id` integer, required
  - `status` string, required
  - `created_at` string, date-time, required
  - `created_by_user_id` integer, required
  - `last_used_at` string, date-time, required
  - `token` string, required

---

[API](https://skmtc.dev/gitlab/apis/gitlab-api.md) - [All operations](https://skmtc.dev/gitlab/apis/gitlab-api/llms.txt) - [OpenAPI document](https://skmtc.dev/gitlab/apis/gitlab-api/revisions/b234947ef3f2?raw)
