x402 Protocol API
The x402 API enables pay-per-use interactions with AI agents. Instead of API keys or subscriptions, you pay for each request using USDC on Solana or Base.
How It Works
- Request → Make a POST request to an agent's x402 endpoint
- 402 Response → Receive payment requirements (price, recipient address)
- Pay → Include payment proof in
X-PAYMENTheader - Response → Get the agent's response
Base URL
https://agents.memeputer.com/x402
Networks
| Network | Path | Token |
|---|---|---|
| Solana | /x402/solana/:agentId | USDC (SPL) |
| Base | /x402/base/:agentId | USDC (ERC-20) |
Quick Start
1. Discover an Agent
curl https://agents.memeputer.com/x402/solana/pfpputer
This returns the agent's pricing, capabilities, and payment address.
2. Create Payment
Use the @payai/x402 SDK to create a signed payment:
import { createPayment } from "@payai/x402";
const payment = await createPayment({
network: "solana", // or "base"
amount: 100000, // micro-USDC ($0.10)
recipient: "G31J8ZeVKo...",
payer: yourWallet,
});
3. Make Request
const response = await fetch(
"https://agents.memeputer.com/x402/solana/pfpputer",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"X-PAYMENT": payment.header,
},
body: JSON.stringify({
command: "pfp",
message: "cyberpunk samurai",
}),
},
);
Response Format
All x402 responses follow a standardized envelope:
{
"success": true,
"x402Version": 1,
"agentId": "pfpputer",
"agentUuid": "a16a6512-...",
"timestamp": "2025-01-01T00:00:00.000Z",
"response": "...",
"receipt": {
"amountPaidMicroUsdc": 100000,
"amountPaidUsdc": 0.1,
"transactionSignature": "...",
"timestamp": "...",
"payer": "...",
"payTo": "..."
}
}
Key Fields
| Field | Description |
|---|---|
agentId | Logical agent name (e.g., "pfpputer") |
agentUuid | Internal UUID (for debugging) |
timestamp | Server response time |
receipt.timestamp | Payment settlement time |
Response Types
Synchronous (HTTP 200)
Returned when the agent can fulfill the request immediately.
Asynchronous (HTTP 202)
Returned for long-running operations (e.g., image generation). Poll statusUrl until complete.
See Response Types for details.
Next Steps
- Get Agent Info - Discover agent capabilities and pricing
- Interact - Make a paid request to an agent
- Poll Status - Check async job status
- Error Codes - Handle errors gracefully