Give an agent a personal access token
Create a personal access token for a CI job or an agent that works without you, limit it to the scopes it needs, and revoke it.
A personal access token (PAT) is a credential that acts as you, for a CI job, a scheduled task or an AI agent that works while nobody is at the keyboard. It reaches the management API and the MCP endpoint with your access, held to the scopes you give it. It expires within 90 days, and you can revoke it at any time.
A PAT belongs to you, not to a project: it reaches every project your account can work on, through the roles you hold there. If you lose a role, the PAT loses it on its next call.
Before you start
- A server with personal access tokens on.
personal_access_tokens.enabled(NEXTGEN_PERSONAL_ACCESS_TOKENS_ENABLED) is off by default; off, the operations below answer501. - An account on the platform project: the account you sign in to the console with. A project's own users hold no PATs.
- Either a console session, or an access token with
personal_access_token.create. An agent you sign in through OAuth asks for this scope; the consent step leaves it unticked, so tick it only for a client you trust to create credentials in your name. - With a console session, a sign-in in the last 15 minutes. A session that signed in longer ago answers
403withtkn.pat_sign_in_required: sign in again, then create the PAT. An access token with the create scope is not held to this. - A sign-in made with your current password. After your password is set, neither a session nor an access token from before creates a PAT until you sign in again.
Create a PAT from the CLI
Sign in once with zitadel login. It opens your browser on the server's own sign-in and consent page; tick create personal access tokens there, with the scopes the job needs. The CLI keeps the sign-in in its config directory, outside every project, and refreshes it.
zitadel login --server "$ZITADEL_URL"
zitadel personal-access-token create --server "$ZITADEL_URL" --name "Deploy from CI" \
--scope project.read --scope deployment.read --expires-in 30personal-access-token create prints the token once. zitadel personal-access-token list shows your PATs without their tokens, zitadel personal-access-token revoke <id> revokes one, and zitadel logout forgets the sign-in on this machine; your PATs keep working until they expire or you revoke them.
Create a PAT through the API
Call createMyPersonalAccessToken (POST /users/me/personal_access_tokens) with a name, the scopes, and when it expires:
curl -X POST "$ZITADEL_URL/api/v1/users/me/personal_access_tokens" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Deploy from CI","scopes":["project.read","deployment.read"],"expires_at":"2027-03-02T10:00:00Z"}'The response holds the token, zpat_…, in token. It is shown only once: the server keeps a hash of it. Store it in your CI's secret store.
- Scopes. Give it only the scopes the job needs. Created with an access token, it holds no scope that access token lacks. It can never hold
personal_access_token.create, so a PAT never creates another. - Expiry.
expires_atis required and at most 90 days away. To keep a job running, create a new PAT and revoke the old one.
An agent connected to the MCP endpoint with the create scope calls the createMyPersonalAccessToken tool the same way.
Use it
Send it as a bearer token:
curl "$ZITADEL_URL/api/v1/projects/$ZITADEL_PROJECT_ID" -H "Authorization: Bearer $ZITADEL_PAT"An operation that needs a scope the PAT lacks answers 403 with auth.scope_insufficient, naming the scope. Create a PAT with that scope if the job needs it.
Every event of a call made with a PAT names you as the actor, the PAT's ID as token_id, and pat_shared as delegation_type. Investigate with events shows how to read them.
List and revoke your PATs
listMyPersonalAccessTokens (GET /users/me/personal_access_tokens) lists your PATs with their names, scopes, expiry and the client that created each. It never returns a token.
revokeMyPersonalAccessToken (DELETE /users/me/personal_access_tokens/{personal_access_token_id}) revokes one; the next call with it answers 401. A PAT may revoke itself, if it holds personal_access_token.delete.
If a PAT leaks, revoke it at once. Deactivating your account ends all of them.
A new password ends your PATs
When your password is set, every PAT of yours that has not expired stops working at once. Someone who got into your account and created a PAT loses it when you get a new password.
This also stops every CI job and agent that uses one of your PATs. Their next call answers 401. After a password change, create a new PAT for each job and store it in the job's secret store. An auth.token.revoked event with reason password_set and a count records how many ended.
- Today only
setUserPasswordsets a password, and it takes a project secret, which the platform project has only if an operator created one. The server has no page yet where you change or reset your own password; those will end your PATs the same way. Until then, revoke a PAT you no longer trust yourself. - A new password does not end your sessions or the access an agent you signed in already holds, but neither can create a PAT any more: they answer
403withtkn.pat_sign_in_requireduntil you sign in again with the new password. Create the replacement PATs after that sign-in. - Signing out does not end your PATs: a PAT is meant to outlive the session that created it.
- If you sign in with a passkey or an identity provider and have no password, nothing ends your PATs for you. After a lost device or a taken-over provider account, list your PATs and revoke any you did not create.
Was this helpful?