Webhooks and signed receipts for call billing

Webhooks tell your backend what happened on every call as it happens. Signed receipts are the durable record of what was connected, free and billed. Together they let you charge your own users correctly and settle disputes with evidence. Both are optional: calls work with the App Key alone.

Optional, and it needs a server. Your app can make calls with only the App Key, no backend (Quick mode). Webhooks are deliveries to an HTTPS endpoint you run, and receipts are read with the project key, so both need a server of your own. Add them when you want a durable record per call, or when your app charges its users per minute: wallet debits belong on a server you trust, not in the app. Without a server, you still see every call and its cost in the console.

Two tools, two jobs

A webhook is a signed HTTPS POST we send to your server when something happens: someone joins, the call connects, the call ends, your balance runs low. A receipt is a JSON record of an ended call, signed with Ed25519, that anyone can verify with our public key. The call.ended webhook carries the receipt, so one handler gives you both. References: Webhooks and Billing and usage.

Set up the endpoint

Set an HTTPS URL on a project in the console. Each project has its own webhook secret (whsec_…); keep it on your server. Every delivery is a POST with three headers:

HeaderValue
Titli-EventEvent name
Titli-DeliveryEvent id. Retries and replays reuse it; use it to dedupe
Titli-Signaturet=<unix seconds>,v1=<hex HMAC-SHA256(webhook secret, "<t>.<raw body>")>
POST https://yourapp.in/hooks/titli
{
  "id": "<event id>",
  "event": "call.ended",
  "created_at": "2026-11-25T10:42:00.000Z",
  "data": {
    "call": { "id": "6a1f…", "type": "video", "status": "ended", "end_reason": "completed",
              "connected_seconds": 300, "billed_minutes": 8.0, "amount": 1.6 },
    "receipt": { "call_id": "6a1f…", "end_reason": "completed", "…": "…" },
    "receipt_signature": "base64…"
  }
}

Events and their data

EventWhenData
participant.joinedSomeone joinscall_id, room, end_user_id, role, at
call.startedA second person joins (the call is connected)call_id, room, type, payer_end_user_id, connected_at
participant.leftSomeone leavescall_id, room, end_user_id, at
call.endedThe call ends, for any reasonThe call object, the receipt and receipt_signature
balance.lowBalance falls below your alert level (once, until it rises above it again)balance, threshold, currency
webhook.testYou pressed "Send test" in the consolemessage, project_id, app_id

