Skip to documentation
HeyMilo Red University

Get started

Polling and webhooks

Scans run in the background. Red can tell you when one finishes, or you can ask it.

Which to use

Use webhooks in production. Red POSTs a signed event the moment a scan finishes, retries for about a day if your endpoint is down, and keeps a delivery log you can replay from. Nothing on your side has to loop.

Polling is fine to start with, or for a handful of scans. Each poll counts against the rate limit of 120 requests per minute per key, so 25 scans polled every 5 seconds already needs 300.

Polling

GET /v1/scans/{scan_id}

  • Poll every 5 seconds. Scans take several minutes, longer for long recordings.
  • COMPLETED and FAILED are both final. Stop polling on either.
  • With red.v2, some findings can be added shortly after a scan first reads COMPLETED. The webhook is sent only once they are in, so prefer webhooks for red.v2.
  • After a network error or a 5xx, back off exponentially from 5 seconds up to 2 minutes. After a 429, wait for Retry-After seconds.
  • Red gives the analysis engine about 9 hours before it fails the scan with a detection_failed error. Set your own give-up time well before that.
  • A live scan the workspace can't pay for ends FAILED and sends scan.failed. Caught when Red reserves the cost, error is the 402 message: Insufficient balance to run this scan. Upgrade to continue. Estimated cost: …, balance: … or Add a payment method to activate your $6 monthly allowance. Caught after transcription, once the real length is known, it is insufficient_balance: … or payment_method_required: …. Any hold is refunded.
GETPoll until terminal
export RED_API_KEY="<YOUR_API_KEY>"
scan_id="8F3A91C24D7E0B5A6C1D9E2F3B4A5C6D7E8F9A0B1C2D3E4F5A6B7C8D9E0F1A2B"

while true; do
  scan=$(curl -fsS "https://red-api.apps.heymilo.cloud/v1/scans/$scan_id" \
    -H "x-api-key: $RED_API_KEY")
  status=$(printf '%s' "$scan" | jq -r '.status')

  case "$status" in
    COMPLETED)
      printf '%s\n' "$scan" | jq '.result.verdict'
      break
      ;;
    FAILED)
      printf '%s\n' "$scan" | jq -r '"Scan failed: \(.error // "no reason given")"' >&2
      break
      ;;
  esac

  sleep 5
done
Response
{
  "status": "COMPLETED",
  "result": {
    "version": "red.v1",
    "verdict": {
      "risk_level": "high",
      "recommended_action": "review",
      "summary": "Off-screen reading detected during two technical answers.",
      "requires_human_review": true,
      "session_duration_sec": 237.4,
      "flagged_duration_sec": 15.2,
      "flagged_percentage": 6.4,
      "total_findings": 2,
      "risk_breakdown": {
        "high": {
          "count": 2,
          "duration_sec": 15.2,
          "percentage": 6.4
        }
      },
      "category_breakdown": [
        {
          "category": "assistance",
          "findings": 2,
          "duration_sec": 15.2,
          "percentage": 6.4,
          "risk_level": "high"
        }
      ]
    },
    "findings": [
      {
        "category": "assistance",
        "check": "offscreen_reading",
        "risk_level": "high",
        "confidence": 0.92,
        "starts_at_sec": 142.2,
        "ends_at_sec": 151.2,
        "summary": "Gaze held off-screen while the answer cadence matched read speech.",
        "recommended_action": "review",
        "evidence": {}
      }
    ],
    "warnings": []
  }
}

How webhook delivery works

When a scan finishes or fails, Red POSTs a JSON event to every active endpoint subscribed to that event. Add endpoints on the Webhooks page or with the webhook endpoints API.

A scan created with a webhook_url is different: its events go to that URL only, and your saved endpoints are skipped. Those events are signed with the workspace's per-request URL secret, shown on the Webhooks page. They are retried like any other delivery, but never switch anything off and never send failure emails.

Any 2xx response counts as delivered. Respond within 15 seconds: Red gives up on an attempt after 20 seconds in all and retries it. Red doesn't follow redirects, so a 3xx counts as a failure: point the endpoint at its final URL.

Payload

