> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cdp.coinbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Pay with x402

> Let AI agents and apps pay over HTTP with the x402 protocol.

Pay with x402 lets AI agents and apps pay over HTTP. The customer sends a base64-encoded payment payload in the `PAYMENT-SIGNATURE` header. Use it for machine-to-machine payments and API monetization.

You create the payment session and give its `x402Url` to the agent. The agent gets the payment requirements and submits a signed payment. You track the authorization until it succeeds or fails.

## 1. Create a payment session

[Create a payment session](https://docs.cdp.coinbase.com/payments/payment-acceptance/payment-sessions.md) with a [wallet target](https://docs.cdp.coinbase.com/payments/payment-acceptance/payment-sessions.md#target-types). The response includes an `x402Url`, which is the session's `POST .../payment-sessions/{id}/authorizations/x402` endpoint. Give this URL to an x402-enabled agent. The agent gets the payment requirements and submits the payment. The examples below use `$X402_URL` for this URL.

## 2. Get the payment requirements

The agent sends the request without a `PAYMENT-SIGNATURE` header. The response is `402 Payment Required`:

```bash theme={null}
curl -i -X POST "$X402_URL"
```

```
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbi...
```

The base64-encoded `PAYMENT-REQUIRED` header lists the accepted networks, assets, amounts, and payment addresses.

## 3. Submit the payment

The agent signs a payment that meets one of the requirements, then retries the request with the base64-encoded payload in the `PAYMENT-SIGNATURE` header:

```bash theme={null}
curl -X POST "$X402_URL" \
  -H "PAYMENT-SIGNATURE: eyJ4NDAyVmVyc2lvbi..."
```

An invalid `PAYMENT-SIGNATURE` also returns `402 Payment Required`.

## 4. Track the authorization

The agent receives `200` with a `PAYMENT-RESPONSE` header and the authorization, which starts as `pending`:

```json theme={null}
{
  "authorizationId": "authorization_82c879c1-...",
  "status": "pending",
  "amount": "1.00",
  "message": "Your payment was successfully submitted",
  "source": {
    "address": "0xAbC1234567890aBcDeF1234567890AbCdEf123456",
    "network": "base",
    "asset": "usdc"
  }
}
```

The authorization moves to `succeeded` or `failed`. You track it with [webhooks](https://docs.cdp.coinbase.com/webhooks/payment-acceptance/overview.md) or by fetching the payment session with your API key. Don't rely on the agent's copy of the response.

## What to read next

> **[Payment Sessions](https://docs.cdp.coinbase.com/payments/payment-acceptance/payment-sessions.md)**
>
> Session lifecycle, authorization outcomes, and idempotency

> **[x402 with Payment Acceptance](https://docs.cdp.coinbase.com/x402/integrations/payment-acceptance-api.md)**
>
> How x402 agents use Payment Acceptance sessions

> **[Webhooks](https://docs.cdp.coinbase.com/webhooks/payment-acceptance/overview.md)**
>
> Get notified when authorization succeeds or fails
