Turn on paid calls from a server
Before its first paid call, a payment key is bound to your API key and a person approves it once in the web app. The SDK does the binding; the approval is a person’s step and cannot be automated. This page covers both, and what happens when you replace a key.
Create a payment key
Section titled “Create a payment key”The payment key is an EVM key that your server holds. The SDK never creates or stores keys: make one with your own tools, for example viem’s generatePrivateKey() or eth-account’s Account.create(), and keep it in your secret store or KMS.
Make a new key just for this, not your wallet’s key. It can only sign payments within the caps a person approves, and the SDK refuses to pay with a key that is the paying account itself.
Check the status, then bind
Section titled “Check the status, then bind”const status = await assay.paidCalls.status();if (status.state !== "active") { const setup = await assay.paidCalls.bind(); console.log(`Approve at ${setup.approvalUrl}`); console.log(`The page must show ${setup.fingerprint}`);}status = assay.paid_calls.status()if status.state != "active": setup = assay.paid_calls.bind() print(f"Approve at {setup.approval_url}") print(f"The page must show {setup.fingerprint}")bind() asks Assay for a challenge, checks every field of it, signs it with your payment key to prove you hold it, and binds the key. Calling it again is safe: a key that is already bound, or already waiting, is not signed again (alreadyBound is true).
Show the link and the fingerprint to the person who will approve: the last 8 hex digits of the key’s address, in two groups of four, such as 1A2B 9F3C.
A person approves once
Section titled “A person approves once”The person opens the link on portal.goassay.ai and signs in to the account that owns the API key. Then:
- Check that the fingerprint under Payment key matches the one your server printed. If it differs, do not approve.
- Select It matches what my app showed.
- Review the limits: Per call $0.50, Per 24 hours $5 and Days 30 by default. They become the key’s on-chain caps.
- Add funds if the page asks for them, then choose Approve and sign in the wallet.
- Wait for Paid calls are on. Go back to your app and ask again.
The approval link carries the key’s address only in the URL fragment, which browsers never send to a server. The SDK builds the link on your webUrl origin; it uses a link the server sent only when that link is on the same origin.
Wait until paid calls are on
Section titled “Wait until paid calls are on”await assay.paidCalls.waitUntilActive({ timeoutMs: 15 * 60_000 });assay.paid_calls.wait_until_active(timeout=15 * 60)It polls every 5 seconds for 2 minutes, then every 15 seconds, and returns once this client’s key is the bound key and its paid calls are on. After the time limit it raises an error with code WAIT_TIMEOUT. In Node, pass signal to stop it early.
Check it worked
Section titled “Check it worked”status() answers state: "active", and a paid tools.call returns a result with a non-zero charged amount.
Status states
Section titled “Status states”state |
Meaning | Do this |
|---|---|---|
unbound |
No payment key is bound to this API key. | Call bind(). |
pending_approval |
This key is bound, or waits to replace another, and no one has approved it yet. | Show the link; call waitUntilActive(). |
active |
Paid calls are on for this key. | Nothing. |
expired |
The approval lapsed (its Days ran out). | Ask the person to approve again with the link. |
bound_to_other_key |
Another key is bound to this API key. | Call bind() to ask to replace it. |
unknown |
Assay could not read the key’s permission from the chain just now. | Ask again later. Do not treat it as off. |
The status also gives delegate (the bound key), pendingDelegate (a key waiting for approval), boundAt, pendingSince, the on-chain caps, approvalUrl and fingerprint. Python uses the same names in snake case.
Replace a payment key
Section titled “Replace a payment key”When another key is already bound to the API key, bind() does not replace it at once:
- It answers
bindStatus: "PENDING_APPROVAL"(bind_statusin Python). - The old key stays
delegateand keeps signing payments. - The new key waits as
pendingDelegate. It replaces the old key in one step when a person approves it. waitUntilActive()returns only when the new key isdelegateand its paid calls are on.
So a new key never takes over silently, and paid calls keep working during the change. On the approval page, the person sees Replace the payment key for your app, the new key under Payment key and the old one under Current payment key:. After approving, the page offers Stop the old key: the old key keeps its on-chain permission until someone stops it.
The person can also choose Discard beside the waiting key under Controls → Agents. The old key keeps paying, and your server must call bind() again to ask for a replacement.
Errors
Section titled “Errors”| Error | Code | Meaning | Fix |
|---|---|---|---|
ScopeMissingError |
AUTH_SCOPE_MISSING (requiredScope: "payments") |
The API key has no Pay permission. | Create a key with the Agent choice and use it. |
DelegateAlreadyBoundError |
ACCOUNT_DELEGATE_ALREADY_BOUND (409) |
This payment key is bound, or waiting, on another live API key. Nothing was bound. | Use a payment key of this server’s own, or revoke the other API key first. |
DelegateBindConflictError |
ACCOUNT_DELEGATE_BIND_CONFLICT (409, retryable) |
Another key won a first bind of this API key at the same moment. Nothing was bound. | Call bind() once more: your key then waits as pendingDelegate for approval. The SDK does not retry this on its own. |
PaymentNetworkUnknownError |
G2_NETWORK |
No network for the signer is in the client’s table. | Update the SDK, or pass networks for another deployment. See Configure the client. |
ConfigError “bind() needs an eip155 signer” |
CONFIG_INVALID |
The client has no EVM signer. | Pass signer. |
AssayError |
WAIT_TIMEOUT |
No approval within the time limit. | Check with the person, then wait again. |
