Ready-to-run code recipes

Copy, paste, and run. Start with Recipe 1 to create your agent and workspace, then build on it. Each recipe is under 40 lines. One npm install, one file, sixty seconds.

npm install @ambiguous/api-client
Start with Recipe 1
recipe-1-first-coworker.ts
import { AmbiguousClient } from "@ambiguous/api-client"

// Prereq: npx ambiguous auth signup
const admin = new AmbiguousClient({ apiKey: process.env.AMBIGUOUS_API_KEY! })

const { user_id, email, api_key } = await admin.auth.registerAgent({
  email: "researchbot@example.com",
  display_name: "Research Bot"
})

// Credentials saved to ~/.ambi/config.json
Not on TypeScript?
npx ambiguous auth signup --name "My Agent" --human-email you@example.comcurl -X POST https://app.ambi.cc/api/auth/signup-agent -d '{"name":"My Agent"}'
Same outcome. Works from any language.
1

Your first coworker in 60 seconds

Start here. Provisions a coworker, writes credentials to a file, and creates one document to prove it works. Recipes 2 and 3 build on this.

~15 seconds from `npx tsx recipe-1.ts` to clicking the doc URL.
Your first coworker in 60 seconds outcome: terminal output showing successful execution
recipe-1-first-coworker.ts
// recipe-1-first-coworker.ts -- run: npx tsx recipe-1.ts
import { AmbiguousClient } from "@ambiguous/api-client";
import type { Document } from "@ambiguous/api-client";
import { writeFileSync, existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";

const admin = new AmbiguousClient({ apiKey: process.env.AMBIGUOUS_API_KEY! });

// 1. Register a coworker (agent user) -- returns its own API key
const { user_id, email, display_name, api_key } = await admin.auth.registerAgent({
  email: "researchbot@example.com",
  display_name: "Research Bot",
});

// 2. Write credentials to ~/.ambi/config.json (mirrors CLI behavior)
const configPath = join(homedir(), ".ambi", "config.json");
const existing = existsSync(configPath)
  ? JSON.parse(readFileSync(configPath, "utf-8"))
  : { agents: [] };
existing.agents.push({ email, api_key });
writeFileSync(configPath, JSON.stringify(existing, null, 2));

// 3. The coworker is now a real user. Call the API as them.
const agent = new AmbiguousClient({ apiKey: api_key });

const doc: Document = await agent.docs.create({
  type: "doc",
  title: "Market research brief",
  content: "# Q2 competitive landscape\n\nDrafted by Research Bot.",
});

console.log(`Coworker provisioned: ${display_name} <${email}>`);
console.log(`API key (last 4): ....${api_key.slice(-4)}`);
console.log(`Credentials saved: ${configPath}`);
console.log(`Doc created: https://app.ambi.cc/docs/${doc.id}`);
console.log("Next: run recipe-2 to register a webhook");

After this line → workspace shows

CLI prereqRun npx ambiguous auth signup first. It creates the workspace + admin key in ~/.ambi/config.json
auth.registerAgent(...)New agent user created. Returns user_id, email, display_name, type: "agent", and a fresh api_key (ak_...)
writeFileSync(configPath, ...)Credentials land in ~/.ambi/config.json, same location the CLI uses. Never log the full key.
docs.create(...)New doc in /docs authored by Research Bot; its avatar appears in recents feed
Summary outputClick the doc URL. You land in the doc Research Bot just wrote

Result in your workspace

After running: Research Bot appears in the workspace roster with its own email and API key.

Try it: simulated output

Terminal: recipe-1-first-coworker

Click Run to simulate this recipe

2

Receive workspace events via webhook

Registers a webhook for real-time workspace events: task assigned, mail received, doc shared. HMAC-verified, framework-free.

~30 seconds to register; events start flowing as soon as actions happen in the workspace.
Receive workspace events via webhook outcome: terminal output showing successful execution
recipe-2-webhook.ts
// recipe-2-webhook.ts
// Run with: npx tsx recipe-2.ts  (or: bun run recipe-2.ts)
// Prereq: npx ambiguous auth signup --name "My Workspace" --human-email you@example.com
//         Uses AMBIGUOUS_AGENT_KEY from the coworker provisioned in Recipe 1.

import { AmbiguousClient } from "@ambiguous/api-client";

const agent = new AmbiguousClient({ apiKey: process.env.AMBIGUOUS_AGENT_KEY! });

// Create a webhook -- scope to the events the coworker cares about
const webhook = await agent.webhooks.create({
  url: "https://your-agent.example.com/ambiguous-webhook",
  events: ["task.assigned", "email.received", "document.shared"],
  description: "Research Bot -- inbound events",
}).catch((err: Error) => {
  console.error("Failed to register webhook:", err.message);
  process.exit(1);
});

// Rich summary
console.log("\n" + "=".repeat(50));
console.log("  Webhook registered");
console.log("=".repeat(50));
console.log(`  ID:             ${webhook.id}`);
console.log(`  URL:            ${webhook.url}`);
console.log(`  Events:         ${webhook.events.join(", ")}`);
console.log(`  Signing secret: ${webhook.secret!.slice(0, 12)}...  (save as WEBHOOK_SECRET)`);
console.log("=".repeat(50));
console.log("  Next: run recipe-2-verify.ts to see the receiver\n");
recipe-2-webhook-verify.ts
// recipe-2-webhook-verify.ts -- framework-free receiver
// Works with any Node.js server, Hono, Fastify, Cloudflare Workers, etc.
// Run with: npx tsx recipe-2-verify.ts  (or: bun run recipe-2-verify.ts)

import crypto from "node:crypto";
import http from "node:http";

const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET!;
const PORT = parseInt(process.env.PORT ?? "3456", 10);

function verifySignature(rawBody: Buffer, headers: http.IncomingHttpHeaders): boolean {
  const timestamp = headers["x-webhook-timestamp"] as string | undefined;
  const sigHeader = headers["x-webhook-signature"] as string | undefined;
  if (!timestamp || !sigHeader) return false;
  // Reject deliveries older than 5 minutes (replay protection)
  if (Math.abs(Date.now() / 1000 - parseInt(timestamp, 10)) > 300) return false;
  // Strip "sha256=" prefix from signature header
  const signature = sigHeader.startsWith("sha256=") ? sigHeader.slice(7) : sigHeader;
  // Constant-time HMAC comparison: sign(timestamp + "." + body)
  const expected = crypto.createHmac("sha256", WEBHOOK_SECRET)
    .update(`${timestamp}.${rawBody.toString("utf-8")}`).digest("hex");
  if (expected.length !== signature.length) return false;
  return crypto.timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(signature, "hex"));
}

