# X402 Payments For Tool Usage

> Pay for one eligible AgentPMT tool action with x402.

Content type: documentation
Source URL: https://www.agentpmt.com/docs/autonomous-agents/x402-payments-for-tool-usage
Markdown URL: https://www.agentpmt.com/docs/autonomous-agents/x402-payments-for-tool-usage?format=agent-md
Category: Autonomous Agents

---

# X402 Payments For Tool Usage

Use direct x402 payment when an autonomous agent needs one eligible tool action. The agent sends action parameters, receives a `402 Payment Required` challenge, signs one token transfer authorization, and retries the exact same action body with `X-PAYMENT`.

The product action must be direct-x402-enabled.

## Endpoint

```text
POST https://www.agentpmt.com/api/external/tools/{productSlug}/actions/{actionSlug}/invoke
```

Direct x402 requests use the action parameters as the JSON request body.

## Flow

1. **Send the action parameters**
   POST the action's JSON parameters to the invoke endpoint without a payment header. If the action is direct-x402-enabled and payment is required, the server responds with `402`.

2. **Decode the payment challenge**
   Read the JSON response body and the base64 `PAYMENT-REQUIRED` header. Both describe the same payment challenge with `x402Version`, `resource`, and `accepts`.

3. **Select the exact acceptance**
   Choose an `accepts[]` entry by network, token asset, payee, amount, and resource URL. Do not blindly sign the first acceptance if the agent has a network or asset policy.

4. **Sign the EIP-712 authorization**
   Build the `TransferWithAuthorization` typed-data domain from `acceptance.extra.name`, `acceptance.extra.version`, the numeric chain id parsed from `acceptance.network`, and `acceptance.asset`.

5. **Retry the same body with X-PAYMENT**
   Base64-encode the signed x402 envelope and retry the exact same action-parameter JSON body with `X-PAYMENT: <base64-envelope>`.

## Initial Request

This example uses the live AI Writing Quality Check action tested on May 15, 2026.

```bash
curl -i -s -X POST "https://www.agentpmt.com/api/external/tools/ai-writing-quality-check/actions/check_for_banned_phrases/invoke" \
  -H "Content-Type: application/json" \
  -d '{ "content":"Our customers love us. Ask our AI." }'
```

Expected response:

- HTTP status `402 Payment Required`.
- `PAYMENT-REQUIRED` header containing a base64 JSON challenge.
- JSON body containing `x402Version`, `resource`, and `accepts`.

The decoded challenge includes one or more payment requirements similar to this shape:

```json
{
  "x402Version": 2,
  "error": "Payment required",
  "resource": {
    "url": "https://www.agentpmt.com/api/external/tools/ai-writing-quality-check/actions/check_for_banned_phrases/invoke",
    "description": "AgentPMT tool action",
    "mimeType": "application/json"
  },
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:8453",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "payTo": "0x7ed9057a8edec4496c902c9aecf1d30947d7cc09",
      "amount": "50000",
      "extra": {
        "name": "USD Coin",
        "version": "2"
      }
    }
  ]
}
```

The example acceptance above is Base USDC. `amount` is in token minor units, so `50000` means `0.05` USDC for a six-decimal token.

## Sign the Payment

Sign the selected acceptance with EIP-712 `TransferWithAuthorization` typed data.

EIP-712 domain:

| Field | Value |
| --- | --- |
| `name` | `acceptance.extra.name` |
| `version` | `acceptance.extra.version` |
| `chainId` | Numeric chain id parsed from `acceptance.network`, such as `8453` from `eip155:8453` |
| `verifyingContract` | `acceptance.asset` |

EIP-712 primary type:

```json
{
  "TransferWithAuthorization": [
    { "name": "from", "type": "address" },
    { "name": "to", "type": "address" },
    { "name": "value", "type": "uint256" },
    { "name": "validAfter", "type": "uint256" },
    { "name": "validBefore", "type": "uint256" },
    { "name": "nonce", "type": "bytes32" }
  ]
}
```

Authorization message:

```json
{
  "from": "0xPAYER_WALLET",
  "to": "acceptance.payTo",
  "value": "acceptance.amount",
  "validAfter": "0",
  "validBefore": "<unix-timestamp-before-timeout>",
  "nonce": "0x<fresh-32-byte-nonce>"
}
```

## Paid Retry

The signed x402 envelope is base64-encoded JSON. Use the selected acceptance's network and asset, and include the signature plus authorization values.

```json
{
  "x402Version": 2,
  "scheme": "exact",
  "network": "eip155:8453",
  "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "payload": {
    "signature": "0x<eip712-signature>",
    "authorization": {
      "from": "0xPAYER_WALLET",
      "to": "0x7ed9057a8edec4496c902c9aecf1d30947d7cc09",
      "value": "50000",
      "validAfter": "0",
      "validBefore": "<unix-timestamp-before-timeout>",
      "nonce": "0x<fresh-32-byte-nonce>"
    }
  }
}
```

Retry the exact same action body:

```bash
curl -s -X POST "https://www.agentpmt.com/api/external/tools/ai-writing-quality-check/actions/check_for_banned_phrases/invoke" \
  -H "Content-Type: application/json" \
  -H "X-PAYMENT: <base64-envelope>" \
  -d '{ "content":"Our customers love us. Ask our AI." }'
```

On success, the response is the paid tool result with `x402` payment metadata.

## Successful Response

A successful direct x402 tool call returns the paid tool result and sets `PAYMENT-RESPONSE` with a base64-encoded JSON settlement payload. Decode that header to read the settlement transaction, network, payer, and the payment requirement that the broadcast satisfied.

## Related References

- [Credit Based Tool Usage With AgentAddress](/docs/autonomous-agents/credit-based-tool-usage-with-agentaddress) - Buy reusable credits with x402, then spend them through signed AgentAddress calls.
  - [Endpoint Catalog](/docs/api-reference/autonomous-agents) - Auto-generated autonomous-agent API request and response schemas.