API usage
Reference examples
Node.js (fetch)
Fail-closed integration skeleton.
const API_KEY = "REPLACE_ME";
const BASE_URL = "https://aisafegate.com";

const res = await fetch(BASE_URL + "/api/validate", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    authorization: "Bearer " + API_KEY,
  },
  body: JSON.stringify({
    ai_output: aiOutput,
    context: { actionKind: "data.write", workflow: "Refunds" },
  }),
});

if (!res.ok) {
  // Fail-closed: do not execute.
  throw new Error("Validation failed");
}

const decision = await res.json();

if (decision.outcome === "PASS") {
  await executeAction();
} else if (decision.outcome === "WARN") {
  await waitForApproval(decision.decision_id);
  throw new Error("Approval required");
} else {
  // BLOCK
  throw new Error("Blocked by safety policy");
}
Python (requests)
Fail-closed integration skeleton.
import requests

API_KEY = "REPLACE_ME"
BASE_URL = "https://aisafegate.com"

res = requests.post(
  BASE_URL + "/api/validate",
  headers={
    "content-type": "application/json",
    "authorization": "Bearer " + API_KEY,
  },
  json={
    "ai_output": ai_output,
    "context": {"actionKind": "data.write", "workflow": "Refunds"},
  },
  timeout=10,
)

if res.status_code != 200:
  # Fail-closed
  raise Exception("Validation failed")

decision = res.json()

if decision.get("outcome") == "PASS":
  execute_action()
elif decision.get("outcome") == "WARN":
  wait_for_approval(decision.get("decision_id"))
  raise Exception("Approval required")
else:
  raise Exception("Blocked by safety policy")
WARN polling example
Check approval state without mutating the decision.
// Poll approval state
const API_KEY = "REPLACE_ME";
const BASE_URL = "https://aisafegate.com";

const poll = await fetch(
  BASE_URL + "/api/decisions/" + decisionId + "/approval",
  { headers: { authorization: "Bearer " + API_KEY, "x-approval-token": approvalToken } }
);

if (!poll.ok) throw new Error("Approval poll failed");
const { approved } = await poll.json();

if (approved) {
  await executeAction();
} else {
  // still waiting
}
Disclaimer
This documentation is provided for general information only. It is not legal advice, not a guarantee of compliance, and not a substitute for your own security review. You are responsible for evaluating and meeting any legal, regulatory, and contractual obligations applicable to your use case.