Reference
Riskbound SDK (TypeScript)
The TypeScript SDK. It asks Riskbound before an AI agent acts, then carries out the answer. It has no dependencies and is not published yet.
import { createRiskbound, RiskboundBlockedError } from "@riskbound/sdk";
const riskbound = createRiskbound({
apiKey: process.env.RISKBOUND_API_KEY!,
baseUrl: "http://localhost:8200",
});
const refund = riskbound.guard("refund", { agent: "support-bot" });
try {
const result = await refund(
{ order_id: "ord_2291", amount_minor: 48000, currency: "USD" },
() => payments.refund("ord_2291", 48000),
);
// result.outcome is "allow" or "ask_human"; result.value is what the action returned.
} catch (err) {
if (err instanceof RiskboundBlockedError) {
// err.reasons says why: a policy id, "spend_cap", "kill_switch", ...
}
}What happens for each outcome#
| Outcome | What the SDK does |
|---|---|
allow | Runs the action and reports the result |
ask_human | Waits for a person. Runs on approval; throws on rejection or expiry |
dry_run | Runs the dryRun handler you passed, never the real action |
block | Throws RiskboundBlockedError. The action does not run |
When Riskbound cannot be reached#
By default the guard fails closed: it throws RiskboundUnavailableError and the
action does not run. Pass failMode: "open" to a guard to run the action
unchecked instead. A rejected request, such as a bad key, is never treated as
unavailable.
Reporting the result#
After the action runs, the SDK tells Riskbound whether it worked. By default the
guard waits for that report before it returns. Pass reportResult: "background" to createRiskbound to return as soon as the action does and send
the report after. This saves one round trip for a caller that is waiting. A
failed report goes to onError in both modes and never changes the result.
In background mode, keep the process alive long enough for the report to go
out.
How requests are labelled#
Every decision request carries via: "sdk". The risk score counts how much
of an agent's traffic comes through the gateway, which the agent cannot go
around (../docs/adr/0010-risk-score.md). The gateway sets via: "gateway"
itself. Agent code leaves via unset. Riskbound believes "gateway" only
from a gateway key. From any other key the request is blocked with the
reason via_not_trusted (../docs/adr/0012-gateway-keys.md).
Amounts#
Send amounts as whole numbers in minor units (amount_minor: 48000 for
$480.00). Fractions are rejected.
Develop#
npm install
npm run lint && npm run typecheck && npm test && npm run buildTry it against a local backend:
RISKBOUND_API_KEY=<agent key from db:seed:dev> npx ts-node examples/refund.ts