Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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

  1. Each request that passes validation increments a counter.
  2. The meter tracks: call count, first/last sequence numbers, period timestamps.
  3. 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:

StringModeRate (smallest unit)
"0.001/call"per-call1000
"0.01/call"per-call10000
"1.00/call"per-call1000000

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
  },
})

Next steps