Skip to content

TypeScript SDK ​

@aithorized/sdk puts the approval lifecycle around any function: local policy, the request, the wait, the verification of the signed decision, and the execution report. Node 20 or later.

bash
npm install @aithorized/sdk   # once published (private beta)

Create a client ​

ts
import { Aithorized } from '@aithorized/sdk';

const az = new Aithorized({
  agentKey: process.env.AITHORIZED_AGENT_KEY!,
  agentId: process.env.AITHORIZED_AGENT_ID!,
  tenantId: process.env.AITHORIZED_TENANT_ID!,
  pinnedPolicyKey: JSON.parse(process.env.AITHORIZED_POLICY_KEY!),
  environment: 'prod'
});
Option
agentKey, agentId, tenantIdFrom Agents in the dashboard. Set by your code, never by the model.
pinnedPolicyKey{ keyId, publicKeyJwk }, or a list of them during a key rotation. The policy bundle and the device-key directory must be signed by one of them. Without it, every call needs a CRITICAL approval.
baseUrlDefaults to https://api.aithorized.dev/v1.
localPolicyA policy merged with the signed one; it can only make it stricter.
redactionWhat to hide from the preview the phone shows (the hash still covers the full payload).
environment, sessionIdDefaults for every call: shown on the phone, usable in policies and by the kill switch.
clockSkewAllowanceMsDefaults to 5000.

withApproval ​

Wraps a function so it only runs with arguments a human approved (or edited), when your policy asks for approval:

ts
const refund = az.withApproval(
  {
    action: 'stripe.refund',
    editableFields: [{ path: '/amount', type: 'integer', min: 1, max: 50000, label: 'Amount (cents)' }]
  },
  (args: { charge: string; amount: number }) => stripe.refunds.create(args)
);

await refund({ charge: 'ch_1', amount: 45000 });
  • The function receives the final arguments: the original ones, or the ones the approver edited (only at editableFields, within their limits).
  • It throws (and the function never runs) on a rejection, a timeout, a failed verification or any other refusal. See Errors.
  • After the function runs, the SDK reports success or failure to the audit log. That report never changes the decision.

guard ​

The same check without running anything, for when you call the tool yourself:

ts
const outcome = await az.guard('sql.execute', { query }, {
  reason: llmReason,                  // shown on the phone as untrusted text
  dryRun: async (args) => ({          // what the call would change, if you can tell
    source: 'my-sql-adapter',
    kind: 'sql',
    summary: 'DELETE FROM orders WHERE …',
    impact: { affectedRows: 48210, reversible: false }
  })
});

await db.execute((outcome.finalArgs as { query: string }).query);

outcome.decision is ALLOW, OBSERVE, APPROVED or MODIFIED_APPROVED; finalArgs are the arguments to use; requestId is set when a human was asked; modifiedPaths lists edited fields.

Per-call options: reason, dryRun, editableFields, environment, sessionId, and forcePolicyRefresh (skip the policy cache once).

Shadow Mode ​

Calls matched by an OBSERVE rule run immediately and are queued as observations. The queue sends them in the background and never blocks your agent; call await az.flushObservations() before your process exits.

The policy cache ​

The SDK fetches the signed policy bundle, verifies it against the pinned key, and caches it, refreshing about every minute. A bundle that is missing, stale or does not verify puts the client in degraded mode: every call needs a CRITICAL approval until a good bundle arrives (outcome.degraded is true).

The policy engine, MCP proxy, SDK and hook are MIT-licensed.