Skip to main content

x402 Protocol

The x402 protocol enables machine-to-machine payments on the web using HTTP status code 402. Invoica extends x402 with financial compliance — invoicing, tax calculation, budget enforcement, and settlement detection.

How x402 Works

The x402 protocol uses HTTP to negotiate and execute payments between AI agents and resource servers:

x402 Headers

The protocol uses two key headers:

PAYMENT-REQUIRED (Server → Client)

When a server requires payment for a resource, it responds with HTTP 402 and includes the PAYMENT-REQUIRED header. This header contains the payment details the agent needs:
The header value is a JSON object specifying:
  • price — Amount to pay
  • token — Token to use (e.g., USDC)
  • recipient — Wallet address to send payment to
  • network — Blockchain network (e.g., base, ethereum, solana)

PAYMENT-SIGNATURE (Client → Server)

After the agent completes the payment, it retries the original request with the PAYMENT-SIGNATURE header containing the signed payment proof:
The server verifies the payment and returns the resource.

Standard x402 Flow

With Invoica Middleware

Invoica sits as a transparent proxy between the agent and the resource server. When it intercepts a 402 response, it generates an invoice, calculates applicable taxes, and tracks the settlement:

Invoice Metadata Headers

In addition to the standard x402 headers, Invoica uses custom headers to capture invoice metadata from AI agents:
These headers are optional — when present, the middleware uses them to populate the buyer details on the generated invoice.

What Invoica Adds

Supported Networks

Invoica supports settlement detection on:
  • Ethereum Mainnet — ERC-20 token transfers (tested on Sepolia)
  • Base Mainnet — Low-cost L2 transactions with EIP-3009 support
  • Solana Mainnet — SPL USDC token transfers
  • Arbitrum — Optimistic rollup settlements