An AI-powered research agent that autonomously discovers, evaluates, and pays for data services on the Stellar blockchain using x402 micropayments — all within a user-specified USDC budget.
- You ask a research question (e.g., "What's happening in crypto markets today and how might global news affect Bitcoin?")
- You set a USDC budget (e.g., $0.10)
- An AI agent autonomously:
- Decomposes your query into data-gathering sub-tasks
- Discovers available paid data services via the xlm402.com catalog
- Calls each service by paying USDC via x402 on Stellar testnet
- Tracks spending against your budget in real-time
- Synthesizes all findings into a comprehensive research report
- You see everything live: each API call, its cost, the Stellar transaction hash, and the final report
Agents can reason and plan — but they still can't pay. x402 on Stellar changes that. SARA demonstrates what happens when AI agents get their own wallet and can make economic decisions: choosing which data to buy, how much to spend, and when to stop — using real stablecoin micropayments on a real blockchain.
User (Browser)
└─> Next.js Frontend
└─> POST /api/research (SSE stream)
└─> Orchestrator Agent (OpenAI GPT-5.1, function calling)
├─> Fetches service catalog from xlm402.com
├─> Plans sub-tasks based on query
├─> For each task:
│ ├─> Calls x402 endpoint (pays USDC on Stellar)
│ └─> Collects results
└─> Synthesizes report with cost breakdown
| Service | Endpoints | Cost/call |
|---|---|---|
| Weather | Current, forecast, archive, history summary | $0.01 |
| News | 13 categories (tech, AI, crypto, business, etc.) | $0.01 |
| Crypto | Quote, candles (OHLCV) | $0.01 |
| Web Scrape | Extract content from any public URL | $0.03 |
| Data Collect | Bounded same-origin crawl | $0.08 |
- Frontend: Next.js 16, React 19, Tailwind CSS 4
- AI Orchestration: OpenAI GPT-5.1 with function calling
- Payments: x402 protocol on Stellar testnet (USDC)
- Blockchain: Stellar testnet via
@stellar/stellar-sdk - x402 SDK:
@x402/fetch,@x402/stellar,@x402/core - Data Services: xlm402.com (44 paid endpoints)
- Node.js 18+
- OpenAI API key
- Testnet USDC (free from Circle faucet)
cd stellar-sara
npm installnpx tsx scripts/setup-wallet.tsThis generates a new keypair, funds it with testnet XLM via Friendbot, and creates a USDC trustline.
- Go to https://faucet.circle.com/
- Select Stellar Testnet
- Paste your public key from step 2
- Request testnet USDC
Edit .env.local and add your OpenAI API key:
OPENAI_API_KEY=sk-...
STELLAR_PRIVATE_KEY=S... # Already set by setup script
STELLAR_PUBLIC_KEY=G... # Already set by setup scriptnpm run dev- The agent makes a standard HTTP request to a paid endpoint on xlm402.com
- The server responds with
402 Payment Required+ payment details - The x402 SDK automatically signs a USDC payment on Stellar
- The request is retried with the signed payment header
- The facilitator verifies and settles the payment on-chain
- The agent receives the data
All of this happens in a single fetch() call thanks to wrapFetchWithPayment().
- "What's happening in the crypto market today and how might global economic news affect Bitcoin?"
- Chains: crypto quote + candles + news/blockchain + news/economics
- "What's the weather like in major tech hubs and what's the latest in AI?"
- Chains: weather/current (multiple cities) + news/tech + news/ai
- "Research the latest cybersecurity threats and their potential impact on blockchain"
- Chains: news/security + news/blockchain + scrape (relevant URLs)
- Budget-constrained autonomy: The agent decides what to pay for within your budget
- Real Stellar transactions: Every API call is a real USDC payment on Stellar testnet
- Live cost tracking: Watch your budget deplete in real-time with transaction links
- Service discovery: Agent programmatically discovers available services from the xlm402.com catalog
- Streaming UI: Server-Sent Events stream every step of the agent's decision process
- Currently uses xlm402.com testnet endpoints only (no mainnet spending)
- AI chat/image services are mainnet-only on xlm402.com, so they're not included
- Could be extended with MPP session mode for high-frequency streaming data
- Budget optimization could be improved with cost/value scoring