- Top up a prepaid Buyer Wallet using PayPal Sandbox.
- Issue a scoped Agent Key with policy limits.
- Protect an existing API with 2 lines of middleware in Hono or Express.
- Run an autonomous Google Gemini Research Agent that negotiates HTTP 402 challenges and settles micro-payments in real USD.
- Withdraw earned seller revenue directly back to your PayPal account.
Architecture Flow
Prerequisites
Before starting, ensure you have:- Bun (
v1.2+) installed. - A free PayPal Developer Sandbox account.
- A Google Gemini API Key.
Step 1: Fund Buyer Wallet & Create Agent Key
- Navigate to the Haggles Portal: haggles-portal.onrender.com.
- Log in using your PayPal Sandbox account.
- Go to Buyer > Wallet (
/buy/wallet):- Click Add Funds.
- Approve a
$10.00sandbox deposit. The ledger credits your prepaid USD balance instantly.
- Go to Buyer > Agent Keys (
/buy/keys):- Click Create Key.
- Set Name:
Research Agent. - Set Daily Cap:
$5.00. - Set Per-Call Max:
$0.10. - Copy the generated key:
hgk_test_....
Step 2: Set Up Seller API (seller-datasets)
The seller exposes public and paywalled endpoints using @haggles/server.
Launch the Seller Service:
- Open your terminal in the repo root:
http://localhost:4010.
Step 3: Launch the Gemini Research Agent UI
The research agent queries data vendors autonomously and renders real-time receipts in a Space Grotesk timeline interface.- Open a second terminal window:
- Open
http://localhost:4012in your browser. - Click Run Research Agent ($0.07):
- Step 1: Discovers endpoints from
seller-datasets. - Step 2: Transparently negotiates three HTTP 402 challenges:
GET /datasets/rent-index?city=austin($0.03)GET /datasets/rent-index?city=chicago($0.03)GET /datasets/transit-fares?city=austin($0.01)
- Step 3: Gemini synthesizes the purchased data into a concise comparative report.
- Step 1: Discovers endpoints from
- Inspect the Live Spend Panel: Notice the sub-100ms settlement times, remaining daily allowance, and immutable Ed25519 receipt hashes.
Click Test Policy Cap ($0.08) to see the gateway block an excessive purchase on demand, proving that developers are 100% immune to runaway LLM billing loops.
Step 4: Verify Seller Revenue & Request Payout
- Return to the Haggles Portal:
- Navigate to Seller > Endpoints (
/sell/endpoints): The routes/datasets/rent-indexand/datasets/transit-faresappear automatically with live call volumes and revenue.
- Navigate to Seller > Endpoints (
- Navigate to Seller > Earnings (
/sell/earnings):- View accumulated USD revenue.
- Click Request Payout to transfer earnings directly to your connected PayPal account.