Getting started
Quickstart
Install the client, create a key, and run your first governed agent — start to finish in under a minute.
1 · Install#
bash
npm install @bahini/sdk2 · Create an API key#
In the console, open Settings → API keys and create a key (format bah_…). Give it a read-only or write scope per what the integration needs. Store it as an environment variable — treat it like a password.
bash
export BAHINI_API_KEY=bah_your_key_here3 · Construct the client#
ts
import { BahiniClient } from "@bahini/sdk";
const bahini = new BahiniClient({
apiKey: process.env.BAHINI_API_KEY!,
// Self-hosted? Point at your own deploy:
// baseUrl: "https://bahini.your-company.com",
});4 · Run an agent and wait#
The one-call path: kick off a single agent and block until it reaches a terminal (or approval-gated) state.
ts
const done = await bahini.runAgentAndWait("agent_123", {
prompt: "Summarize last month's sales by division.",
});
console.log(done.run.status); // "COMPLETED"
console.log(done.run.output); // the agent's answer
for (const step of done.steps) {
console.log(step.agentName, step.status);
}Structured output. If the agent is configured for JSON mode, parse the result with
parseRunOutput<T>(done) — it returns the typed object or nullif the output isn't valid JSON.5 · Fire-and-poll (long runs)#
For long swarms, kick off with an idempotency key (safe to retry — the server dedupes so you never double-fire), then poll on your own cadence.
ts
const { runId } = await bahini.runPreset("preset_monthly_review", {
prompt: "Prepare the June board deck from the latest sales data.",
idempotencyKey: "june-2026-board",
});
const detail = await bahini.waitForRun(runId, {
intervalMs: 3000,
timeoutMs: 600_000,
onPoll: (d) => console.log(d.run.status),
});waitForRun stops on a terminal status or WAITING_FOR_APPROVAL — so an approval-gated run wakes you to act instead of timing out. Check detail.run.status to tell them apart.