Skip to content

Channel payments

From release 1.2.0, the SDK pays for calls on a payment channel. Instead of one signed payment and one on-chain transaction per call, your payment key signs one running total per channel, and Assay settles many calls on chain in one transaction. The on-chain cost per call is much lower. Your spend limits, the refund rules and the dispute hold stay the same.

Channels are on by default, with nothing to configure. On a server with a normal file system, the code from Turn on paid calls from a server already pays this way. Read this page if your code runs where there is no file system (a Cloudflare Worker, a browser), or if you run several processes with one payment key.

A lane is one channel from your payer to one provider, signed by your payment key. Each paid call on a lane adds its price to the lane’s running total, and your key signs the new total. The SDK keeps its own record of every lane and writes it to disk before each signature. It never takes a total from the server.

Stage What happens
Call Assay offers a channel with the payment request. The SDK checks the request as it does for every paid call, then signs the lane’s new total.
Settle Assay records the lane’s calls on chain in one transaction, about 30 minutes after the first call not yet recorded. It settles sooner when that part of the lane reaches $5, or when a signature would otherwise expire. Until then the money stays in your escrow.
Dispute hold The settled amount is held for at least 1 hour, rounded up to the next full hour. A bad-result report accepted in this time is refunded in full.
Payout After the hold, the provider is paid in its next payout run.

The SDK uses a channel only when Assay offers one and the offer matches the per-call payment request exactly. Otherwise it pays that call per call, as before. A per-call payment is the automatic fallback; you do not choose between them.

On a server, pass nothing: the lane record goes into a file in your Assay config folder.

import { Assay, evmSigner } from "@goassay-ai/sdk";
import { privateKeyToAccount } from "viem/accounts";
const assay = new Assay({
signer: evmSigner(privateKeyToAccount(process.env.PAYMENT_KEY as `0x${string}`)),
});

To keep the record somewhere else, for example on a mounted volume:

import { Assay, evmSigner, fileChannelStore } from "@goassay-ai/sdk";
const assay = new Assay({
signer: evmSigner(account),
channels: { store: fileChannelStore("/var/lib/my-agent/assay-lanes.json") },
});
import os
from eth_account import Account
from goassay import Assay, evm_signer
client = Assay(signer=evm_signer(Account.from_key(os.environ["PAYMENT_KEY"])))

To keep the record somewhere else, for example on a mounted volume:

from goassay import Assay, FileChannelStore, evm_signer
client = Assay(
signer=evm_signer(account),
channels=FileChannelStore("/var/lib/my-agent/assay-lanes.json"),
)

On a runtime without a file system, such as a Cloudflare Worker or a browser, the client cannot keep a record on its own and refuses to start with a ConfigError. Pass a store that lasts: an object with load(), save(book) and, optionally, exclusive(fn), backed by durable storage of your choice. memoryChannelStore() (MemoryChannelStore() in Python) keeps lanes only while the process runs: use it for tests.

Topic Rule
Default lane file One file per payment key, named after the key’s address, in a goassay/channels/ folder: ~/Library/Application Support/ on macOS, ~/.config/ on Linux, %USERPROFILE%\AppData\Roaming\ on Windows. The file is readable by your user only (mode 0600), with a lock file next to it.
One process per file A lane file belongs to one process at a time. A second process using the same file (or the same payment key with the default file) pays per call. To run several processes with channels, give each its own payment key, or its own file with fileChannelStore(path). Clients inside one process share the file safely.
Keep the file The lane record is what lets the SDK continue a lane after a restart and renew an earlier channel payment (below). Do not delete it or restore it from an old backup. A damaged record is never reset: the client pays per call until a person fixes or removes the file.
Spend limits limits and the on-chain caps count what each call adds (its price), never the lane’s total.
onPayment amount is still the price of this one call. On a channel, channel adds channelId, cumulative (the lane’s new total), calls and increase (what this signature adds: the price, or "0" when an unchanged total is signed again).
Chain check Before it continues a lane after a restart, or after 10 minutes, the SDK compares its record with the escrow’s own state on chain. A record behind the chain is retired and a new lane opened. If the chain cannot be read, that call is paid per call.
Parallel calls A lane carries one call at a time. Parallel calls use more lanes, up to 8 per provider.
Your own network entry An entry you pass in networks replaces the built-in one whole: it must say channels: true for channels to be used on it.

If a channel payment for a call you received could not be collected in time, Assay pauses your paid calls (PAYMENT_DEBT_OUTSTANDING) until it is collected. Only the key that signed the lane can renew that payment, so the SDK does it for you: when a paid call is refused for a debt, it signs the same total again on the same lane, never more, and sends it to Assay. The call itself is not sent again, and the renewal does not count toward your limits a second time.

You can also run it yourself, at most once a minute:

const results = await assay.paidCalls.renewChannelDebts();
for (const r of results) console.log(r.intentId, r.status);
for r in client.paid_calls.renew_channel_debts():
print(r.intent_id, r.status)
status Meaning
renewed Signed again and sent. Assay is collecting it; paid calls usually resume within about 5 minutes.
pending Already being collected.
per_call A per-call debt. A person settles it in the web app on Money → Funding.
no_lane, not_signed_here This client has no record of that lane (a deleted file, another computer or key). A person settles it on Money → Funding once the app offers it.
other_wallet Another wallet of your organization owes it. Its own agent, or a person in the web app, settles it.
rate_limited, failed Not renewed just now. Try again in a minute or two.
refused Assay refused the renewal (code says why). A person settles it on Money → Funding once the app offers it.

The web app offers to settle a channel debt per call only after the lane’s last signature can no longer be collected, about 2 hours after it expired. A memory store cannot renew a debt after its process ended.

Code Meaning Fix
ConfigError “channel vouchers need a durable store for their lanes” The runtime has no file system or home folder. Pass channels: { store } (channels= in Python).
PAYMENT_UNSETTLED_LIMIT Earlier payments are still being recorded on chain. Nothing was charged. The SDK resends short waits itself; otherwise call again after retryAfterMs with the same idempotency key.
CHANNEL_ROTATE, CHANNEL_LIMIT, CHANNEL_SIGNER_EXPIRING, CHANNEL_NOT_OFFERED The channel could not take this payment. Nothing was charged. Retryable. Call again. The next call uses a new lane, or pays per call for an hour.
PAYMENT_DEBT_OUTSTANDING An earlier payment is owed. The message says whether it is being collected. See Channel debts.

Every code, with its message, is in the Errors reference.