Every event has the same envelope. data carries the scan: result on success, error on failure, as code: message.

  • id stays the same across retries and replays. Store the ids you have handled and skip repeats.
  • delivery_id is new for each delivery, so a replay gets a fresh one.
  • livemode is false for sandbox scans and for test events sent from the console or the test endpoint.
  • Don't rely on arrival order. Use created, in Unix seconds.
scan.completed payload
{
  "id": "evt_5f0c2a9e7b3d4c1e8a6f9b2d0c4e7a13",
  "delivery_id": "del_9a1b2c3d4e5f40718293a4b5c6d7e8f9",
  "type": "scan.completed",
  "livemode": true,
  "created": 1790157600,
  "data": {
    "scan_id": "8F3A91C2…",
    "external_id": "interview-123",
    "status": "COMPLETED",
    "result": { "version": "red.v1", "verdict": {}, "findings": [] },
    "error": null
  }
}

Verifying signatures

Every request carries two equivalent signatures. Check either one. Both are HMAC-SHA256 over the raw request body, so verify the bytes you received before parsing the JSON.

Request headers
POST /webhooks/red HTTP/1.1
Content-Type: application/json
red-signature: t=1790157600,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
webhook-id: evt_5f0c2a9e7b3d4c1e8a6f9b2d0c4e7a13
webhook-timestamp: 1790157600
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
What is signed
# red-signature
v1 = hex(HMAC-SHA256(secret, "{t}.{raw body}"))

# webhook-signature (Standard Webhooks)
v1 = base64(HMAC-SHA256(base64decode(secret without "whsec_"),
                        "{webhook-id}.{webhook-timestamp}.{raw body}"))
  • Reject a request whose timestamp is more than 5 minutes from your clock.
  • Compare signatures in constant time, such as hmac.compare_digest or crypto.timingSafeEqual, never with ==.
  • Deduplicate on webhook-id. It is the event id, so it stays the same across retries and replays.
  • While a rotated secret still overlaps, Red sends a second v1 value. Accept the request if any one matches.
  • The webhook-* headers follow the Standard Webhooks spec, so its libraries work unchanged.
Verify red-signatureNode.js shown, no cURL example yet
import crypto from "node:crypto";
import express from "express";

const secret = process.env.RED_WEBHOOK_SECRET; // whsec_…
const TOLERANCE_SECONDS = 5 * 60;

function verify(rawBody, header) {
  const pairs = header.split(",").map((part) => part.trim().split("="));
  const timestamp = pairs.find(([key]) => key === "t")?.[1];
  const signatures = pairs.filter(([key]) => key === "v1").map(([, value]) => value);
  if (!timestamp || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex");
  // While a rotated secret overlaps, Red sends one v1 per secret.
  return signatures.some(
    (signature) =>
      signature.length === expected.length &&
      crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected)),
  );
}

const app = express();

// Verify the raw bytes: re-serialised JSON will not match the signature.
app.post("/webhooks/red", express.raw({ type: "application/json" }), (req, res) => {
  if (!verify(req.body.toString("utf8"), req.get("red-signature") ?? "")) {
    return res.status(400).send("Invalid signature");
  }
  const event = JSON.parse(req.body);
  // Retries and replays reuse event.id, so skip ids you have already handled.
  console.log(event.type, event.id);
  res.sendStatus(200);
});

app.listen(3000);

Retries and failures

Red tries each event up to 8 times. After the first attempt it waits 5 s, 5 min, 30 min, 2 h, 5 h, 10 h, 10 h between tries, about 27 hours in all.

  • Pausing or deleting an endpoint cancels its pending retries. Resuming a paused endpoint resends the events canceled in the last 7 days.
  • Sandbox scans send events too, but they never count toward an endpoint's failure streak or auto-disable.
  • A saved endpoint that fails continuously for 5 days is turned off, and workspace owners and admins get an email.
  • When an event to a saved endpoint runs out of retries, owners and admins get an email too, at most once a day per endpoint.
  • You can replay any finished delivery from the event log. A replay sends the same event id.
  • Deliveries, with their attempts and responses, are kept for 30 days.

Events

Sample payloads are visible to workspace owners and admins.

scan.completedA scan finished and its trust report is ready.
scan.failedA scan could not be completed. The payload carries the error.