LeashgateDocs
API reference

API reference

Base URL https://gw.leashgate.com. Authenticate with your API key as a Bearer token.

POST /v1/chat/completions

OpenAI-compatible. Accepts the same body as OpenAI's Chat Completions API and returns the provider's answer, with blocked or held tool calls removed and explained in the message content.

Request
curl https://gw.leashgate.com/v1/chat/completions \
  -H "Authorization: Bearer lg_your_key" \
  -H "x-leash-agent: refunds-bot" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Refund order A-1042"}],"tools":[...]}'

Optional headers

x-leash-agentAgent name. Letters, digits, dot, dash, underscore.
x-upstream-baseOverride the provider base URL for this call.
x-upstream-keyOverride the provider key for this call.
Streaming responses (stream: true) are forwarded as they arrive, so their tool calls are not inspected. Use non-streaming calls, or action checks, for actions that matter.

POST /v1/actions/check

Ask Leashgate before running any action. No model involved.

Request
curl https://gw.leashgate.com/v1/actions/check \
  -H "Authorization: Bearer lg_your_key" \
  -H "Content-Type: application/json" \
  -d '{"agent":"billing","action":"refund","params":{"amount":4800,"order":"A-1042"}}'
Response
{
  "decision": "approval_required",   // allow | approval_required | block | quarantine
  "reason": "amount $4,800 is above $1,000",
  "observed": false,                  // true in observe mode: would have been stopped
  "rule": "P-03",
  "reason": "Payment above threshold",
  "approval_id": "apr_k3x9q2mf"
}

Retry the same call after approval: it returns "decision": "allow" once, within one hour.

Errors

StatusCodeMeaning
401invalid_keyMissing or unknown API key.
400upstream_missingNo AI provider configured.
403agent_quarantinedThe agent is in quarantine.
403loop_detectedThe agent was just quarantined for looping.
429budget_exceededThe agent's daily budget is reached.

Errors from /v1/chat/completions use OpenAI's error format, so your SDK raises them as usual.