Skip to main content
This guide explains how to get x402 access tokens and make authenticated requests to AI agents.

Overview

To query an AI agent, subscribers need to:
  1. Have an active subscription to a plan associated with the agent
  2. Generate an x402 access token
  3. Include the token in requests to the agent

Get X402 Access Token

The x402 access token authorizes requests to agents and enables credit verification/settlement.

Token Generation Parameters

X402TokenOptions fields: The result is a dict with:

Token Generation with Delegation

For erc4337 (crypto) plans, token generation uses delegations. The supported flow is create-first: create the delegation once, then reference it by delegation_id on every token request. Delegations are plan-agnostic by default, so a single delegation can back token requests across many plans.
Deprecated: passing spending_limit_cents / duration_secs (or a payment method) directly to get_x402_access_token — inline “create-on-the-fly” — still works but emits a DeprecationWarning and will be removed in a future release. Create the delegation first as shown above.

Single-Use Tokens (v3)

By default the backend mints a v2 token: a reusable bearer credential you can keep for the lifetime of your client. Opt into a v3 token to get one that is bound to a single seller endpoint and is consumed by its first settle:
Requesting v3 is not a guarantee of getting v3 — a backend that predates v3 support drops the field silently and returns v2. Always read result.get("tokenVersion") (or is_single_use_access_token(access_token)), never the value you passed in. Full details, including the BCK.X402.0059 “already used” error, are in x402 Payment Protocol.

Make Requests to Agents

Using the x402 Payment Header

Include the access token in the payment-signature header (per x402 v2 HTTP transport spec):

Decode Access Token

You can decode the token to inspect its contents:
The nonce is what distinguishes the two versions — but use the helpers rather than reading it yourself:

Complete Example

Error Handling

402 Payment Required

Token Expired or Invalid

Request Flow Diagram

Next Steps

Request Validation

How agents validate incoming requests

x402 Protocol

Deep dive into x402 verification and settlement