Open app

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.

  1. Make a private wallet

    Open /app, connect your wallet, press Make a private wallet and sign. Your service's keys are derived from it.

  2. 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_ID and AYO_SERVICE_KEY from the done screen: the key is shown once.

  3. Install the SDK

    Install
    npm install @ayo/sdk
  4. Set 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>
  5. 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 app

    Use the price and unit you listed. On Express, import serve from @ayo/sdk/express and mount it with app.use.

  6. Serve a paid call

    Call your endpoint without payment and you get 402 Payment Required with an Ayo-Hello header. 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