A pay-per-prompt AI chat application that monetizes an Ollama LLM behind the x402 payment protocol. Users connect a wallet, pay micro-amounts in USDC per request, and chat with the model. Responses are generated and signed inside an Oyster CVM TEE for end-to-end verifiability.
┌────────────┐ ┌──────────────────┐ ┌──────────────┐
│ Frontend │──────▶│ x402 Gateway │──────▶│ Ollama │
│ (Next.js) │ x402 │ (Rust / Axum) │ HTTP │ LLM Server │
│ port 5000 │◀──────│ port 3000 │◀──────│ port 11434 │
└────────────┘ └──────────────────┘ └──────────────┘
- The Frontend sends a chat request with an x402 payment header.
- The x402 Gateway validates payment via the facilitator, forwards the request to Ollama, signs the response with a TEE-backed key, and returns it.
- The Frontend renders the markdown response and displays signature verification info.
The gateway is a high-performance Rust/Axum reverse proxy that intercepts HTTP requests, enforces x402 payment, and signs responses.
For full documentation, see marlinprotocol/x402-gateway.
- Multi-Chain Support — Accept payments on Base, Polygon, Avalanche, Solana, and more.
- Per-Endpoint Pricing — Configure different USDC amounts for different routes.
- TEE Signatures — Responses signed with a secp256k1 key (via Oyster KMS).
The gateway is configured via a config.json file.
| Field | Description |
|---|---|
gateway_port |
Port the gateway listens on (default 3000) |
facilitator_url |
x402 facilitator service URL (e.g., https://www.x402.org/facilitator) |
target_api_url |
Backend API to proxy requests to (e.g., http://127.0.0.1:11434) |
networks[].type |
Type of blockchain network ("evm" or "solana") |
networks[].network |
Network ID (e.g., "base-sepolia", "solana-devnet") |
networks[].payment_address |
Wallet address for receiving payments (e.g., 0xd232A8b0F63a555d054134f67b298ffE955f3BAf for EVM or EGBQqKn968sVv5cQh5Cr72pSTHfxsuzq7o7asqYB5uEV for Solana) |
protected_routes[].path |
Protected API route (e.g., "/api/chat") |
protected_routes[].usdc_amount |
USDC amount required for accessing the route (e.g., 100) |
A Next.js 16 + React 19 chat interface with wallet integration and x402 payment handling.
cd x402-frotend
npm install
npm run devThe frontend will start on http://localhost:5000. Open it in your browser, connect your wallet, and start chatting.
| Script | Description |
|---|---|
npm run dev |
Start dev server on port 5000 |
npm run build |
Create optimised production build |
npm start |
Serve production build on port 5000 |
Simulate locally:
oyster-cvm simulate --docker-compose docker-compose.yml \
--init-params "config.json:1:0:file:./config.json" -p 3000Deploy to production:
oyster-cvm deploy \
--wallet-private-key <key> \
--duration-in-minutes 30 \
--arch amd64 \
--docker-compose docker-compose.yml \
--init-params "config.json:1:0:file:./config.json"Get the expected public key from Oyster KMS:
oyster-cvm kms-derive \
--image-id <IMAGE_ID> \
--path signing-server \
--key-type secp256k1/publicIf both public keys match, the response is verified as originating from the expected Oyster enclave running the correct image.
EVM Mainnets: Base, Polygon, Avalanche, Sei, XDC, XRPL EVM, Peaq, IoTeX, Celo
EVM Testnets: Base Sepolia, Polygon Amoy, Avalanche Fuji, Sei Testnet, Celo Sepolia
Solana: Mainnet, Devnet
