Install

npm install @orgs/sdk
# or
pnpm add @orgs/sdk
# or
bun add @orgs/sdk

Quick start

import { Orgs } from "@orgs/sdk";

const orgs = new Orgs({
  apiKey: process.env.ORGS_API_KEY!,
});

// List entities
const entities = await orgs.entities.list();

// Create a proposal
const proposal = await orgs.proposals.create({
  entity: "helios-research",
  kind: {
    type: "spend",
    amountUsd: 12_500,
    recipient: "aws-bedrock",
    description: "Q2 compute reservation",
  },
});

// Vote
await orgs.proposals.vote(proposal.id, {
  choice: "approve",
  reason: "Within Q2 budget",
});

Types

All API types are exported from @orgs/sdk/types:
import type { Entity, Proposal, TreasuryBalance } from "@orgs/sdk/types";

Error handling

import { OrgsError, isInsufficientFunds } from "@orgs/sdk";

try {
  await orgs.treasury.disburse({ ... });
} catch (error) {
  if (isInsufficientFunds(error)) {
    console.error(`Not enough: ${error.requested} > ${error.available}`);
  }
}

Webhooks (Node.js)

import { verifyWebhook } from "@orgs/sdk/webhooks";

app.post("/webhook", async (req, res) => {
  const event = verifyWebhook(
    req.body,
    req.headers["x-orgs-signature"],
    process.env.ORGS_WEBHOOK_SECRET!
  );

  switch (event.type) {
    case "proposal.approved":
      // handle
      break;
  }
  res.status(200).send();
});

Browser use

The SDK works in browsers, but API keys must NEVER be shipped to the browser. Use a server-side proxy and pass a short-lived session token to the browser:
// Browser
const orgs = new Orgs({ sessionToken: "..." });

Framework adapters

Full docs

github.com/l1feai/orgs-sdk-typescript