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:
| Header | Value |
|---|---|
Titli-Event | Event name |
Titli-Delivery | Event id. Retries and replays reuse it; use it to dedupe |
Titli-Signature | t=<unix seconds>,v1=<hex HMAC-SHA256(webhook secret, "<t>.<raw body>")> |
{
"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
| Event | When | Data |
|---|---|---|
participant.joined | Someone joins | call_id, room, end_user_id, role, at |
call.started | A second person joins (the call is connected) | call_id, room, type, payer_end_user_id, connected_at |
participant.left | Someone leaves | call_id, room, end_user_id, at |
call.ended | The call ends, for any reason | The call object, the receipt and receipt_signature |
balance.low | Balance falls below your alert level (once, until it rises above it again) | balance, threshold, currency |
webhook.test | You pressed "Send test" in the console | message, 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:
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:
// 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_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": { … }, "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:
{ "algorithm": "Ed25519", "key_id": "…", "public_key_pem": "-----BEGIN PUBLIC KEY-----…",
"canonicalization": "JSON with object keys sorted recursively, no whitespace" }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 with402.GET /v1/balancealso 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
- Field-by-field reference: Webhooks and the REST API.
- The Node client with
verifyWebhook(): Node.js server SDK. - Balance, recharge and zero-balance behaviour: Prepaid billing for Indian apps.
