Agent payments (x402)

How AI agents pay for screenshots without accounts, API keys, or human intervention.

What is x402?

x402 is a protocol that turns HTTP 402 ("Payment Required") from a forgotten status code into a machine-readable payment negotiation. When an agent calls an x402-enabled API without credentials, it gets back payment instructions instead of an error — and can pay automatically.

The flow

Step 1: Agent calls the API (no auth header)

POST /api/v1/screenshot
Content-Type: application/json

{"url": "https://example.com"}

Step 2: Server responds with 402 + payment details

HTTP/1.1 402 Payment Required

{
  "x402": {
    "version": 1,
    "schemes": [{
      "scheme": "exact",
      "network": "base",
      "token": "USDC",
      "maxAmountRequired": "5000",
      "resource": "https://api.nightglass.xyz/api/v1/screenshot",
      "payTo": "0x1C680703D6cF7dfC9FEABb5AA28E64B869ddB3bC"
    }]
  }
}

Step 3: Agent signs a USDC payment on Base

The agent reads the payment details, signs a transaction (or EIP-3009 authorisation) for the specified amount of USDC on Base, and constructs a payment proof.

Step 4: Agent re-sends the request with payment proof

POST /api/v1/screenshot
Content-Type: application/json
X-PAYMENT: <base64-encoded payment proof>

{"url": "https://example.com"}

Step 5: Server verifies payment and returns the screenshot

The server verifies the payment proof on-chain, and if valid, processes the screenshot and returns the PNG/JPEG image.

Why this matters

Traditional APIs require human signup, API key management, and billing accounts. For autonomous agents operating at scale, this is friction that doesn't need to exist. With x402, an agent can discover an API, pay for it, and use it — all in a single HTTP roundtrip. No human in the loop.

For agent builders: If you're building agents on frameworks like OpenClaw, LangChain, CrewAI, or AutoGPT, you can use the x402 npm package or the x402 Python SDK to handle the payment flow automatically.

Cost

Same as the API key path: $0.005 per screenshot (0.5¢). The maxAmountRequired in the 402 response is in USDC's smallest unit (1/1,000,000). So 5000 = 0.005 USDC = half a cent.