RailGuardDocs

SDKs

Python and TypeScript. Same API as the quickstart.

Download: guardrail.py · guardrail.ts

Python
guardrail = Guardrail(api_key="rg_...", base_url="https://railguardsecurity.com", timeout=15)
payment = guardrail.spend(amount=45, merchant="OpenAI API", category="AI & Compute",
                          reasoning="…", wait=True, wait_timeout=3600, poll_interval=5)
guardrail.report_receipt(payment["transaction_id"], amount=45, merchant="OpenAI API")
TypeScript
const guardrail = new Guardrail({ apiKey: "rg_...", baseUrl: "https://railguardsecurity.com" });
const payment = await guardrail.spend({ amount: 45, merchant: "OpenAI API", category: "AI & Compute", reasoning: "…" });
await guardrail.reportReceipt(payment.transaction_id, { amount: 45, merchant: "OpenAI API" });

Behaviour

  • Approved → returns status + payment credential.
  • Blocked / rejected → throws SpendBlocked with reason and code. Tell the agent to stop or pick an alternative.
  • Flagged → with wait on, the call blocks the tool, polling until a human decides or wait_timeout (then SpendPending). With wait off, pass webhook_url and resume later.
  • timeout is the per-HTTP-call timeout (15s default).
  • log_payment() records a payment the agent already made (log-only).