Integrate with x402 payment-gated APIs. Use when building agents that discover, pay for, and consume HTTP 402-enabled tool endpoints. Covers llms.txt discovery, 402 response parsing, USDC payment on Base L2, receipt verification, and the SearchX402 directory API. Triggers on tasks involving paid API access, micropayments, agent tool purchasing, or x402 protocol implementation.
Rules and patterns for AI agents that need to discover, pay for, and use x402-enabled API endpoints. The x402 protocol extends HTTP 402 Payment Required into a machine-readable payment flow: agents discover tools via llms.txt, hit a 402 response, parse the payment requirements, pay with USDC on Base L2, and retry with a payment receipt.
Reference these guidelines when:
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Discovery | CRITICAL | discover- |
| 2 |
| Payment Flow |
| CRITICAL |
payment- |
| 3 | Receipt Handling | HIGH | receipt- |
| 4 | Server-Side | HIGH | server- |
| 5 | Directory | MEDIUM | directory- |
discover-llms-txt - Find x402-enabled tools via llms.txt and
.well-known/x402.jsondiscover-402-detection - Detect and parse 402 Payment Required responsesdiscover-pricing-metadata - Extract price, currency, and payment address
from 402 responsespayment-usdc-base - Pay with USDC on Base L2 using the x402 payment
envelopepayment-retry-with-receipt - Retry the original request with the payment
receipt headerpayment-budget-guard - Implement per-request and per-session spending
limitsreceipt-verification - Verify payment receipts before granting accessreceipt-replay-prevention - Prevent receipt reuse with nonce trackingserver-402-response - Implement the 402 response format for your own
endpointsserver-receipt-validation - Validate incoming payment receipts on your
Workerdirectory-searchx402 - Use the SearchX402 API to discover paid tools
by categoryRead individual rule files for detailed explanations and code examples:
rules/discover-llms-txt.md
rules/payment-usdc-base.md
rules/server-402-response.md
Each rule file contains: