HTTP headers
The two headers an agent and a service exchange, byte for byte.
An Ayo service and an Ayo agent talk through HTTP headers. The service answers a call without a voucher with 402 Payment Required and an Ayo-Hello header. The agent then sends an Ayo-Voucher header with every paid request. Four smaller headers acknowledge vouchers, drive settlement and pick the hello version. The SDK writes and reads all of them; this page is for anyone implementing either side.
Encoding
Each header value is a UTF-8 JSON object, encoded as unpadded base64url. Field names are case-sensitive. Version 1 requires every field listed below and rejects any other field. The order of JSON properties doesn't matter, because the signature covers a fixed byte layout, not the JSON.
Integer strings use ASCII digits with no leading zeroes. They are strings because a u64 doesn't fit in a JavaScript number.
Ayo-Hello
Sent by the service with 402 Payment Required.
| Field | Type | What it is |
|---|---|---|
version | 1 | The number 1 |
service | address | Base58 address of the service account on chain |
pricePerUnit | u64 string | Positive u64 decimal string, in the mint's base units |
unit | string | Billing unit, such as query |
mint | address | Base58 mint address |
ringAddress | string | The service's public Ring receiving address |
A first call to the demo search service on a local validator, captured as it answered:
GET /search?q=solana HTTP/1.1
HTTP/1.1 402 Payment Required
Ayo-Hello: eyJ2ZXJzaW9uIjoxLCJzZXJ2aWNlIjoiQXZjTnptOTl0aGk3OVNQSEt2a01XNXc1MkNOTkEzY1huZGRDNWNQZTRpU2ciLCJwcmljZVBlclVuaXQiOiI1MDAwIiwidW5pdCI6InF1ZXJ5IiwibWludCI6IkVQakZXZGQ1QXVmcVNTcWVNMnFOMXh6eWJhcEM4RzR3RUdHa1p3eVREdDF2IiwicmluZ0FkZHJlc3MiOiJYZVY0c2NCS2NyelR5aUJDaGdkOGZVYjZmSndCVzc3OVJSVXVuMzR6bjJ2N1M2d0tQeFJYU0NSSk5IdEdnQkdKZkpqWExiRVJpckdZZXloU0xCdjlBaVVGc0t3Q0Y0cHZuRDJnM2JpUDdjcDhldk5rQ0ZSaG5MVGFIYmJ1MTRyakhMNWR3RSJ9
Ayo-Settlement-Window: 20The Ayo-Hello value decodes to:
{
"version": 1,
"service": "AvcNzm99thi79SPHKvkMW5w52CNNA3cXnddC5cPe4iSg",
"pricePerUnit": "5000",
"unit": "query",
"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"ringAddress": "XeV4scBKcrzTyiBChgd8fUb6fJwBW779RRUun34zn2v7S6wKPxRXSCRJNHtGgBGJfJjXLbERirGYeyhSLBv9AiUFsKwCF4pvnD2g3biP7cp8evNkCFRhnLTaHbbu14rjHL5dwE"
}Ayo-Settlement-Window is the service's settlement window as a decimal count of seconds.
Before opening a tab, the agent reads the service's account on chain and checks that the hello matches it: price, unit, mint, Ring address and window, and that the URL it called is under the registered endpoint. The program refuses to change a service's billing terms while any of its tabs is outstanding, so the terms an agent checked hold for the life of its tab.
Ayo-Voucher
Sent by the agent on every paid request after the tab is open.
| Field | Type | What it is |
|---|---|---|
tab | address | Base58 address of the tab account |
cumulativeAmount | u64 string | Total authorized on the tab through this call, positive u64 decimal string in base units |
sequence | u64 string | Positive u64 decimal string, starting at "1" and rising by one per call |
version | 1 | The number 1 |
signature | signature | Base58 of the agent's 64-byte Ed25519 signature over the signed message |
GET /v1/search?q=solana HTTP/1.1
Host: search.example
Ayo-Voucher: eyJ2ZXJzaW9uIjoxLCJ0YWIiOiI…The service verifies the signature with the tab agent's registered signing key. It then checks the tab, the agent's status, the expected sequence, that the total rose by the price of this call, and the maximum unpaid amount, before it serves.
A tab address belongs to one tab for its whole life. A closed tab's address is never reused, so its vouchers can't verify again.
Acceptance and settlement
Four more headers carry the rest of the exchange.
| Header | Sent by | Value | Meaning |
|---|---|---|---|
Ayo-Settlement-Window | service, with the 402 | seconds | How long after opening the tab must be settled |
Ayo-Accepted | service, with a paid response | the voucher's signature | The service accepted this voucher and served the call |
Ayo-Settle | service, with a paid response | now | Settle this tab now: the next call would pass the maximum unpaid amount, or the service's threshold is reached |
Ayo-Settle | agent, with HEAD | confirm | The settlement is recorded; decrypt it and confirm the tab |
Ayo-Settle | agent, with HEAD | reconcile | Did you accept this voucher? 204 with Ayo-Accepted if so, 409 if not. Serves nothing and doesn't move the sequence |
Ayo-Hello-Version | agent, with any request | 2 | Answer a 402 with the version 2 hello |
A service handles each voucher once. Sending an accepted voucher again gets 409 with the same Ayo-Accepted value, so an agent retrying after a lost response learns the call was already paid.
When a paid request loses its response, the voucher is pending. The agent sends it again with its next request, and before settling asks with HEAD and Ayo-Settle: reconcile. It settles the last total the service acknowledged.
After close_tab, the agent sends HEAD to the service's endpoint with its last voucher and Ayo-Settle: confirm. The service decrypts the transfer, checks the amount against that voucher, sends confirm_tab, and answers 204. A service that has lost its journal checks the presented voucher's signature, sequence and price against its terms instead.
Hello version 2
An agent that sends Ayo-Hello-Version: 2 gets a hello with "version": 2 and one more required field, settlementWindowSeconds (a positive u32), so the window arrives in the same object as the other terms. Without the request header, a service sends version 1. Vouchers are version 1 under either hello, with the same signed bytes.
The signed message
The agent signs these 126 bytes directly with Ed25519. The service, and the program when a tab is flagged unpaid, rebuild the same bytes from the voucher, the Ayo program ID and the genesis hash of their cluster. The genesis hash is fixed per deployment, never taken from the voucher.
| Offset | Length | Bytes |
|---|---|---|
| 0 | 14 | ASCII AYO_VOUCHER_V1 |
| 14 | 32 | The Ayo program ID, base58-decoded |
| 46 | 32 | The cluster's genesis hash, base58-decoded |
| 78 | 32 | The tab address, base58-decoded |
| 110 | 8 | Cumulative amount, unsigned little-endian u64 |
| 118 | 8 | Sequence, unsigned little-endian u64 |
A valid signature authorizes the cumulative total on that tab once.
Test vector
These values verify with standard Ed25519. The amount is larger than JavaScript's safe integer range on purpose.
| Input | Value |
|---|---|
| Program ID | 4vJ9JU1bJJE96FWSJKvHsmmFADCg4gpZQff4P3bkLKi |
| Genesis hash | 8qbHbw2BbbTHBW1sbeqakYXVKRQM8Ne7pLK7m6CVfeR |
| Tab | 1thX6LZfHDZZKUs92febYZhYRcXddmzfzF2NvTkPNE |
| Cumulative amount | 72623859790382856 |
| Sequence | 2 |
| Agent signing public key | 6FvEMf4TG1hVD5ZQo6LEoHcKPkna6vQAPVncj4honkTj |
| Signature | 5TkYqPp4LTcwZZuVnvZ5pHsU3BPiY87iz23ygt1wi6A86SLFYwM9mSZ7pJcRZqewv2eVAXeKces39EUpM9xWtg7E |
The message, as hex, one field per line:
41594f5f564f55434845525f5631
0101010101010101010101010101010101010101010101010101010101010101
0202020202020202020202020202020202020202020202020202020202020202
000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
0807060504030201
0200000000000000