x402 payments for AI agents: pay-per-memory with no subscriptions
Your agent stores a memory, pays a fraction of a cent, and moves on. Here’s how x402 makes that work.
Most developer tools charge you in one of two ways: a monthly subscription with usage tiers, or a pay-as-you-go model with invoices and billing cycles. Both assume a human is managing the account, watching dashboards, and occasionally upgrading plans.
AI agents don’t check billing dashboards. They just work, or they hit a paywall and stop.
MemoClaw uses x402, an HTTP-native payment protocol, to let agents pay for memory operations inline with their API requests. Your agent stores a memory, pays $0.005 in USDC, and keeps going. No subscription to manage, no human in the loop.
What is x402?
x402 takes its name from HTTP status code 402, “Payment Required.” This status code has been reserved since HTTP/1.1 was defined in 1997, but it was never standardized. The note in the spec just says “reserved for future use.”
Nearly 30 years later, x402 fills that gap. It’s a protocol (pioneered by Coinbase) that defines how a server can request payment and how a client can pay, all within the HTTP request/response cycle.
Here’s the flow:
1. Free tier (first 100 calls)
Every wallet gets 100 free API calls. No payment setup needed:
# Just works — no payment required
memoclaw store "User likes dark mode" --importance 0.5
# âś“ Stored (97 free calls remaining)
2. Free tier exhausted
Once you’ve used your 100 free calls, the server responds with 402 Payment Required:
HTTP/1.1 402 Payment Required
X-Payment-Required: true
X-Payment-Amount: 5000
X-Payment-Currency: USDC
X-Payment-Network: base
X-Payment-Address: 0x...
The response includes everything the client needs: how much, what currency, which network, and where to send it.
3. Client pays inline
An x402-compatible client (like the MemoClaw CLI or SDK) automatically handles this:
# The CLI detects 402 and pays automatically
memoclaw store "Project deadline moved to April" --importance 0.9
# âś“ Stored (paid $0.005 USDC)
Under the hood:
- The CLI receives the 402 response
- It constructs a USDC payment on Base (a Layer 2 network, so fees are fractions of a cent)
- It signs the transaction with your wallet
- It re-sends the original request with a payment proof header
- The server verifies the payment and processes the request
All of this happens in a single request cycle. Your agent doesn’t wait for block confirmations. x402 uses payment attestations that the server can verify instantly.
4. Agent keeps working
From the agent’s perspective, nothing changed. The API call succeeded. A memory was stored. It cost $0.005 instead of being free. The agent moves on.
Why this matters for AI agents
Think about what a subscription-based memory service requires. A human signs up for a plan, provides a credit card, monitors usage to avoid overages, upgrades the plan when limits are hit, and handles billing failures. Every one of those steps requires a human. An autonomous agent can’t do any of them.
With x402, the agent handles everything. It has a wallet with USDC. It pays per request. If the wallet runs low, it stops making paid calls (or the human tops it up). There’s no subscription to manage, no plan to choose, no billing cycle to track.
The pay-per-use model also means you pay for actual usage, exactly. MemoClaw’s pricing:
| Operation | Cost |
|---|---|
| Store a memory | $0.005 |
| Recall (semantic search) | $0.005 |
| Store batch (up to 100) | $0.04 |
| Update memory | $0.005 |
| Extract/Consolidate/Context | $0.01 |
Operations that don’t use OpenAI embeddings, like listing, deleting, or text search, are completely free. You only pay when MemoClaw calls OpenAI on your behalf.
For context: an agent that stores 10 memories and recalls 5 times per session would cost $0.075 per session. Run that daily for a month and you’re at $2.25. No subscription tier comes close to that for light usage.
And there’s no lock-in from billing. If MemoClaw stops being useful, you stop calling the API and you stop paying. No cancellation flow, no “are you sure?” modals. Just stop.
Setting up x402 payments
For OpenClaw agents (recommended)
If your agent runs on OpenClaw, setup is minimal:
# Install the skill
clawhub install anajuliabit/memoclaw
# Authenticate with your wallet
memoclaw auth
# Ensure your wallet has USDC on Base
# (even $1 covers ~200 store operations)
The skill handles x402 negotiation automatically. Your agent calls memoclaw store or memoclaw recall and the payment happens behind the scenes.
For CLI users
# Install
npm install -g memoclaw
# Auth (signs a SIWE challenge with your wallet)
memoclaw auth
# Fund your wallet with USDC on Base
# Then just use it — payments are automatic
memoclaw store "Meeting notes from standup" --tags work,meetings
For direct API consumers
If you’re calling the REST API directly, you’ll need an x402-compatible HTTP client. The flow looks like:
import { createX402Client } from 'x402-js';
const client = createX402Client({
wallet: yourWallet, // ethers.js wallet or similar
network: 'base',
});
// The client handles 402 responses automatically
const response = await client.post('https://api.memoclaw.com/memories', {
content: 'User prefers morning meetings',
importance: 0.6,
tags: ['preferences', 'scheduling'],
});
The economics of agent memory
Let’s do some real math.
Light usage (personal OpenClaw agent):
- 10 stores/day Ă— $0.005 = $0.05/day
- 5 recalls/day Ă— $0.005 = $0.025/day
- Monthly cost: ~$2.25
Medium usage (project-focused agent):
- 30 stores/day Ă— $0.005 = $0.15/day
- 20 recalls/day Ă— $0.005 = $0.10/day
- Monthly cost: ~$7.50
Heavy usage (multi-agent shared memory):
- 10 batch stores/day Ă— $0.04 = $0.40/day (using batch API, up to 100 memories each)
- 50 recalls/day Ă— $0.005 = $0.25/day
- Monthly cost: ~$19.50
Compare that to typical SaaS pricing for developer tools. Most charge $20-50/month for a “Pro” plan regardless of whether you use it once or a thousand times. With x402, you pay for actual usage, and nothing on days you don’t use it.
What about gas fees?
A reasonable concern: if every API call requires an on-chain transaction, won’t gas fees eat you alive?
Two things make this work:
-
Base L2: MemoClaw uses USDC on Base, Coinbase’s Layer 2 network. Transaction fees on Base are typically $0.001-0.01, negligible compared to the API cost itself.
-
Payment attestations: x402 doesn’t necessarily require a full on-chain transaction per request. The protocol supports payment attestations that batch settlements, reducing the number of actual blockchain transactions.
The result: gas costs are a rounding error, not a barrier.
Free operations
Not everything costs money. MemoClaw only charges for operations that call OpenAI (embeddings for semantic search, GPT for extraction/consolidation). Everything else is free:
# Free — no embeddings needed
memoclaw list
memoclaw list --tag work
memoclaw get MEMORY_ID
memoclaw delete MEMORY_ID
memoclaw search "exact text match"
memoclaw stats
memoclaw namespaces
memoclaw export
This is intentional. You shouldn’t pay to browse your own memories or delete things. Only the computationally expensive operations (generating and searching vector embeddings) cost money.
The bigger picture: agents with wallets
x402 payments are part of a larger shift toward AI agents as economic actors. An agent with a wallet can authenticate to services (wallet-as-identity), pay for resources per request, store persistent memory, and operate autonomously across sessions without human intervention.
MemoClaw leans into this. The 100-call free tier means any agent can start without funding. When it needs more, it pays per request. The alternative is a human logging in to upgrade a plan because their agent ran out of quota at 3am. That’s the problem x402 exists to eliminate.
Get started: Install MemoClaw (clawhub install anajuliabit/memoclaw or npm install -g memoclaw), authenticate with your wallet, and your first 100 calls are free. When you need more, load a dollar of USDC on Base and you’re good for hundreds of operations.