camelAI Documentation

Channels and voice

camelRun v2 webhooks: run, input, dreaming, voice, and usage events

Register webhook endpoints at /v2/webhooks, verify HMAC-SHA256 X-CamelRun-Signature headers, and handle run, input, voice, and usage events.

View as Markdown

camelRun v2 delivers signed JSON webhooks asynchronously via a Cloudflare Queue whenever agent runs complete, fail, pause for human input, finish dreaming, or emit voice call and usage events.

Manage webhook endpoints (/v2/webhooks)

All webhook management endpoints require a tenant API key (cr_live_...).

ts
const hook = await client.webhooks.create({
  url: "https://app.example.com/webhooks/camelrun",
  events: ["run.completed", "run.failed", "run.input_required", "usage.recorded"],
  secret: process.env.CAMELRUN_WEBHOOK_SECRET, // optional: generated if omitted
});

const allHooks = await client.webhooks.list();
await client.webhooks.delete(hook.id);

Over REST

bash
# Register a webhook (omit events or pass ["*"] to subscribe to all events)
curl -s -X POST "https://run.camelai.com/v2/webhooks" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://app.example.com/webhooks/camelrun",
    "events": ["run.completed", "run.failed", "run.input_required"]
  }'

# List webhooks
curl -s "https://run.camelai.com/v2/webhooks" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

# Delete a webhook
curl -s -X DELETE "https://run.camelai.com/v2/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $CAMELRUN_API_KEY"

Event types

Event typeTrigger
run.completedAn agent run finished (status: "completed")
run.failedAn agent run failed (status: "failed", includes error)
run.cancelledAn agent run was aborted or cancelled
run.input_requiredA run paused waiting for human approval, question, or MCP elicitation
agent.dream_completedA memory consolidation pass finished writing /workspace/MEMORY.md
voice.session.startedA managed voice call started
voice.utteranceA voice call recorded a speaker utterance
voice.agent.repliedA voice call agent tool call completed
voice.session.endedA managed voice call ended
usage.recordedUsage was recorded for a metered voice call or model call

Payload envelope and headers

Every delivery is an HTTP POST with Content-Type: application/json and four headers:

HeaderValue
X-CamelRun-Signaturet=<unixSeconds>,v1=<hmacSha256Hex>
X-CamelRun-EventEvent type (for example run.completed)
X-CamelRun-DeliveryUnique event ID (evt_...)
X-CamelRun-TimestampUnix timestamp in seconds (matches t in signature)

JSON payload shape:

json
{
  "id": "evt_...",
  "type": "run.completed",
  "tenantId": "tnt_...",
  "createdAt": 1763760000000,
  "data": {
    "agentId": "agt_...",
    "agentKey": "support-42",
    "runId": "run_...",
    "text": "...",
    "output": null,
    "usage": { "inputTokens": 412, "outputTokens": 98, "costUsd": 0.001804, "vmMs": 0 },
    "filesChanged": []
  }
}

Verify webhook signatures

The signature is computed as HMAC-SHA256(secret, "${timestamp}.${rawBody}"). Always verify it using the exact raw request body and constant-time comparison before parsing JSON:

ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyCamelRunWebhook(
  rawBody: string,
  signatureHeader: string | null,
  secret: string,
  maxAgeSeconds = 300,
): boolean {
  if (!signatureHeader) return false;
  const parts = Object.fromEntries(
    signatureHeader.split(",").map((part) => {
      const idx = part.indexOf("=");
      return [part.slice(0, idx).trim(), part.slice(idx + 1).trim()];
    }),
  );
  const ts = Number(parts.t);
  const sig = parts.v1;
  if (!Number.isFinite(ts) || !sig) return false;
  if (Math.abs(Math.floor(Date.now() / 1000) - ts) > maxAgeSeconds) return false;

  const expected = createHmac("sha256", secret)
    .update(`${ts}.${rawBody}`)
    .digest("hex");

  const a = Buffer.from(sig, "hex");
  const b = Buffer.from(expected, "hex");
  return a.length === b.length && timingSafeEqual(a, b);
}

Deliveries that return HTTP 5xx (or fail at the network layer) are retried by the Cloudflare Queue consumer (up to 3 retries by default). Return any 2xx response quickly and process heavy work asynchronously, deduplicating on id (X-CamelRun-Delivery).