When to use agent authorization
Use agent authorization when you want to allow your users to use their wallets via a self-hosted agent (such as Claude Code, Codex, OpenClaw, or a custom CLI). Agent authorization is the foundation for building agent-first experiences on top of your Privy app. By implementing this flow, your app’s will be able to deliver rich experiences via any of agentic interfaces, including CLIs, MCP servers, Skills, connectors, and autonomous agents. Agent authorization is a good fit when:- The agent runs in a CLI or headless environment with no persistent browser
- Wallet operations need to happen autonomously after a one-time user approval
- App secrets must not be distributed to end-user machines
- The app does not want to require a backend server to proxy wallet requests to the Privy API, including the authentication and authorization that entails
How it works
The flow has three participants: the agent (CLI or autonomous process), the user (approves via browser), and your app (hosts the verification page and holds the Privy app).Agent requests a device code
The agent calls Privy’s device authorization endpoint and receives a
device_code (kept secret on the machine) and a user_code (short, human-readable). The agent displays the verification URL and user code:User approves in browser
The user opens the verification URL (a page your app hosts), signs in with Privy, and approves the
agent’s request. The verification page calls Privy’s
device_verify endpoint with the user code
and the user’s access token.Agent receives tokens
The agent polls Privy’s token endpoint at a fixed interval. Once the user approves, the response
contains an access token and a refresh token. The agent stores these tokens for subsequent
requests.
Enable in dashboard
Navigate to your app in the Privy Dashboard, open Authentication -> Advanced and toggle Enable for CLI and agent access on. Set the Verification URI, the URL where users will approve agent requests. The verification URI must point to a page your app hosts. Privy returns this URI to the agent in the device authorization response so the agent can display it to the user.Build the verification page
The verification page is the only browser-side step in the flow. It reads theuser_code from the query string, prompts the user to log in if needed, and calls device_verify to approve or deny the agent’s request.
Privy’s device authorization endpoint returns a verification_uri_complete that pre-fills the user code as a query parameter, so users arriving via that link will not need to type a code manually.
- React
- Vanilla JS
Integrate device authorization in your agent
The following covers the full API flow for a CLI or agent. All requests go tohttps://auth.privy.io and require the privy-app-id header. For the complete request and response schemas, see the OpenAPI specification.
Request a device code
Call this once at the start of login to receive the codes the agent will use for polling and display.verification_uri_complete (or verification_uri + user_code separately) to the user. Keep device_code secret on the machine; it is used only for polling. The device code expires after 10 minutes.
Error: 403 device_auth_not_enabled: device authorization is not enabled for this app in the dashboard.
Poll for an access token
Poll this endpoint at theinterval from the previous response (in seconds) until the user approves.
400 with one of the following errors:
| Error | Action |
|---|---|
authorization_pending | User has not approved yet; keep polling |
slow_down | Polling too fast; increase interval by 5 seconds |
expired_token | Device code expired; restart from the previous step |
access_denied | User denied access; stop polling and surface an error |
Refresh an access token
Exchange a refresh token for a new access token when the current one is near expiry or after receiving a401 from a wallet endpoint. The old refresh token is immediately invalidated.
refresh_token. If this endpoint returns access_denied, the refresh token has expired or the user revoked access, and the user must re-authorize from the beginning.
Get a wallet signing key
Before submitting wallet operations, exchange the access token for an ephemeral signing key. Provide an HPKE public key so the response is encrypted to the agent process only.encrypted_authorization_key with the corresponding HPKE private key. Cache and reuse the key until expires_at. It produces the privy-authorization-signature header on RPC requests.
Submit a wallet RPC
Use the Privy wallet ID (for example,wallet_abc123), not the on-chain address.
| Error | Action |
|---|---|
401 access token expired | Refresh via the token endpoint, then retry |
403 wallet not accessible | Wallet does not belong to the authenticated user |
Token lifetimes
| Artifact | Lifetime |
|---|---|
device_code / user_code | 10 minutes |
| Access token | 15 minutes |
| Refresh token | 30 days (rotated on each use) |
Managing authorizations
Users can list and revoke active agent authorizations at any time. These endpoints require a valid user access token.List active authorizations
Revoke an authorization
Learn more
Agent CLI
Give any agent a wallet with a CLI command. No integration code needed.
Agentic wallets
Create developer-controlled agent wallets with policy guardrails.
Policies
Constrain agent behavior with transfer limits, allowlists, and time-based controls.
x402 payments
Enable HTTP-native payments for APIs and digital content.

