Accept Per-Call Payments
Charge a fixed amount for each API request.
Per-call metering is the simplest mode. Every request costs the same fixed amount, regardless of payload size or processing time.
Server setup
import { AMP } from "@valeo/amp-server"
const amp = new AMP({
wallet: serverKeypair,
connection,
pricing: {
mode: "per-call",
rate: "10000", // $0.01 per call (USDC, 6 decimals)
token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
minDeposit: "1000000",
settleInterval: 3600,
},
})
app.use("/v1", amp.middleware())
app.get("/v1/data", (req, res) => {
res.json({ result: "paid content", balance: req.amp?.balance?.toString() })
})How metering works
- Each request that passes validation increments a counter.
- The meter tracks: call count, first/last sequence numbers, period timestamps.
- At the settlement interval, the server submits one on-chain transaction:
amount = callCount * rate
Rate string shorthand
The rate string "0.001/call" is syntactic sugar:
| String | Mode | Rate (smallest unit) |
|---|---|---|
"0.001/call" | per-call | 1000 |
"0.01/call" | per-call | 10000 |
"1.00/call" | per-call | 1000000 |
Per-route pricing
Different routes can have different rates:
const amp = new AMP({
wallet: serverKeypair,
connection,
pricing: { mode: "per-call", rate: "1000", token: "...", minDeposit: "1000000", settleInterval: 3600 },
routes: {
"/v1/inference": { mode: "per-call", rate: "100000" }, // $0.10
"/v1/search": { mode: "per-call", rate: "5000" }, // $0.005
},
})