Quickstart: charge agents per call
List an API, add one middleware line, and serve a paid call.
You need a Solana wallet in your browser, Node 22, and a Hono or Express server.
Make a private wallet
Open /app, connect your wallet, press Make a private wallet and sign. Your service's keys are derived from it.
List the service
Go to /app/services/new. Enter a name, your endpoint, a price per unit in USDC, the unit, a settlement window and a maximum unpaid amount per tab. Press List service and approve. Copy
AYO_SERVICE_IDandAYO_SERVICE_KEYfrom the done screen: the key is shown once.Install the SDK
Install npm install @ayo/sdkSet the environment
.env AYO_SERVICE_ID=<the service address from the done screen> AYO_SERVICE_KEY=<the key from the done screen> AYO_PROGRAM_ID=<Ayo program ID> AYO_RPC_URL=<Solana RPC URL> AYO_API_URL=<Ayo API URL>Add the middleware
server.ts import { Hono } from 'hono' import { serve } from '@ayo/sdk/hono' const app = new Hono() app.use('/v1/*', serve({ price: '0.002', unit: 'call' })) app.get('/v1/search', (c) => c.json({ results: ['…'] })) export default appUse the price and unit you listed. On Express, import
servefrom@ayo/sdk/expressand mount it withapp.use.Serve a paid call
Call your endpoint without payment and you get
402 Payment Requiredwith anAyo-Helloheader. Call it from an agent and it gets paid:agent.ts import { agent } from '@ayo/sdk' const payments = agent(process.env.AYO_AGENT_KEY!) const res = await payments.fetch('https://your-api.example/v1/search?q=hello') await payments.shutdown()Your service's page in the app shows the tab, its running total, and the settlement once the agent shuts down.
Next
- List a service: terms, settlement and a durable voucher store
- Settlement: how one transfer pays a whole tab