Skip to Content
CallHumanDocs
Recipes

Human approval for AI agents

Pause an AI agent before a risky action, call a person to approve or reject, and continue with the answer.

Your agent wants to do something important — refund money, deploy, delete data. Before acting, it calls a human and waits.

1. The approval function

const CALLHUMAN = "https://api.callhuman.es/v1/calls";
const headers = {
  Authorization: `Bearer ${process.env.CALLHUMAN_API_KEY}`,
  "Content-Type": "application/json",
};

/** Calls the approver and resolves to true (approved) or false. */
export async function askForApproval({ phone, action }) {
  const created = await fetch(CALLHUMAN, {
    method: "POST",
    headers,
    body: JSON.stringify({
      to: phone,
      message: `Your agent wants to ${action}.`,
      options: [
        { label: "Approve", reply: "Approved. Going ahead." },
        { label: "Reject", reply: "Rejected. Nothing will happen." },
      ],
    }),
  }).then((r) => r.json());

  // Poll until the call ends (or use a webhook in production).
  for (;;) {
    await new Promise((r) => setTimeout(r, 5000));
    const call = await fetch(`${CALLHUMAN}/${created.id}`, { headers }).then((r) => r.json());
    if (["answered", "not_answered", "failed"].includes(call.status)) {
      return call.status === "answered" && call.option_label === "Approve";
    }
  }
}

2. Use it as a tool

const approved = await askForApproval({
  phone: "+34600333444",
  action: "refund 1,240 euros to Acme Ltd for invoice 2231",
});
if (!approved) throw new Error("Refund not approved by a human");
await refund(invoice);
On the phone
  1. CallHuman: Your agent wants to refund 1,240 euros to Acme Ltd for invoice 2231.

  2. CallHuman: Press 1 to approve. Press 2 to reject.

  3. Person: 1pressed

  4. CallHuman: Approved. Going ahead.

Tips

  • Not answered means no. Treat not_answered as a rejection, or escalate to a second approver.
  • Say exactly what will happen, with amounts and names: the person decides only from what they hear.
  • For agents that support MCP, a native server is coming soon.

On this page