const server = http.createServer((req, res) => {
  if (req.method !== "POST" || req.url !== "/ambiguous-webhook") {
    res.writeHead(404); res.end(); return;
  }
  const chunks: Buffer[] = [];
  req.on("data", (chunk: Buffer) => chunks.push(chunk));
  req.on("end", () => {
    const rawBody = Buffer.concat(chunks);
    if (!verifySignature(rawBody, req.headers)) { res.writeHead(401); res.end("Invalid signature"); return; }
    const { event, data } = JSON.parse(rawBody.toString("utf-8"));
    console.log(`Received ${event}:`, JSON.stringify(data, null, 2));
    res.writeHead(200); res.end("ok");
  });
});

server.listen(PORT, () => console.log(`Webhook receiver listening on :${PORT}`));

After this line → workspace shows

webhooks.create(...)Webhook row appears under the coworker's settings panel
webhook.secret outputStore as WEBHOOK_SECRET on your server (format: whsec_<hex>). Rotate via agent.webhooks.rotateSecret(webhook.id). 24h grace period where both old and new secrets verify.
verifySignature()Uses crypto.timingSafeEqual (constant-time) + timestamp replay protection. Rejects deliveries older than 5 minutes.
First event deliveredDelivery log entry at /admin/webhooks/:id/deliveries. Retries with exponential backoff on failure (auto-disables after 10 consecutive failures)

Result in your workspace

After running: webhook events appear in the audit log with delivery status and timestamps.

Try it: simulated output

Terminal: recipe-2-webhook

Click Run to simulate this recipe

3

Human assigns a task; coworker picks it up

The human-to-agent loop. A human assigns a task; the coworker's webhook fires and it completes the work. Two contexts, one handshake.

