Add Payments to Your API
Accept AMP payments for your API endpoints in under 5 minutes.
Using an LLM?
Paste this into your coding agent:
Reference https://amp.valeoprotocol.io/quickstart/server
Add AMP payments to my Express server with a /v1/data route
that charges $0.01 per request using USDC on Solana.Install
npm install @valeo/amp-server @solana/web3.jsOne-liner setup
The fastest way to add AMP payments:
import express from "express"
import { AMP } from "@valeo/amp-server"
const app = express()
// Protect all routes — $0.001 per call
app.use(AMP.middleware({ rate: "0.001/call" }))
app.get("/v1/data", (req, res) => {
res.json({
message: "Hello from a paid API!",
channel: req.amp?.channel?.toBase58(),
})
})
app.listen(3000)This does everything automatically:
- Returns
402with pricing headers when no AMP credentials are present - Validates the channel on-chain
- Verifies Ed25519 signatures
- Meters usage
- Auto-settles periodically
Full configuration
For production, provide your own keypair and connection:
import { AMP } from "@valeo/amp-server"
import { Keypair, Connection } from "@solana/web3.js"
const serverKeypair = Keypair.fromSecretKey(/* your key */)
const connection = new Connection("https://api.mainnet-beta.solana.com")
const amp = new AMP({
wallet: serverKeypair,
connection,
pricing: {
mode: "per-call",
rate: "10000", // $0.01 in USDC (6 decimals)
token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
minDeposit: "1000000", // $1.00 minimum channel deposit
settleInterval: 3600, // settle every hour
},
routes: {
"/v1/inference": { mode: "per-call", rate: "100000" }, // $0.10/call
"/v1/stream": { mode: "per-second", rate: "1000" }, // $0.001/sec
},
settlement: { auto: true, interval: 3600 },
})
// Serve pricing manifest
app.get("/.well-known/amp.json", amp.wellKnownHandler())
// Protected endpoints
app.use("/v1", amp.middleware())Pricing manifest
AMP clients discover your pricing via /.well-known/amp.json:
{
"amp_version": "1.0",
"recipient": "<your_pubkey>",
"program_id": "2d1B2PmumwYWuR82AbXAARTL1nrn8N7Vu9bLXTXUDmVA",
"network": "solana:mainnet-beta",
"pricing": {
"default": {
"mode": "per-call",
"rate": "10000",
"token": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"minDeposit": "1000000",
"settleInterval": 3600
}
}
}What happens when a client connects
- Client sends
GET /v1/datawith no AMP headers - Your middleware returns
402withAMP-Pricingheaders - Client opens a channel on-chain (deposits USDC)
- Client retries with
AMP-Channel,AMP-Seq,AMP-Sigheaders - Middleware validates, meters, and calls
next() - Your handler runs normally —
req.amphas channel context