Skip to content

SDK quickstart

The Assay SDK calls tools from your own code over MCP. Free calls need only an API key. Paid calls also need a payment key that you hold: you pass the SDK a signer, and the SDK never stores or creates keys.

There are two packages with the same features: @goassay-ai/sdk for Node and goassay for Python. Pick your language in the tabs below.

Node 22 or newer. The package is ESM only.

Terminal window
npm install @goassay-ai/sdk

Python 3.10 or newer. The package is typed.

Terminal window
pip install goassay

Put your API key in the environment. The client reads ASSAY_API_KEY when you do not pass the key in code:

Terminal window
export ASSAY_API_KEY="assay_sk_live_..."

Search for a tool, read its contract and price, then call it. Use the tool name your search returns; weather_forecast is an example.

Save as free.mjs and run node free.mjs:

import { Assay } from "@goassay-ai/sdk";
const assay = new Assay(); // reads ASSAY_API_KEY
const found = await assay.tools.search("weather forecast", { limit: 5 });
console.log(found.results.map((t) => t.name));
const tool = await assay.tools.get("weather_forecast"); // schemas and price
const res = await assay.tools.call("weather_forecast", { city: "Lisbon" });
console.log(res.structuredContent); // the tool's output
console.log(res.isError); // true only for the provider's own tool error
console.log(res.receipt); // what the call cost

Save as free.py and run python free.py:

from goassay import Assay
with Assay() as assay: # reads ASSAY_API_KEY
found = assay.tools.search("weather forecast", limit=5)
print([t["name"] for t in found.results])
tool = assay.tools.get("weather_forecast") # schemas and price
res = assay.tools.call("weather_forecast", {"city": "Lisbon"})
print(res.structured_content) # the tool's output
print(res.is_error) # True only for the provider's own tool error
print(res.receipt) # what the call cost

AsyncAssay has the same methods for asyncio code.

Assay refusals are raised as errors. A result is returned only when the call ran; isError (is_error) is then the provider’s own tool error, not an Assay refusal.

To pay, pass a signer for your payment key. For a local key, wrap a viem account (Node) or an eth-account account (Python). A KMS or HSM key works too: a signer is any object with namespace ("eip155"), address and a signTypedData (sign_typed_data) method.

The payment key must be bound to your API key and approved by a person once before its first paid call. Do that first with Turn on paid calls from a server.

Terminal window
npm install @goassay-ai/sdk viem
import { Assay, evmSigner } from "@goassay-ai/sdk";
import { privateKeyToAccount } from "viem/accounts";
const assay = new Assay({
signer: evmSigner(privateKeyToAccount(process.env.PAYMENT_KEY)),
limits: { maxPerCall: "0.50", maxPerDay: "5" }, // dollars, checked before every signature
});
const res = await assay.tools.call("weather_forecast", { city: "Lisbon" });
console.log(res.receipt?.charged);
Terminal window
pip install goassay eth-account
import os
from eth_account import Account
from goassay import Assay, evm_signer
assay = Assay(
signer=evm_signer(Account.from_key(os.environ["PAYMENT_KEY"])),
limits={"max_per_call": "0.50", "max_per_day": "5"}, # dollars, checked before every signature
)
res = assay.tools.call("weather_forecast", {"city": "Lisbon"})
print(res.receipt and res.receipt.get("charged"))

Keep PAYMENT_KEY in your secret store, never in code. What happens on a paid tool:

  1. Assay answers the first attempt with PAYMENT_REQUIRED and the exact price. Nothing is charged.
  2. The SDK checks the request on your side: the network, escrow and asset against its own pinned table, the price against the tool’s quote, your key’s on-chain permission and caps, and your local limits. A failed check raises an error and signs nothing.
  3. Your onPayment (on_payment) hook runs, if you set one. Return false to refuse.
  4. The SDK signs one voucher and sends the same call again with the same idempotency key.

A voucher is never signed twice for one call, even when network retries resend it or you start the same call twice at once.

Only a paid call has a receipt to fetch. The call’s receipt already holds what it cost; a free call’s intentId is null. Reading a receipt needs the Read activity permission on the key, which the Agent choice includes.

const intentId = res.receipt?.intentId;
if (intentId) {
const receipt = await assay.receipts.get(intentId);
console.log(receipt.chargedPrice); // { amount: "100000", asset: "eip155:...", decimals: 6 }
}
intent_id = res.receipt.get("intentId") if res.receipt else None
if intent_id:
receipt = assay.receipts.get(intent_id)
print(receipt["chargedPrice"]) # {"amount": "100000", "asset": "eip155:...", "decimals": 6}

Amounts are in atomic units: USDG has 6 decimals, so "100000" is $0.10.

Every error is an AssayError with a stable code. Branch on the class or the code, never on the message.

import {
AssayError,
PaymentRefusedError,
PaymentRequiredError,
RateLimitError,
ScopeMissingError,
} from "@goassay-ai/sdk";
try {
await assay.tools.call("weather_forecast", { city: "Lisbon" });
} catch (e) {
if (e instanceof ScopeMissingError) console.error(`the API key needs the ${e.requiredScope} permission`);
else if (e instanceof PaymentRequiredError) console.error("paid tool: pass a signer");
else if (e instanceof PaymentRefusedError) console.error(`refused before signing by ${e.guard}: ${e.code}`);
else if (e instanceof RateLimitError) console.error(`retry in ${e.retryAfterMs} ms`);
else if (e instanceof AssayError) console.error(e.code, e.message);
else throw e;
}
from goassay import errors
try:
assay.tools.call("weather_forecast", {"city": "Lisbon"})
except errors.ScopeMissingError as e:
print(f"the API key needs the {e.required_scope} permission")
except errors.PaymentRequiredError:
print("paid tool: pass a signer")
except errors.PaymentRefusedError as e:
print(f"refused before signing by {e.guard}: {e.code}")
except errors.RateLimitError as e:
print(f"retry in {e.retry_after} s")
except errors.AssayError as e:
print(e.code, e.message)

A key made with Free calls only that calls a paid tool gets a ScopeMissingError naming payments. Nothing is signed or sent again; only a key with the Pay permission fixes it. Every class and code is in the Errors reference.

Every call has an idempotency key: yours, or one the SDK creates. Every error out of tools.call carries it. Calling again with that key is safe: Assay replays a call it already served and does not charge twice.

try {
return await assay.tools.call("weather_forecast", { city: "Lisbon" });
} catch (e) {
if (e instanceof AssayError && e.retryable && e.idempotencyKey) {
return await assay.tools.call("weather_forecast", { city: "Lisbon" }, { idempotencyKey: e.idempotencyKey });
}
throw e;
}
try:
res = assay.tools.call("weather_forecast", {"city": "Lisbon"})
except errors.AssayError as e:
if not (e.retryable and e.idempotency_key):
raise
res = assay.tools.call("weather_forecast", {"city": "Lisbon"}, idempotency_key=e.idempotency_key)

For work you may redo after a restart, pass your own key, such as order-1234-weather. A key is 1 to 128 printable ASCII characters and names one call: the same key with another tool or other arguments is refused with IDEMPOTENCY_KEY_REUSED. A result marked replayed is a stored answer and was not charged again.

The free call prints the tool’s output and a receipt with a zero charge. The paid call prints a non-zero charged amount, and the call shows in Activity → Calls in the web app.