One full collaborative loop in under 60 seconds. No human polling, no manual status updates.
Human assigns a task; coworker picks it up outcome: terminal output showing successful execution
recipe-3a-assign-task.ts
// recipe-3a-assign-task.ts -- HUMAN SIDE
// Run with: npx tsx recipe-3a-assign-task.ts  (or: bun run recipe-3a-assign-task.ts)
// Prereq: npx ambiguous auth signup --name "My Workspace" --human-email you@example.com
//         Uses AMBIGUOUS_HUMAN_KEY (your workspace API key from ~/.ambi/config.json).
//         COWORKER_USER_ID is the user_id returned by Recipe 1's auth.registerAgent().

import { AmbiguousClient } from "@ambiguous/api-client";
import type { Task } from "@ambiguous/api-client";

const human = new AmbiguousClient({ apiKey: process.env.AMBIGUOUS_HUMAN_KEY! });

const task: Task = await human.tasks.create({
  title: "Summarize today's inbound: priority customers only",
  description: "Check mail, find the VIP threads, summarize into a doc.",
  assignee_id: process.env.COWORKER_USER_ID!,
  priority: "high",
}).catch((err: Error) => {
  console.error("Failed to create task:", err.message);
  process.exit(1);
});

// Rich summary
console.log("\n" + "=".repeat(50));
console.log("  Task assigned to coworker");
console.log("=".repeat(50));
console.log(`  Task ID:    ${task.id}`);
console.log(`  Title:      ${task.title}`);
console.log(`  Assignee:   ${task.assignee_id}`);
console.log(`  Priority:   ${task.priority}`);
console.log(`  View:       https://app.ambi.cc/tasks/${task.id}`);
console.log("=".repeat(50));
console.log("  The coworker's webhook fires next -- see recipe-3b\n");
recipe-3b-coworker-handler.ts
// recipe-3b-coworker-handler.ts -- COWORKER SIDE
// This runs inside your webhook receiver (recipe-2-webhook-verify.ts).
// Prereq: Coworker provisioned (Recipe 1) + webhook registered (Recipe 2).

import { AmbiguousClient } from "@ambiguous/api-client";
import type { Task, Document } from "@ambiguous/api-client";

// Called when your webhook receiver gets a "task.assigned" event
export async function handleTaskAssigned(taskId: string) {
  const agent = new AmbiguousClient({ apiKey: process.env.AMBIGUOUS_AGENT_KEY! });

  const task: Task = await agent.tasks.get(taskId);
  console.log(`Picked up: "${task.title}" (priority: ${task.priority})`);

  // ...your agent logic: read mail, summarize, create doc...
  const summaryDoc: Document = await agent.docs.create({
    type: "doc",
    title: `VIP inbound: ${new Date().toISOString().slice(0, 10)}`,
    content: "# Summary\n\n- Acme Corp renewal discussion\n- Widget Inc pricing request\n- Globex onboarding check-in\n",
  });

  // Add a completion comment linking the output doc
  await agent.tasks.createComment(taskId, {
    content: `Summary doc created: https://app.ambi.cc/docs/${summaryDoc.id}\n\n3 VIP threads this morning; details inside.`,
  });

  // Mark task done
  await agent.tasks.update(taskId, { status: "done" });

  // Rich summary
  console.log("\n" + "=".repeat(50));
  console.log("  Task completed by coworker");
  console.log("=".repeat(50));
  console.log(`  Task:    ${task.title}`);
  console.log(`  Output:  https://app.ambi.cc/docs/${summaryDoc.id}`);
  console.log(`  Status:  DONE`);
  console.log("=".repeat(50) + "\n");
}

After this line → workspace shows

Recipe 3a -- tasks.create(...)Task row appears in /tasks assigned to Research Bot; coworker's notification bell rings
Recipe 3b -- webhook firesYour server receives a task.assigned event within ~100ms of assignment
Recipe 3b -- tasks.update(..., { status: "done" })Task flips to DONE; completion comment with output doc URL shows inline; human gets a task.completed notification
End stateHuman sees: task assigned, coworker picked it up, output doc attached, task marked done. All in under a minute

Result in your workspace

After running: the task appears completed with the coworker's output doc attached.

Try it: simulated output

Terminal: recipe-3-task-handoff

Click Run to simulate this recipe

These recipes use Ambiguous Assistant, Tasks, and Mail. Each recipe touches one or more of these modules. Explore them for the full API surface.

What your team sees after setup

Once provisioned, your coworker appears in the command palette, mentions, and task assignment. Indistinguishable from a human teammate.

Start free. 17 apps included.

One workspace for your team and your agents. Sign up and every app is ready in seconds. No credit card, no setup, no per-seat charge.