Agents

One tool call, in any framework.

The check is a single POST with a small JSON body. Wrap it as a tool, put it in front of the action, and treat every outcome except an explicit allow as a stop.

The contract the model must follow

A model will happily ignore an instruction like "ask before acting" unless the tool result makes the rule mechanical. Three sentences are enough:

system prompt fragment
Before any tool that changes state, call aprve_authorize with the agent id and the action.
If decision is "allow", perform the action.
If decision is "deny", do not act. There is no reversal inside Aprve: the only path is your own endpoint, called deliberately.
If decision is "deny" or the call fails, stop and report the explanation.
Do not let the model retry a deny. Retrying a denied action with a smaller amount is policy evasion with extra steps. Surface the explanation instead.

OpenAI function calling / Agents SDK

tool definition
{
  "type": "function",
  "function": {
    "name": "aprve_authorize",
    "description": "Ask Aprve whether an agent may perform an action. Call this BEFORE the action. Proceed only when the returned decision is 'allow'. Treat 'deny' and any error as a stop.",
    "parameters": {
      "type": "object",
      "required": ["agent_id", "action"],
      "properties": {
        "agent_id": { "type": "string", "description": "Stable identifier for the acting agent." },
        "action": {
          "type": "object",
          "required": ["tool"],
          "properties": {
            "tool": { "type": "string", "description": "Tool name as the policy sees it, e.g. refund.create" },
            "amount_usd": { "type": "number" },
            "target": { "type": "string" },
            "data_classes": { "type": "array", "items": { "type": "string" } }
          }
        },
        "risk_score": { "type": "number", "minimum": 0, "maximum": 100 },
        "idempotency_key": { "type": "string" }
      }
    }
  }
}

In the Agents SDK, register the same schema with function_tool and have the handler return the raw decision object. Returning the whole response, including the record hash, keeps the evidence in the transcript.

LangChain / LangGraph

python
from langchain_core.tools import tool
import requests, os

@tool
def aprve_authorize(agent_id: str, tool_name: str, amount_usd: float | None = None) -> dict:
    """Ask Aprve whether this action is authorized. Call before acting."""
    r = requests.post(
        "https://aprve-trust.base44.app/api/v1/authorize",
        headers={"Authorization": f"Bearer {os.environ['APRVE_KEY']}"},
        json={"agent_id": agent_id, "action": {"tool": tool_name, "amount_usd": amount_usd}},
        timeout=3,
    )
    if r.status_code != 200:
        return {"decision": "deny", "reason": f"aprve_error_{r.status_code}"}
    return r.json()

MCP tool

tool schema
{
  "name": "aprve_authorize",
  "description": "Authorize an agent action before performing it. Proceed only on decision=allow.",
  "inputSchema": {
    "type": "object",
    "required": ["agent_id", "action"],
    "properties": {
      "agent_id": { "type": "string" },
      "action": {
        "type": "object",
        "required": ["tool"],
        "properties": {
          "tool": { "type": "string" },
          "amount_usd": { "type": "number" },
          "data_classes": { "type": "array", "items": { "type": "string" } }
        }
      },
      "idempotency_key": { "type": "string" }
    }
  }
}

Reference client

javascript
// Reference client. Fail closed on everything that is not an explicit allow.
export async function authorize(key, body, { timeoutMs = 3000 } = {}) {
  const res = await fetch("https://aprve-trust.base44.app/api/v1/authorize", {
    method: "POST",
    headers: {
      authorization: `Bearer ${key}`,
      "content-type": "application/json",
    },
    body: JSON.stringify(body),
    signal: AbortSignal.timeout(timeoutMs),
  });

  if (res.status === 429) {
    const retry = Number(res.headers.get("retry-after") ?? 1);
    return { decision: "deny", reason: "rate_limited", retry_after: retry };
  }
  if (!res.ok) return { decision: "deny", reason: `http_${res.status}` };

  const data = await res.json();
  if (data.decision !== "allow") return data;          // deny
  if (!data.record?.hash) return { decision: "deny", reason: "missing_record" };
  return data;
}

The same shape works in Python, Go and Rust: a bounded timeout, a 429 path that backs off, and a deny on anything unexpected. The full surface is in /openapi.json.

A decision you can verify right now
permanent demo decisionALLOW
action
refund.create · $180
rule
Refunds up to 250 USD
record
seq 1
sha-256
078506dc86…8a5948
statement
anchored
receipt
moment-j5xx23u1
dec_demo_permanent

Cite: Aprve decision dec_demo_permanent, seq 1, sha-256 078506dc868d5413af74db8267801c4bf602dea47d0446ef97ca517d5e8a5948