Create a personal access token
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.
AuthorizationBearer <token>Scope: personal_access_token.create
application/json- body
name*stringA name that tells this token from your others, 1–200 characters.
1 <= length <= 200scopes*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.
1 <= items <= 100expires_at*stringWhen the token stops working: in the future, and at most 90 days from now. It cannot be extended later.
date-timeThe token was created. Its token is shown only here.
application/json- response
The new token's record, and the token, which no other response returns.
id*personal-access-token-idThe 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.
^tkn_[a-zA-Z0-9_-]+$name*stringThe 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*stringWhen it was created.
date-timeexpires_at*stringWhen it stops working. A token past this time is refused.
date-timeclient_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*stringThe 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.
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",});{ "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?