Docs

Create a personal access token

POST
/users/me/personal_access_tokens

Creates a personal access token for the signed-in person and returns it once, with its record.

A personal access token (PAT) acts as the person who created it, capped by its scopes: send it as Authorization: Bearer <token> to the API or the MCP endpoint, from a CI job or an agent with no person at the keyboard. It reaches the operations an access token issued for a person reaches. On each call the person's grants at that moment decide, and an operation that names a scope the token was not created with is refused with auth.scope_insufficient, naming the scope.

expires_at is required and at most 90 days away; a token cannot be extended. It also stops working when it is revoked with revokeMyPersonalAccessToken, when its owner's password is set (setUserPassword), while its owner is not active, and when its owner is deleted.

Authenticate with a console session cookie, or an access token issued for the person with the scope personal_access_token.create, which consent never preselects. A session creates one only within 15 minutes of a sign-in in that session; later it answers 403 tkn.pat_sign_in_required, and the person signs in again. Neither creates one when its session signed in before the person's current password was set: after a password set, the person signs in again first. Created with an access token, the PAT holds no scope that token lacks, and its record names the token's client. A personal access token never creates another. The person must be homed in the platform project. Cookie requests follow that scheme's CSRF rules. The token is in this response only; the server keeps a hash of its secret. Records an auth.token.issued event.

Authorization

headerAuthorizationBearer <token>

Scope: personal_access_token.create

Request Body

application/json
  1. body
name*string

A name that tells this token from your others, 1–200 characters.

Length1 <= length <= 200
scopes*array<>

The scopes the token may be used with, one or more. Each must be a scope an access token issued for a person can be used with: the ones the MCP endpoint's metadata lists in scopes_supported, except personal_access_token.create. Created with an access token, it holds no scope that token was not issued with.

Items1 <= items <= 100
expires_at*string

When the token stops working: in the future, and at most 90 days from now. It cannot be extended later.

Formatdate-time

Response Body

The token was created. Its token is shown only here.

application/json
  1. response

The new token's record, and the token, which no other response returns.

id*personal-access-token-id

The personal access token's ID (tkn_<opaque>): the id that createMyPersonalAccessToken (POST /users/me/personal_access_tokens) returns or listMyPersonalAccessTokens lists. It is not the token.

Match^tkn_[a-zA-Z0-9_-]+$
name*string

The name its owner gave it, to tell it from their others.

scopes*array<string>

The scopes it may be used with. They cap what its owner's grants allow and never grant anything themselves.

created_at*string

When it was created.

Formatdate-time
expires_at*string

When it stops working. A token past this time is refused.

Formatdate-time
client_id?|

The OAuth client of the access token it was created with, such as the CLI or an MCP client. Null when it was created from a console session.

token*string

The token: zpat_, its id without tkn_, _, then a random secret and a checksum. Send it as Authorization: Bearer <token>. Store it now: the server keeps only a hash of it, and no response returns it again.

Example Request
import { createZitadelApi } from "@zitadel/api/client";import { configureZitadel, getApi } from "@zitadel/api/config";// In the browser, through the SDK proxy: the session cookie authenticates the call.const session = getApi(configureZitadel({ projectId: "proj_01KWH1P4MYS7F0N9WD3P2E4YM5" }));// A write the session cookie authenticates carries the session's CSRF token.const { csrf_token } = await session.getMySessionCsrfToken();const api = createZitadelApi(  session.client.with({    fetch: (input, init) => {      const headers = new Headers(init?.headers);      headers.set("X-Zitadel-CSRF", csrf_token);      return fetch(input, { ...init, headers });    },  }),);const myPersonalAccessToken = await api.createMyPersonalAccessToken({  name: "Deploy from CI",  scopes: ["project.read", "deployment.read"],  expires_at: "2027-03-02T10:00:00Z",});
Example Response
{  "id": "string",  "name": "string",  "scopes": [    "string"  ],  "created_at": "2019-08-24T14:15:22Z",  "expires_at": "2019-08-24T14:15:22Z",  "client_id": "string",  "token": "string"}

Was this helpful?