Skip to content
Menu · Webhooks

API reference

Webhooks

Composa tells your server when a document or a batch is done. Events, payloads, signatures, delivery and retries.

A webhook tells your server what happened in your Team: a batch finished, a document printed, a template was approved. Composa sends a signed POST with a JSON body to an https address of yours.

Add an endpoint

An Admin adds endpoints on the Webhooks page of the app. Each endpoint has:

  • an https address, on a public host and port 443;
  • the events it is told;
  • all the Team's templates, or chosen ones.

Its signing secret (whsec_…) is shown once, when the endpoint is made. Keep it in your server's configuration, for example in COMPOSA_WEBHOOK_SECRET. Each endpoint's page has Send test event and Replay.

Events

TypeWhen
batch.completedA batch finished: every item is done.
batch.failedA batch was refused or stopped before its end.
batch.pausedA batch paused because the Team ran out of pages.
batch.expiredA paused batch waited 72 hours in all and gave up.
batch.canceledA batch was canceled and has stopped.
run.completedOne document was printed. Off unless you choose it.
run.failedOne document was refused or failed. Off unless you choose it.
approval.changedA template was sent for approval, approved, sent back or withdrawn.

A batch sends one event, never one per item, whatever its size.

Payload

Every event has the same envelope:

json
{  "id": "evt_6f1c0a9e2b7d4c3fa1e85b0d9c2f4a17",  "type": "batch.completed",  "created_at": "2026-11-08T12:00:01.204Z",  "test": false,  "data": {    "batch_id": "bat_zd3s7udbz7c41e9a0b2",    "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38",    "source": "api",    "status": 200,    "items": 10000,    "success_count": 9998,    "error_count": 2,    "refused_count": 0,    "credits": 0,    "duration_ms": 412000,    "status_url": "https://api.composa.ai/v1/run/batches/bat_zd3s7udbz7c41e9a0b2"  }}

test is true for an event sent with Send test event. Read the batch's files at status_url.

A run.completed event carries the document's link, never the file:

json
{  "id": "evt_0a5b…",  "type": "run.completed",  "created_at": "2026-11-08T12:00:01.204Z",  "test": false,  "data": {    "template_id": "85416813-8d99-46e8-be2b-1d61cee5db38",    "source": "api",    "status": 200,    "pages": 1,    "credits": 0,    "duration_ms": 812,    "format": "pdf",    "url": "https://…/document.pdf",    "url_expires_in": 3600  }}

url is null when the call asked for the file itself rather than a link. That is not a failure. A run.failed or batch.failed event adds error, the sentence the caller got. source is api, playground or mcp.

A batch.paused event adds reason, done_count, resets_at, expires_at and top_up_url. An approval.changed event has template_id, template_name, request_id, status (waiting, approved, changes_requested or withdrawn), version, note and by. No event ever carries a document, the data a caller sent, or a key.

Verify the signature

Each request carries three headers:

HeaderValue
Composa-Event-IdThe event's id.
Composa-Event-TypeThe event's type.
Composa-Signaturet=<unix seconds>,v1=<hex>

The v1 value is an HMAC-SHA256 of <t>.<raw body>, keyed with the signing secret. Check it on the raw body, before you parse the JSON, and refuse a t more than five minutes old. For 24 hours after a secret is rotated, the header carries two v1= values, the new secret's first: accept the event when any one matches.

The SDKs do all of this:

import express from 'express';import { Composa, WebhookVerificationError } from '@composa-labs/node';​const composa = new Composa();const app = express();​// express.raw keeps the body as bytes: register it before any express.json().app.post('/webhooks/composa', express.raw({ type: 'application/json' }), async (req, res) => {  try {    const event = await composa.webhooks.verify({      payload: req.body,      signature: req.get('composa-signature'),    });    if (event.type === 'batch.completed') console.log(event.data.batchId, event.data.statusUrl);    res.sendStatus(204);  } catch (error) {    if (error instanceof WebhookVerificationError) return res.sendStatus(400);    throw error;  }});

Without an SDK, in Node.js:

js
import { createHmac, timingSafeEqual } from 'node:crypto';​export function verifyComposa(rawBody, header, secret = process.env.COMPOSA_WEBHOOK_SECRET) {  const parts = header.split(',').map((p) => p.trim().split('=', 2));  const t = Number(parts.find(([k]) => k === 't')?.[1]);  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) return false;  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();  return parts.some(([k, v]) => {    if (k !== 'v1') return false;    const given = Buffer.from(v ?? '', 'hex');    return given.length === expected.length && timingSafeEqual(given, expected);  });}

Delivery and retries

  • Answer with any 2xx status within 5 seconds.
  • Anything else is tried again: three attempts in all, at once, after 2 seconds, then after 8 seconds more. Redirects are not followed.
  • Every attempt carries the same id. Use it to drop duplicates.
  • Events are sent after the API has answered its caller, and are not ordered.
  • Each endpoint's page lists every attempt and the status your server answered. Replay sends an event again, with the same id, for 7 days.