balance.low goes to every active project of the account. Billing starts at call.started, because only connected time is billed. The end_reason on the ended call is one of completed, ended_by_vendor, insufficient_balance, max_duration, room_closed, vendor_suspended, killed_by_operator, ended_by_operator, project_cap (the project's daily spending cap was reached), room_create_failed or expired_unused (nobody joined within an hour).

If you use the Live Hosts API, two more events arrive at the same URL with the same signature: live_host.call.connected and live_host.call.ended.

Verify the signature

Compute the HMAC over the raw request body, before JSON parsing, and reject deliveries whose timestamp is more than 5 minutes old:

verify.js
import crypto from 'node:crypto';
function verify(rawBody, header, secret) {
  const p = Object.fromEntries(header.split(',').map((kv) => kv.split('=')));
  if (Math.abs(Date.now() / 1000 - Number(p.t)) > 300) return false;
  const exp = crypto.createHmac('sha256', secret).update(`${p.t}.${rawBody}`).digest('hex');
  return exp.length === p.v1.length && crypto.timingSafeEqual(Buffer.from(exp), Buffer.from(p.v1));
}

If your framework parses JSON for you, configure it to keep the raw body for this route. Re-serialising the parsed object will not produce the same bytes.

A complete receiver

The Node server client ships the same check as verifyWebhook(). This receiver verifies, answers at once, dedupes and then does its work:

webhook-server.js
// Minimal receiver (Node 20+, no dependencies). Verifies on the RAW body, answers fast, dedupes.
import http from 'node:http';
import { verifyWebhook } from 'titli-video-sdk/server'; // npm i titli-video-sdk

const secret = process.env.TITLI_WEBHOOK_SECRET; // whsec_…
const seen = new Set(); // retries and replays reuse the same event id

http.createServer((req, res) => {
  const chunks = [];
  req.on('data', (c) => chunks.push(c));
  req.on('end', () => {
    const raw = Buffer.concat(chunks).toString('utf8');
    if (!verifyWebhook(raw, req.headers['titli-signature'], secret)) { res.writeHead(401).end(); return; }
    const ev = JSON.parse(raw);
    res.writeHead(200).end('ok'); // answer fast; do slow work after
    if (seen.has(ev.id)) return;
    seen.add(ev.id);
    switch (ev.event) {
      case 'call.started':
        console.log('call connected', ev.data.call_id, 'payer', ev.data.payer_end_user_id);
        break;
      case 'call.ended':
        console.log('call ended', ev.data.call.id, ev.data.call.end_reason, 'INR', ev.data.call.amount);
        break;
      case 'balance.low':
        console.log('balance low:', ev.data.balance, 'threshold', ev.data.threshold);
        break;
    }
  });
}).listen(8080);

In production, keep the seen ids in your database rather than in memory, so a restart does not process an event twice.

Retries and replay

Answer with any 2xx within 8 seconds. Failed deliveries are retried after 10 seconds, 1 minute, 5 minutes and 30 minutes (5 attempts in all). Every attempt is logged in the console, where an event that was not delivered can be sent again, up to 5 times a day. Because retries and replays reuse the event id, a handler that dedupes on it is safe to call more than once.

Signed receipts

Every ended call has a receipt. It shows exactly which seconds were connected, free and billed, per participant:

receipt
{
  "receipt_version": 1, "key_id": "…", "call_id": "…", "app_id": "app_…", "room": "tvs_…",
  "type": "video", "billing_mode": "participant_minute", "rate_per_minute": 0.2, "currency": "INR",
  "payer_end_user_id": "user_1001",
  "created_at": "…", "started_at": "…", "connected_at": "…", "ended_at": "…", "end_reason": "completed",
  "connected_seconds": 300, "participant_seconds": 600, "free_seconds": 60,
  "billed_minutes": 8.0, "amount": 1.6,
  "participants": [ { "end_user_id": "user_1001", "role": "user", "joined_at": "…", "left_at": "…",
                      "billable_seconds": 300, "free_seconds": 60, "amount": 0.8 } ]
}

In this example two people were connected for 300 seconds (600 participant-seconds). The payer's 60 free seconds covered both participants, so 480 participant-seconds, or 8 participant-minutes, were billed: 8 × ₹0.20 = ₹1.60. The arithmetic is explained in Per-minute pricing explained.

You get the receipt in the call.ended webhook, or on demand from GET /v1/calls/{call_id}/receipt, which answers 409 call_not_ended until the call has ended:

Receipt reply
{ "receipt": { … }, "signature": "base64…", "algorithm": "Ed25519", "key_id": "…" }

Verify a receipt

The signature is Ed25519 over the canonical JSON of the receipt: object keys sorted recursively, no whitespace. Fetch the public key once from GET /v1/receipts/public-key (no auth) and cache it:

Public key reply
{ "algorithm": "Ed25519", "key_id": "…", "public_key_pem": "-----BEGIN PUBLIC KEY-----…",
  "canonicalization": "JSON with object keys sorted recursively, no whitespace" }
verify-receipt.js
import crypto from 'node:crypto';
const canonical = (v) => Array.isArray(v) ? '[' + v.map(canonical).join(',') + ']'
  : v && typeof v === 'object' ? '{' + Object.keys(v).sort().map((k) => JSON.stringify(k) + ':' + canonical(v[k])).join(',') + '}'
  : JSON.stringify(v);
const ok = crypto.verify(null, Buffer.from(canonical(receipt)), crypto.createPublicKey(publicKeyPem), Buffer.from(signature, 'base64'));

POST /v1/receipts/verify (no auth) is a convenience check: send the receipt and its signature and it answers with valid true or false. Verify locally in production. The Node client also exports verifyReceipt().

Using them for your own billing

  • Charge your users from call.ended. We meter minutes and bill your prepaid balance; your coins, wallets and host payouts stay in your own system. The ended call's seconds and amount are the numbers to settle against.
  • Store the receipt and its signature with your own call record. When a user disputes a charge, the receipt shows the connected seconds, and anyone can verify that it was not edited.
  • Act on balance.low. Recharge before calls start failing with 402. GET /v1/balance also returns the balance, the threshold and how many 1:1 minutes it covers.
  • Do not trust the app for durations. Minutes come from the media server, not from anything a client reports.

Next steps

Free SDK. Pay only for the minutes you use.

Create a free account: it starts with ₹100 welcome credit, about 250 minutes of 1:1 video, so your first call needs no recharge. Questions? Message us on WhatsApp and a person replies.

Start free