AWS re:Invent 2026 · COM312 · x402 + AgentCore payments
Everything you need for your agent to pay a 402: a prompt for your coding agent, an AgentCore payments tutorial, and the API behind my booking page. Testnet money only.
x402 in 30 seconds
HTTP set aside 402 "for future use" in 1997. It sat unused for decades.
The server names a price, the client signs a USDC payment, retries, and gets in.
Each one settles in about a second, and the facilitator pays the gas. A cent per call works.
An agent can pay for one request with nothing set up. That's why it needs spending rules, and the trap journey shows what happens without them.
Bring your own agent · about 5 minutes
Copy this prompt into Claude Code, Codex, Cursor, Kiro, or any coding agent. It writes a small x402 client, funds a test wallet from my faucet, buys a fortune with a real testnet payment, and then proves its own spending rules by refusing the 0.25 trap. You get a Basescan link at the end, and your name lands on the receipts wall.
Build a tiny x402 client and use it to make a real payment on Base Sepolia testnet.
Server: https://whereis.davidvictoria.com (x402 v2, scheme "exact", network eip155:84532, test USDC)
1. Create a new Node.js project in an empty folder, set "type": "module" in package.json, and install viem.
2. Generate a fresh wallet with viem (generatePrivateKey, privateKeyToAccount). Save the private key to .env and never print it. Print the address.
3. Fund it: POST https://whereis.davidvictoria.com/api/faucet with JSON {"address": "<address>"}. It sends 0.60 test USDC, enough for a fortune and a meeting. A 200 means the money is on its way. If the response is an error, print it, wait 30 seconds, and retry, up to 3 times. Then poll GET https://whereis.davidvictoria.com/api/balance?address=<address> every 3 seconds until usdc >= 0.01. If usdc comes back null, the RPC was slow: keep polling.
4. GET https://whereis.davidvictoria.com/api/fortune?name=<MY NAME>. Expect HTTP 402. Base64-decode the PAYMENT-REQUIRED response header into JSON and print accepts[0].
5. Spending rules, checked before signing anything:
- network must be eip155:84532
- amount must be at most 50000 (0.05 USDC)
- payTo must equal the pay_to from GET https://whereis.davidvictoria.com/api/meet: products.fortune.pay_to for /api/fortune and /api/lab/*, products.meeting.pay_to for /api/book
If a rule fails, stop, sign nothing, and say which rule failed.
6. Sign an EIP-3009 TransferWithAuthorization with viem's account.signTypedData. Use Unix time in seconds for now.
domain: { name: accepts[0].extra.name, version: accepts[0].extra.version, chainId: 84532, verifyingContract: accepts[0].asset }
types: { TransferWithAuthorization: [ {name:"from",type:"address"}, {name:"to",type:"address"}, {name:"value",type:"uint256"}, {name:"validAfter",type:"uint256"}, {name:"validBefore",type:"uint256"}, {name:"nonce",type:"bytes32"} ] }
primaryType: "TransferWithAuthorization"
message: { from: <address>, to: payTo, value: amount, validAfter: now - 600, validBefore: now + maxTimeoutSeconds, nonce: random 32-byte hex }
7. Build { x402Version: 2, resource: <resource from the 402>, accepted: accepts[0], payload: { signature, authorization: <the message, every number as a string> } }, base64-encode the JSON, and repeat the same GET with the header PAYMENT-SIGNATURE.
8. Expect 200. Print the fortune, base64-decode the PAYMENT-RESPONSE header, and print https://sepolia.basescan.org/tx/<transaction>. Each wallet can buy 3 fortunes.
9. Prove the spending rules work: run the same flow against https://whereis.davidvictoria.com/api/lab/overcharge (it asks for 0.25) and show that the client refuses to sign.
10. Give back what's left so the faucet keeps working for others: sign one more TransferWithAuthorization for your full balance (GET /api/balance, in 6-decimal units) to products.fortune.pay_to, then POST https://whereis.davidvictoria.com/api/return with JSON {"payment": {"x402Version": 2, "resource": {"url": "https://whereis.davidvictoria.com/api/return", "description": "return", "mimeType": "application/json"}, "accepted": {"scheme": "exact", "network": "eip155:84532", "amount": "<units>", "asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e", "payTo": "<pay_to>", "maxTimeoutSeconds": 300, "extra": {"name": "USDC", "version": "2"}}, "payload": {"signature": "…", "authorization": {…}}}}. Print the transaction link. If you also do the optional booking below, return after it.
Optional, the real thing: book 15 minutes with David for 0.15 test USDC. Read open times from GET https://whereis.davidvictoria.com/api/meet, then POST https://whereis.davidvictoria.com/api/book with JSON {"time", "name", "contact", "topic"}, where contact is an email or a WhatsApp number with its country code (10 digits without one are read as Mexico, +52), and pay the 402 the same way. Raise the amount limit to 150000 (0.15 USDC) for that call only.The client in this prompt keeps its key in a local file and enforces its own limits. That's fine for a demo. In production, AgentCore payments moves both out of the agent: the wallet stays with Coinbase or Stripe (Privy), and the budget lives in a payment session. The tutorial below shows that setup.
Mini tutorial · about 10 minutes · testnet money
You'll set up AgentCore payments with a Coinbase wallet, fund it with free testnet USDC, and have a Strands agent pay 0.01 USDC for a Vegas fortune cookie. Your name shows up on the receipts wall when it works, and the same agent can then book a meeting with me. AgentCore payments is in preview, so check that your AWS account and region have it.
Inside Claude Code (Codex and Kiro work too):
/plugin marketplace add aws/agent-toolkit-for-aws /plugin install aws-agents@agent-toolkit-for-aws
Wire my agent to pay for x402-protected APIs using the agents-build skill in the aws-agents plugin. Test it against https://whereis.davidvictoria.com/api/fortune?name=YOUR_NAME
The skill creates the Payment Manager, connector, wallet, and a budget-capped session, and adds a payment tool to your agent.
The skill pauses twice. First you sign in to Coinbase (Quick create, no keys to copy). Then you open the wallet link, grant the agent permission to sign, and fund the wallet with test USDC on Base Sepolia from the Circle faucet.
It calls the endpoint, gets the 402, pays 0.01 USDC, retries, and prints your fortune with a Basescan link. Scroll down: your first name is on the wall.
pip install boto3 "bedrock-agentcore[strands-agents]" strands-agents
Fastest path: AgentCore console → Payments → Create Payment Manager, then add a Coinbase connector with Quick create and authorize in the Coinbase window. Coinbase connectors need the free Coinbase Wallets for AgentCore Payments subscription in AWS Marketplace. Keep the manager ARN and connector ID.
Every step has CLI and SDK versions in the AgentCore payments quick start.
from bedrock_agentcore.payments import PaymentManager manager = PaymentManager(payment_manager_arn=PAYMENT_MANAGER_ARN, region_name="us-west-2") instrument = manager.create_payment_instrument( user_id="reinvent-you", payment_connector_id=PAYMENT_CONNECTOR_ID, payment_instrument_type="EMBEDDED_CRYPTO_WALLET", payment_instrument_details={"embeddedCryptoWallet": { "network": "ETHEREUM", "linkedAccounts": [{"email": {"emailAddress": "you@example.com"}}], }}, ) INSTRUMENT_ID = instrument["paymentInstrumentId"] print(instrument["paymentInstrumentDetails"]["embeddedCryptoWallet"]["redirectUrl"])
Open the printed link and grant signing permission. Then fund it with Base Sepolia USDC from the Circle faucet.
session = manager.create_payment_session(
user_id="reinvent-you",
limits={"maxSpendAmount": {"value": "0.05", "currency": "USD"}},
expiry_time_in_minutes=30,
)
SESSION_ID = session["paymentSessionId"]Five cents caps the damage at five fortunes. AgentCore refuses any payment over the budget, whatever the agent decides. Raise it to $0.15 when you want the agent to book a meeting.
from strands import Agent from bedrock_agentcore.payments.integrations.strands import ( AgentCorePaymentsPlugin, AgentCorePaymentsPluginConfig, ) plugin = AgentCorePaymentsPlugin(config=AgentCorePaymentsPluginConfig( payment_manager_arn=PAYMENT_MANAGER_ARN, user_id="reinvent-you", payment_instrument_id=INSTRUMENT_ID, payment_session_id=SESSION_ID, region="us-west-2", )) agent = Agent(plugins=[plugin]) # the plugin brings an http_request tool that pays 402s agent("Buy me a Vegas fortune at https://whereis.davidvictoria.com/api/fortune?name=YOUR_NAME")
Same agent and wallet, a session budget of $0.15, and a real meeting at the end:
agent("Check https://whereis.davidvictoria.com/api/meet for David's open times, " "then book 15 minutes on Tuesday afternoon at The Venetian with a POST to " "https://whereis.davidvictoria.com/api/book. JSON body: time, name, " "contact, topic, venue. My name is ___ and my WhatsApp is +__ ___.")
claude mcp add --transport http meet-david https://whereis.davidvictoria.com/mcp
Any client that speaks Streamable HTTP works: Claude, Cursor, Kiro, VS Code.
Where is David right now? Book me 15 minutes with him on Tuesday morning. I'm Ana, ana@example.com, I want to talk about agent wallets.
book_meeting answers with x402 payment requirements. A client that pays x402, such as a Strands agent with the AgentCore payments plugin, finishes the booking. Other clients show you the terms and stop there.
Reference
Times are Pacific (UTC−8) on the hour or half hour: Nov 30 to Dec 3 from 9 AM to 6 PM, Dec 4 from 9 AM to noon. Paid endpoints speak x402 v2 and also accept X-PAYMENT.
POST /mcpMCP server: where_is_david, book_meeting, buy_vegas_fortune.GET /api/meetWhere I am, my next open times, prices, networks, and the receiving wallet.POST /api/bookJSON {time, name, contact, topic, venue}. 15 minutes for 0.15 test USDC on Base Sepolia. venue is optional and best effort.GET /api/fortune?name=Practice purchase: 0.01 test USDC on Base Sepolia.POST /api/faucetJSON {address}. Sends 0.60 test USDC from my treasury, with Coinbase's faucet as backup. Twice per address per day.POST /api/returnJSON {payment}: an EIP-3009 payload that sends leftover test USDC back to my treasury. Gasless.GET /api/balance?address=Test USDC balance on Base Sepolia.GET /api/receiptsThe wall, as JSON.