Reference

SDK reference

Every method of the TypeScript SDK, with the Python equivalents.

Constructor

ts
new Unslept({
  agentAccount,   // AgentAccount address
  signer,         // viem account, or anything with an address and signTypedData
  network,        // "robinhood-chain" reads its settings from the environment
  chain?,         // custom chain implementation, instead of the preset
  fetch?,         // custom fetch implementation
  schemes?,       // scheme preference, default ["unslept-direct", "exact"]
  onPayment?,     // called after every settled payment
  reportUrl?,     // Unslept site URL, to report policy refusals to webhooks
})

Methods

TypeScriptWhat it returns
fetch(input, init?, { maxAmount? })A Response. Pays a 402 if needed, within maxAmount and the policy.
getBalances()liquid, working, debt and net, in atomic USDG.
getPolicy()perCallCap, dailyCap, remainingToday, paused and revoked.
setPolicy(policy)A transaction hash. Owner only.
getPayments({ limit? })Settled payments read from chain.
localPayments()Payments made by this SDK instance, with transaction hashes.
onLowBalance(cb, { threshold, intervalMs? })A function that stops the watch.

Python

The Python SDK mirrors the TypeScript one with snake case names: fetch(url, method, headers, body, max_amount), get_balances(), get_policy(), set_policy(policy), get_payments(limit), local_payments() and on_low_balance(callback, threshold). Wrap an eth_account key in EthAccountSigner to use it as the signer.