Documentation
๐Ÿ’กConcepts

How x402 Works

Understand the protocol, payment flow, and key concepts behind x402.

The HTTP 402 Status Code

HTTP 402 "Payment Required" was defined in 1999 as part of the HTTP specification, reserved for future use in digital payment systems. After 25 years, x402 finally puts it to work.

When a server returns 402, it signals that the requested resource requires payment. The response includes headers that describe how to make that payment.

Response Headers
HTTP/1.1 402 Payment Required
X-402-Invoice-Id: inv_abc123xyz
X-402-Amount: 0.05
X-402-Pay-To: 0xABC...xyz
X-402-Network: mainnet
X-402-Description: AI Completion API

The Payment Flow

When an agent makes a request to a paid API, here's what happens:

1

Initial Request

Agent makes a request to the API endpoint

2

402 Response

API returns 402 Payment Required with X-402 headers

3

Quote Request

Agent SDK calls Gateway /quote with the payment details

4

Policy Check

Gateway checks agent policies (limits, allowed providers, etc.)

5

Payment Execution

If allowed, Gateway executes MNEE payment and returns proof

6

Retry with Proof

Agent SDK retries original request with payment proof header

7

Success

API verifies proof and returns the requested resource

Key Entities

๐Ÿข

Workspace

An isolated environment containing agents, wallets, and policies. Each workspace has its own MNEE treasury.

๐Ÿค–

Agent

An AI system or application that consumes paid APIs. Each agent has an API key and can have individual spending policies.

๐Ÿ”Œ

Provider

An API that accepts x402 payments. Providers receive MNEE directly to their wallet address.

๐Ÿ’ฐ

Treasury

The workspace's MNEE wallet. Agents draw from this balance when making payments.

๐Ÿ“‹

Policy

Rules that govern agent spending: daily limits, per-request limits, allowed providers, etc.

๐Ÿงพ

Invoice

A unique identifier for a payment request, generated by the provider and verified after payment.

About MNEE

MNEE is a USD-backed stablecoin (ERC20) on Ethereum. It provides the payment layer for x402 with several key advantages:

  • Fast Settlement โ€” Payments settle in ~12 seconds on Ethereum
  • Wide Ecosystem โ€” Built on the most widely adopted smart contract platform
  • USD-Backed โ€” 1 MNEE = $1 USD, fully backed and redeemable
  • Programmable โ€” Native support for micropayments and automation

Learn more about MNEE at mnee.io

Security Model

Non-Custodial Wallets

Each workspace generates its own MNEE wallet. The private key is encrypted with a key only the workspace controls. The Gateway never has direct access to wallet private keys.

API Key Security

Agent API keys are hashed before storage. The full key is only shown once at creation time. Keys can be rotated or revoked at any time.

Payment Verification

Providers verify payment proofs through the Gateway. Each proof is cryptographically signed and includes the transaction hash for on-chain verification.

Gateway Architecture

๐Ÿค–

Agents

@x402/agent SDK

โšก

x402 Gateway

Policy & Payment Engine

Quotes โ€ข Payments โ€ข Verification
๐Ÿ”Œ

Providers

@x402/server SDK

โŸ MNEE Stablecoin Layer (Ethereum)