{"success":true,"response":"OpenLibx402 is a library that provides...","sources":[{"title":"Introduction","url":"https://docs.openlibx402.com/intro","excerpt":"OpenLibx402 is..."},{"title":"Features","url":"https://docs.openlibx402.com/features","excerpt":"Key features include..."}],"tokensUsed":150}
Response (402 Payment Required):
The response uses the standardized OpenLibx402 PaymentRequest format:
{"max_amount_required":"0.01","asset_type":"SPL","asset_address":"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU","payment_address":"HMYDGuLTCL6r5pGL8yUbj27i4pyafpomfhZLq3psxm7L","network":"solana-devnet","expires_at":"2025-11-05T12:05:00Z","nonce":"base64-encoded-nonce","payment_id":"uuid-payment-id","resource":"/api/chat","description":"Access to /api/chat endpoint - 3 free queries/day used"}
X402 Standard: This follows the OpenLibx402 HTTP 402 Payment Required protocol for standardized payment requests. See Payment System Documentation for details.
curl-XPOSThttp://localhost:3000/api/chat\-H"Content-Type: application/json"\-d'{ "message": "How do I use OpenLibx402?", "conversationId": "user-123" }'
constresponse=awaitfetch('http://localhost:3000/api/chat',{method:'POST',headers:{'Content-Type':'application/json',},body:JSON.stringify({message:'How do I use OpenLibx402?',conversationId:'user-123'})});if(response.status===402){// Handle rate limit - show payment modalconsole.log('Rate limit exceeded - payment required');}elseif(response.ok){constdata=awaitresponse.json();console.log('Response:',data.response);console.log('Sources:',data.sources);}else{console.error('Error:',response.status);}
{"error":"Rate limit exceeded","message":"You have used all 3 free queries for today. Please make a payment to continue.","remaining":0,"resetAt":1730851200000,"payment":{"required":true,"amount":0.01,"token":"USDC"}}
{"x402_format":"v1","asset_type":"SPL","asset_address":"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU","payment_address":"HMYDGuLTCL6r5pGL8yUbj27i4pyafpomfhZLq3psxm7L","network":"solana-devnet","amount":0.01,"token":"USDC","recipient":"HMYDGuLTCL6r5pGL8yUbj27i4pyafpomfhZLq3psxm7L","payment_methods":[{"method":"x-payment-authorization-header","description":"Submit as X-Payment-Authorization header in base64-encoded JSON"},{"method":"post-body-legacy","description":"Submit as JSON POST body (backward compatible)"}],"instructions":["1. Send the specified amount of USDC to the payment address","2. Get the transaction signature","3. Submit via X-Payment-Authorization header OR POST body to /api/payment","4. Receive query credits (1 USDC = 1000 queries)"]}
{"success":true,"message":"Payment accepted. You have been granted 10 additional queries.","signature":"3xMqyz4fTVaVPpZxbMCuKgf2PQ2hLzpvgLFAkf6fV5zR3FVFBsG9U8k3VzZgPRbmm6U3K3uKZT2","queriesGranted":10,"rateLimit":{"remaining":10,"resetAt":1730851200000,"requiresPayment":false}}
{"error":"Invalid or unconfirmed transaction. Please ensure you sent 0.01 USDC (not SOL) to the recipient address.","details":"Transaction verification failed. Check that: 1) You sent USDC tokens (not SOL), 2) Amount is 0.01 USDC, 3) Sent to the correct recipient address, 4) Transaction has been confirmed on the blockchain"}