List a service
Put a paid API in the directory and take payment per call from any Ayo agent.
A listed service is an on-chain record of your endpoint and its terms, plus middleware in front of your API that holds agents to them. Agents find the service at /app/services, call it, and pay by the call over a tab. Payments settle into your private wallet.
You need a private wallet (see Fund an agent) and an HTTP server on Hono or Express.
Choose the terms
| Field | What to put |
|---|---|
| Name | What agents see in the directory, up to 80 characters |
| Endpoint | The URL that answers the hello. Agents pay for calls to this URL and any path under it |
| Price per unit | In USDC, such as 0.002 |
| Unit | What one charge is: call, query, page |
| Settlement window | 1, 6 or 24 hours. A tab not settled in this time can be flagged unpaid |
| Max unpaid per tab | The most you serve on one tab before it settles, in USDC. At least the price |
The agent's SDK settles before the window ends and before a call would pass the maximum, so these two numbers bound how long and how much you serve on credit.
List it
List a service
Go to /app/services/new, fill in the terms and press List service. Approve the transaction. Your browser derives the service's own keys from your private wallet and the service's index: a signing key, which signs
confirm_tabandflag_unpaidand gets a little SOL for their fees, and a Ring address, where settlements arrive. Because the keys come from yours, your browser can always read what the service has received.Copy the middleware
The done screen shows
AYO_SERVICE_IDandAYO_SERVICE_KEYin one block, next to the middleware line for your price and unit. Copy them into your server's environment; the key is shown once. Open the service shows the service's page.
Add the middleware
import { Hono } from 'hono'
import { serve } from '@ayo/sdk/hono'
const app = new Hono()
app.use('/v1/*', serve({ price: '0.002', unit: 'query' }))
app.get('/v1/search', (c) => c.json({ results: [] }))import express from 'express'
import { serve } from '@ayo/sdk/express'
const app = express()
app.use('/v1', serve({ price: '0.002', unit: 'query' }))
app.get('/v1/search', (req, res) => res.json({ results: [] }))Mount it on the paths under your registered endpoint, with the price and unit you listed; the middleware checks them against the listing.
The middleware reads the service's address from AYO_SERVICE_ID and its key from AYO_SERVICE_KEY, plus the cluster settings in the SDK environment.
What the middleware does
- A request without a voucher gets
402withAyo-HelloandAyo-Settlement-Window. The agent opens a tab and repeats the request. - A request with a voucher reaches your handler only if the voucher checks out: signature, tab, agent status, sequence, exact price, maximum unpaid. The response carries
Ayo-Accepted. - When the next call would pass the maximum, or
settleAtis reached, the response also carriesAyo-Settle: now. - When the agent has settled, it sends
HEADwithAyo-Settle: confirm. The middleware decrypts the transfer, checks the amount against the last voucher, sendsconfirm_taband answers204.
Each accepted call is also posted to the API as a record encrypted to your viewing key, so your service's page shows open tabs with their running totals and the settlements you've received.
Keep vouchers
The middleware journals the last voucher of each tab to files under .ayo/ in the working directory, so a restart keeps every tab it was serving. Point storeDir at a folder that survives deploys, or pass your own store with an atomic compareAndSet. See VoucherStore. The journal is your evidence if a tab goes unpaid.
Change the listing
While any of your tabs is outstanding, you can change the name and endpoint but not the billing terms. The program refuses with OutstandingTabs. Once every tab has settled, been flagged or been voided, any term can change. A tab an agent opened and never paid on can be closed with void(tabId) once its window passes.