@curless/agentbank-sdk
v0.1.2
Published
Official buyer/agent SDK for agentbank — OAuth, agent + customer management, Wallets, and the Pay spend-control plane.
Downloads
1,381
Readme
@curless/agentbank-sdk
Official SDK for agentbank — agent-commerce payments. Wraps the agentbank API: agent OAuth, agent/customer management, and the Pay spend-control plane.
npm install @curless/agentbank-sdkQuick start
Admin (manage agents, fund, approve)
import { Agentbank } from '@curless/agentbank-sdk';
const ab = new Agentbank({
baseUrl: 'https://api.agentbank.example',
apiKey: 'agb_admin_...', // an agentbank:admin / pay:admin key
});
// 1. create an agent + a spend policy
const agent = await ab.agents.create({
name: 'procurement-bot',
spendPolicy: { perTransactionLimit: 50_00, dailyLimit: 500_00, approvalRequiredAbove: 100_00 },
});
// 2. fund it (after an org deposit), and issue it a client credential
await ab.pay.deposit({ amount: 1000_00, currency: 'USD' });
await ab.pay.fundAgent(agent.id, { amount: 500_00, currency: 'USD' });
const cred = await ab.agents.issueCredential(agent.id); // cred.secret shown onceAgent (spend, with auto-managed token)
// Exchanges the credential for short-lived tokens; auto-refreshes.
const agentClient = Agentbank.withClientCredentials({
baseUrl: 'https://api.agentbank.example',
clientSecret: cred.secret, // the agb_… issued above
});
const auth = await agentClient.pay.authorize({
agentId: agent.id,
merchantRef: 'acme.example',
amount: 12_00, // minor units
idempotencyKey: 'order-123',
});
// auth.status: 'authorized' | 'pending_approval' | 'denied'
if (auth.status === 'authorized') {
await agentClient.pay.capture(auth.id);
}Notes
- Amounts are minor-unit integers (USD = cents).
- Errors throw
AgentbankErrorwith.status+.code. - ESM-only; Node ≥ 18 (uses global
fetch). - Pass
fetchin the constructor to inject a custom implementation (tests, proxies).
