@trustline-agents/agent-sdk is the interface an AI agent uses to take and repay revenue-underwritten credit on TrustLine. The agent holds its own Stellar key — every on-chain write is signed by that key, never by TrustLine. Reads are simulate-only (free, no transaction submitted). Scoring/underwriting itself is delegated to the TrustLine backend (the trusted underwriter in v1).
Install
Construct an agent
Function reference
publicKey()
register()
score_registry (one-time — safe to call again, it’s idempotent on-chain). This is a write, signed and submitted by the agent’s own key. Returns { txHash, returnValue, explorerUrl }.
underwrite(opts?)
score_registry. This is the call that actually determines your credit limit and APR.
skipProof: true— skip the (slow, ~20-90s) zkTLS proof step and score on on-chain revenue only. Useful for a fast recheck after new on-chain payments land.fromLedger— an explicit ledger to start indexing from, if you know roughly when your agent’s history begins (helps when the RPC’s ~24h window would otherwise miss older payments).
score.score, score.tier, score.limitUsdc, score.aprBps, the independence breakdown per payer, and the zkTLS proof result if one was attempted.
onboard(opts?)
register() then underwrite(). This is almost always what you want for a brand-new agent.
creditLine()
credit_line contract (a free simulated read, not the backend’s cached copy). tier is the contract’s tier enum (0 = Unrated). Use this to check your terms without re-running a full underwrite.
availableCreditUsdc()
limit − outstanding principal, read live from the vault. Check this before calling borrow() to avoid a failed transaction.
vaultState()
usdcBalanceUsdc()
balance read) — not your credit line, your actual wallet balance.
borrow(usdc)
usdc against your credit line into your own wallet. A write, signed by your key. Will revert on-chain if you request more than availableCreditUsdc().
repay(usdc)
usdc — interest first (which funds the first-loss reserve and lender yield), then principal. A write, signed by your key. On-time repayment is what ramps your credit limit up over subsequent underwrite() calls; see How the credit engine works §4.3.
deposit(agentAddress, usdc)
usdc of liquidity into agentAddress’s isolated vault and is exposed only to that one agent’s default risk. Included on the same class because the SDK doesn’t distinguish “roles” — any keypair can act as either a borrower or a lender.
payWithCredit(url, priceUsdc, opts?)
priceUsdc— the price of the resource, in USDC (you need to know this ahead of time; the SDK doesn’t parse x402 challenge responses for you).opts.maxDraw— optional safety cap. If the shortfall would exceed this, throws instead of borrowing.opts.init— a normalfetchRequestInit(method, headers, body), forwarded to the actual paid request — e.g.{ method: "POST", body: JSON.stringify(...) }.
Response from the paid request.
revenue(fromLedger?)
underwrite() pass.
Types reference (quick index)
Error handling
The SDK throws typed errors (all extendingTrustLineError), so you can catch specific failures instead of string-matching messages:
toStroops, fromStroops, isValidStellarAddress, and creditShortfallUsdc are also exported if you want to reuse the SDK’s conversion/validation logic directly.
A complete, runnable example
Seepackages/agent-sdk/examples/quickstart.mjs for a full script that funds a fresh testnet agent and runs register → underwrite → borrow → repay end to end, with real captured output in the onboarding kit.
Build with Claude — the TrustLine skill
If you use Claude Code, there’s an officialtrustline-agent-sdk skill that teaches Claude to drive this SDK (both JS/TS and Python): the full lifecycle, draw-on-402, error handling, and the common pitfalls. Install it any of these ways:
/reload) and invoke it with /trustline-agent-sdk. If you clone the TrustLine repo, the skill is already present (it lives in .claude/skills/) — no install needed.