On this page
Installation
npm install @aegis-os/sdk
# or: yarn add @aegis-os/sdk | pnpm add @aegis-os/sdkInitialisation
Create one client instance per application and reuse it. The client is stateless and safe for concurrent use.
import { AegisClient } from '@aegis-os/sdk'; export const aegis = new AegisClient({ apiKey: process.env.AEGIS_API_KEY, // required baseUrl: process.env.AEGIS_API_URL, // optional — defaults to production timeout: 10000, // optional — ms, default 10000 });
Submitting intents
Call aegis.intents.submit() before any AI-driven payment. The call returns immediately with a pending intent — policy evaluation happens asynchronously.
const intent = await aegis.intents.submit({ agentId: 'your-agent-uuid', amount: 12500, currency: 'INR', reason: 'Monthly SaaS subscription renewal', confidence: 0.97, // AI confidence (0–1) merchant: 'Notion', merchantCategory:'saas', metadata: { invoiceId: 'INV-2026-0341' }, }); console.log(intent.id); // "int_9f3a2b..." console.log(intent.status); // "pending"
Polling for a decision
Use aegis.intents.waitForDecision() to poll until the policy engine resolves the intent. Configure the timeout and polling interval to suit your workflow.
const resolved = await aegis.intents.waitForDecision(intent.id, { pollIntervalMs: 500, // default 500ms timeoutMs: 15000, // default 15s }); switch (resolved.status) { case 'approved': await executePayment(resolved.id); break; case 'pending_approval': // Notify user; finance team will act via dashboard break; case 'denied': throw new Error(`Spend denied: ${resolved.policyDecision}`); }
Receiving webhook events
Configure a webhook endpoint in the dashboard. AegisOS will POST signed events to your endpoint when intent status changes.
import { AegisClient } from '@aegis-os/sdk'; // Verify the webhook signature before trusting the payload const isValid = AegisClient.verifyWebhookSignature({ payload: rawBody, signature: req.headers['x-aegis-signature'], secret: process.env.AEGIS_WEBHOOK_SECRET, }); if (!isValid) { res.status(401).send('Invalid signature'); return; } const event = JSON.parse(rawBody); if (event.type === 'intent.approved') { await executePayment(event.data.intentId); }
Error handling
The SDK throws typed errors. Wrap calls in try/catch and check the error type to handle specific scenarios.
import { AegisClient, AegisError, AegisTimeoutError } from '@aegis-os/sdk'; try { const intent = await aegis.intents.submit({ /* ... */ }); } catch (err) { if (err instanceof AegisTimeoutError) { // Policy engine did not respond in time — safe to retry } else if (err instanceof AegisError) { console.error(err.statusCode, err.message, err.code); } else { throw err; } }
TypeScript types
All request and response shapes are fully typed. Import types directly for use in your own interfaces.
import type { SubmitIntentInput, IntentResponse, IntentStatus, // 'pending' | 'approved' | 'denied' | 'pending_approval' PolicyDecision, // 'allow' | 'deny' | 'require_approval' WebhookEvent, } from '@aegis-os/sdk';
All methods
intents.submit(input)
Submit a new spend intent for policy evaluation.
intents.get(id)
Retrieve the current state of an intent by ID.
intents.list(filters)
List intents with optional status / agent / date filters.
intents.waitForDecision(id, opts)
Poll until the intent reaches a terminal status.
approvals.list()
List pending approval requests for the current user.
approvals.respond(id, decision)
Approve or reject a pending intent.
agents.list()
List all registered agents in the organisation.
agents.get(id)
Get agent details, risk level, and wallet balance.
AegisClient.verifyWebhookSignature(opts)
Static method — verify an inbound webhook payload signature.