Documentation Index
Fetch the complete documentation index at: https://docs.faremeter.xyz/llms.txt
Use this file to discover all available pages before exploring further.
A complete example of an AI agent that discovers and pays for a protected API endpoint.
Client: the agent
import "dotenv/config"
import { payer } from "@faremeter/rides"
import { getLogger } from "@faremeter/logs"
const logger = await getLogger(["agent"])
await payer.addLocalWallet(process.env.PAYER_KEYPAIR_PATH)
const response = await payer.fetch("http://localhost:3000/api/analyze", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt: "Summarize the latest market trends",
}),
})
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`)
}
const result = await response.json()
logger.info(JSON.stringify(result))
Server: the paid API
import express from "express"
import { createMiddleware } from "@faremeter/middleware/express"
import { x402Exact } from "@faremeter/info/solana"
const app = express()
app.use(express.json())
const paymentWall = await createMiddleware({
facilitatorURL: "https://facilitator.corbits.dev",
accepts: [
...x402Exact({
network: "devnet",
payTo: process.env.MERCHANT_ADDRESS,
asset: "USDC",
amount: "5000",
}),
],
})
app.post("/api/analyze", paymentWall, (req, res) => {
const { prompt } = req.body
res.json({
analysis: `Analysis for: ${prompt}`,
timestamp: new Date().toISOString(),
})
})
app.listen(3000)
Running the example
# Terminal 1: Start the server
MERCHANT_ADDRESS=7xKXwxRPMo2sUAT5... pnpm tsx server.ts
# Terminal 2: Run the agent
PAYER_KEYPAIR_PATH=~/.config/solana/id.json pnpm tsx agent.ts
The agent makes a POST request. The server responds with 402. Rides handles the payment. The server returns the analysis result.