| Header | Value |
|---|---|
X-Agent-Id | Your agent’s UUID |
X-Api-Key | Your workspace API key |
Content-Type | application/json (on POST) |
https://api.finalsay-hitl.com.
Create, wait, act
# Create
curl -sS -X POST https://api.finalsay-hitl.com/v1/approvals \
-H "Content-Type: application/json" \
-H "X-Agent-Id: $FINALSAY_AGENT_ID" \
-H "X-Api-Key: $FINALSAY_API_KEY" \
-d '{
"request_id": "refund-8812",
"question": "Refund €240 to order #8812?",
"context_markdown": "Customer reports a double charge. Payment ids: …",
"options": [
{ "label": "Refund", "value": "refund" },
{ "label": "Decline", "value": "decline" }
]
}'
# Poll
curl -sS https://api.finalsay-hitl.com/v1/approvals/refund-8812/result \
-H "X-Agent-Id: $FINALSAY_AGENT_ID" \
-H "X-Api-Key: $FINALSAY_API_KEY"
import os, time, requests
API = "https://api.finalsay-hitl.com"
HEADERS = {
"X-Agent-Id": os.environ["FINALSAY_AGENT_ID"],
"X-Api-Key": os.environ["FINALSAY_API_KEY"],
}
def ask(request_id: str, question: str, context: str, options: list[dict]) -> dict:
r = requests.post(f"{API}/v1/approvals", headers=HEADERS, timeout=30, json={
"request_id": request_id,
"question": question,
"context_markdown": context,
"options": options,
})
r.raise_for_status()
delay = 2
while True:
res = requests.get(f"{API}/v1/approvals/{request_id}/result", headers=HEADERS, timeout=30)
res.raise_for_status()
body = res.json()
if body["status"] != "pending":
return body
time.sleep(delay)
delay = min(delay * 1.5, 15)
result = ask("refund-8812", "Refund €240 to order #8812?", "Customer reports a double charge.",
[{"label": "Refund", "value": "refund"}, {"label": "Decline", "value": "decline"}])
if result["status"] == "selected_option" and result["selected_option_value"] == "refund":
issue_refund()
const API = "https://api.finalsay-hitl.com";
const headers = {
"Content-Type": "application/json",
"X-Agent-Id": process.env.FINALSAY_AGENT_ID!,
"X-Api-Key": process.env.FINALSAY_API_KEY!,
};
async function ask(body: {
request_id: string;
question: string;
context_markdown: string;
options: { label: string; value: string }[];
}) {
const created = await fetch(`${API}/v1/approvals`, { method: "POST", headers, body: JSON.stringify(body) });
if (!created.ok) throw new Error(`create failed: ${created.status} ${await created.text()}`);
let delay = 2000;
for (;;) {
const res = await fetch(`${API}/v1/approvals/${encodeURIComponent(body.request_id)}/result`, { headers });
if (!res.ok) throw new Error(`result failed: ${res.status}`);
const result = await res.json();
if (result.status !== "pending") return result;
await new Promise((r) => setTimeout(r, delay));
delay = Math.min(delay * 1.5, 15000);
}
}
expires_at (plus a few seconds), when the approval turns expired. For long
waits, use a callback instead.
Handle every outcome
status | Do |
|---|---|
selected_option | Act on selected_option_value. |
custom_instruction | Follow custom_instruction, or stop and tell a person. |
expired | Don’t proceed. custom_instruction has the fallback, if the agent has one. |
Handle errors
| Error | Do |
|---|---|
400 invalid_payload | Fix the body; issues says what’s wrong. |
401 | Check the agent ID and key. |
403 USAGE_APPROVAL_LIMIT | Plan limit reached. Don’t loop; queue and tell a person. |
409 idempotency_conflict | That request_id was used with a different body. |
429 rate_limited | Back off and retry. |
5xx or network | Retry with the same request_id. |