Approvals
Ask a human a yes/no question and be certain they were reached. For deploys, destructive commands and AI agents.
Waiting for a human pages someone and waits for an acknowledgement. An approval is the same guarantee for a real question: may I deploy this? may the agent drop this table? may we refund $4,800? The people who can answer are paged along the real path (with escalation, retries and carrier failover), they answer yes or no, and the answer is recorded with who gave it and how.
#The rule: software asks, only a human answers
Creating an approval needs an alert key, the kind a service or an agent carries. Deciding one needs an admin key (which the dashboard uses on a person's behalf), or a person replying from their own verified phone or app. So an agent can never approve its own request, even if it is compromised. Never give an agent an admin key.
const answer = await treason.approvals.ask({
title: "Deploy v42 to production",
context: { commit: "9f31c2a", diff: "+42 -7", tests: "all green" }, // what the human sees before deciding
teamId, // omit with a single team
timeoutSeconds: 900, // then it is a "no" (onTimeout: "deny", the default)
});
if (!answer.approved) throw new Error(`not approved (${answer.approval.status})`);treason approval request "Deploy v42 to production" --context commit=9f31c2a --timeout 15m --wait
# exit 0 approved, 2 denied / expired / no answercurl -X POST "$TREASON_API_URL/v1/approvals" \
-H "Authorization: Bearer $TREASON_API_KEY" -H "Content-Type: application/json" -H "Idempotency-Key: deploy-v42" \
-d '{"title":"Deploy v42 to production","context":{"commit":"9f31c2a"},"timeoutSeconds":900}'
curl "$TREASON_API_URL/v1/approvals/$ID" -H "Authorization: Bearer $TREASON_API_KEY" # poll until status != pending#How a person answers
| Channel | How |
|---|---|
| Text | Y4821 to approve, N4821 to deny (4821 is the alert number in the message). A bare yes or no works when they have exactly one question open. |
| Phone call | Press 1 to approve, 9 to deny, 2 to escalate now. |
| Dashboard | Approvals page: the context, then Approve or Deny. |
| API | POST /v1/approvals/{id}/decision with an admin key. |
Acknowledging the page (replying with just the number, or the acknowledge button) only stops the paging. The question stays open until someone answers or it times out.
#Who must say yes
requiredsets how many approvals it takes (up to 5). Any denial denies at once.deciderslimits who may answer by text, call or app to named people (default: whoever was paged). An admin key may always decide.userIdspages specific people instead of the team's escalation policy.relatedAlertIdnames the alert the question is about. Whoever acknowledged that alert is paged first, the approval is filed under its team, and the question and the answer appear in its timeline. See An agent fixes it, you approve by text.
#What a timeout means
onTimeout is deny unless you say otherwise, and the approval ends as expired with decision: "deny". Set onTimeout: "approve" only for things where silence should mean yes. The wait never hangs: approvals.ask waits as long as the approval's own timeout.
#Statuses
pending → approved, denied, expired or cancelled (the requester withdrew it, or someone closed its alert by hand). decision is the effective answer: the human's, or for expired whatever onTimeout says. Deciding closes the alert, so nobody keeps getting paged.
#Retries
Send an Idempotency-Key (the SDK does for you). A retried request is the same approval and the same alert, so a flaky network never asks twice.
#Webhooks
approval.requested and approval.decided carry data.approval, for your own systems (post the answer to a pipeline, log it for audit).
#For AI agents
The MCP server exposes request_approval as a tool, so an agent in Claude, Cursor or any MCP client can ask a person before it does something irreversible. examples/agent-approval wraps any tool function the same way. For the whole flow, from the page to the fix, see An agent fixes it, you approve by text.