← Back to home

VENZX Python SDK

Keep a human in the loop on every action your AI agent takes — and a tamper-evident record of each. Allow, block, pause for a human, or cap the spend, in one line of code. Works with any agent or framework.

View on PyPI →Source on GitHub — read the code →Try the live demo

Install & authenticate

Python 3.8+. The sync client only needs requests.

pip install venzx            # sync client
pip install "venzx[async]"   # also installs httpx for the async client

Set your API key once in the environment (create keys in your dashboard):

export VENZX_API_KEY="pai-..."

5-minute end-to-end — paste this and run it

One complete script. After pip install venzx and setting your key above, copy this whole block into a file and run it — you'll watch VENZX allow a safe action, block an unsafe one, and pause a risky one for a human, all in a few lines.

# save as try_venzx.py, then:  python try_venzx.py
from venzx import Venzx, Policy

vx = Venzx()  # reads VENZX_API_KEY from the environment

# Your rulebook: search runs freely, sending email needs a human's OK,
# and nothing may reach an address outside your own API.
policy = (
    Policy()
    .allow_tools("search", "send_email")
    .require_approval("send_email")
    .allow_domains("api.yourapp.com")
)

def check(tool, args):
    r = vx.inspect_tool_call(tool, args, policy=policy)
    print(f"{tool:12} -> {r.decision:12} ({r.decided_by})  {r.reason or ''}")
    return r

# 1) A safe, allow-listed action — runs.
check("search", {"q": "refund policy"})
# -> search       -> allow        (allow)

# 2) A tool that's NOT on the allowlist — blocked outright.
check("run_shell", {"cmd": "rm -rf /data"})
# -> run_shell    -> block        (tool_allowlist)  run_shell not allowed

# 3) A risky action — held for a human instead of running.
r = check("send_email", {"to": "customer@acme.com"})
# -> send_email   -> needs_review (approval_required)
if r.needs_approval:
    print("Held. The approver was emailed a one-click Approve / Reject link.")

That's the whole product in one screen: allow, block, pause for a human — and every one of those decisions is written to a tamper-evident log you can export. Everything below is detail on each piece.

Quick start — check an action

The core check is the tool call — every action your agent tries to take. VENZX inspects it and returns a verdict before it runs.

from venzx import Venzx, Policy

vx = Venzx()  # reads VENZX_API_KEY

r = vx.inspect_tool_call(
    "send_email",
    {"to": "customer@acme.com"},
    policy=Policy().allow_tools("search").require_approval("send_email"),
)

r.decision        # "allow" | "block" | "needs_review"
r.blocked         # True / False
r.needs_approval  # True when a human must approve first
r.reason          # plain-language explanation of the verdict
r.decided_by      # which check decided — e.g. "ssrf", "secret_scan", "allow"
r.duration_ms     # guard pipeline time, server-measured

Policy — your rulebook

A Policy sets the rules for a call (or every call). It's fluent, typed, and validated client-side. Only fields you set are sent.

from venzx import Policy

policy = (
    Policy()
    .allow_tools("search", "read_file")          # may run freely
    .require_approval("send_email", "delete")    # pause for a human
    .allow_domains("api.yourapp.com")            # outbound allowlist
    .limit(max_tool_calls=20, max_tokens=20_000, max_cost=0.50)  # per-run caps
)

guard.tool_call("send_email", {"to": addr}, policy=policy)

Guard — detect and auto-handle (recommended)

The raw client returns a verdict; the Guard acts on it for you — so you get automatic enforcement with no per-call if blocked: branching.

from venzx import Venzx, Policy

vx = Venzx()
guard = vx.guard_for(
    policy=Policy().allow_tools("search").require_approval("send_email"),
    on_tool_block="raise",       # blocked action → raise venzx.Blocked
    on_approval="raise",         # risky action  → raise ApprovalRequired
    # fail_open=True,            # opt in: allow if VENZX can't be REACHED
)

# One-liners:
@guard.protect                     # checks input + output automatically
def answer(prompt: str) -> str:
    return my_llm(prompt)

client = guard.wrap_openai(OpenAI())   # drop-in: prompt + reply guarded

Guard any tool in one line — works with LangChain, CrewAI, LlamaIndex, MCP handlers, or plain functions. Just decorate the function your agent calls:

@guard.protect_tool          # every call is checked before it runs
def send_email(to: str, body: str):
    ...   # blocked -> raises Blocked; risky -> waits for approval

The Guard fails closed (v1.0.1+). If a check does not come back with a verdict, the action is blocked. fail_open=True is an opt-in that covers one case only — VENZX could not be reached at all (connection error or timeout) — and the verdict it returns is marked degraded. Any reply VENZX does send that is not a verdict always blocks: a request that is too large, a rate limit, an empty balance, a revoked key, or an audit record that could not be written.

The human-approval gate

Mark a tool as approval-required and a call to it returns needs_review — the action is held, and the approver is emailed a one-click Approve / Reject link (no login). The agent resumes only when they say yes. An unsafe call (SSRF, not on the allowlist) is still blocked outright, never merely sent for review.

from venzx import Venzx, Policy, ApprovalSpent, ApprovalActionMismatch

vx = Venzx()
policy = Policy().allow_tools("search").require_approval("send_email")

action = {"name": "send_email", "args": {"to": addr}}

r = vx.inspect_tool_call(action["name"], action["args"], policy=policy)
if r.needs_approval:
    # Held. The approver already got the email; block until they decide.
    vx.wait_for_approval(r.approval_id, timeout=600)
    try:
        # Name the action you are about to run. The approval covers THAT
        # call — a different tool or different args is refused.
        vx.consume_approval(r.approval_id, action=action)
    except ApprovalActionMismatch:
        ...                                  # not what was approved — ask again
    except ApprovalSpent:
        ...                                  # already used, rejected, or stale
    else:
        send_email(addr)          # a human said yes, and you hold the claim

# Non-blocking? Poll instead of waiting:
status = vx.get_approval(r.approval_id)["status"]
# pending | approved_unclaimed | used | rejected | expired

What the approver actually sees. Arguments are redacted before the record is written, so neither the email, the confirmation page, nor the stored record carries your raw inputs. Numbers and true/false pass through untouched (amount=500 is the decision, and a number cannot carry a credential). Anything on a sensitive-looking key, or that scans as a credential or a bearer token, is replaced outright. An email address keeps its domain and loses its local part. A long run of digits keeps only its last four. A nested object or list is shown in full, every value in it masked by the same rules. Any text value that survives all of that is cut at 4000 characters and then says how much it left out; a record keeps at most 50 arguments, with the remainder counted in a visible (not shown) row rather than silently dropped; and an argument name is cut at 60 characters. The confirmation page, where the decision is made, shows every value in full, nested ones on their own row; the email is a preview that cuts each value at 300 characters and says so. The action binding is unaffected: the digest is taken from the raw arguments before any of this, so consume_approval still checks the full, exact call.

Reading a status is not permission. get_approval and wait_for_approval only tell you where a request stands — a decided but unclaimed one reads approved_unclaimed. Permission comes from consume_approval, which succeeds for exactly one caller, is bound to the API key that made the request, and is bound to one exact action — pass the tool and arguments you are about to run and a mismatch raises ApprovalActionMismatch without spending the approval. Every later attempt raises ApprovalSpent — deliberately not a Blocked, because "ask for a new approval" and "you aren't allowed" need different handling. Using the Guard instead? It claims the authorization for you on every approval path, so there is nothing extra to write.

Two different timers. wait_for_approval(timeout=…) is how long your agent blocks; the approval's own expiry (default 2h) is when VENZX auto-rejects it. They're independent — if your wait times out the request is still live, so poll again (or rely on the webhook) rather than assuming it was declined.

Auto-reject on timeout. A held request auto-rejects after a deadline (default 2h), set per policy with approval_expiry_seconds. Prefer a webhook? Configure one and VENZX POSTs it on every decision (polling still reflects the result if delivery fails). Every step — created, emailed, approved / rejected / timed-out — is written to the tamper-evident log, exportable as CSV or a printable PDF for an auditor, and viewable on a read-only status page.

Don't take "tamper-evident" on trust. Every row is sealed with HMAC-SHA256(key, previous seal + this row), so each row commits to the one before it and the key never leaves the server. You can check that for yourself in about ten seconds, with no account: open the live ledger on /try, change any line, and ask it to verify — it names the row that stopped adding up.

Run sessions & spend caps

A run pins a run_id + policy across many calls, so per-run budgets (tool calls, tokens, cost) are enforced across the whole agent run — even across servers.

run = vx.run(policy=Policy.strict().limit(max_tool_calls=5))
run.inspect_input(user_msg)
run.inspect_tool_call("search", {"q": "..."})   # budget shared across the run

Batch, streaming, async & errors

  • run(...) — a run session that shares per-run spend caps across many calls.
  • inspect_many([...]) — batch inspection with stop_on_block.
  • stream(...) — streaming inspection (Server-Sent Events) for large bodies.
  • AsyncVenzx — the same surface, awaited (pip install "venzx[async]").
  • Auto-retry on 429/5xx with backoff; hooks (on_request/on_response/on_block).

Every failure raises a typed VenzxError subclass — AuthenticationError, PermissionDeniedError, RateLimitError, InsufficientCreditsError, Blocked, ApprovalRequired, and more — so you can handle each precisely. Each carries a machine-readable .code from the API.

Two you'll meet if your key is restricted: an endpoint the key isn't permitted to use raises PermissionDeniedError with code="INSUFFICIENT_SCOPE", and a key whose rotation grace period has closed raises AuthenticationError with code="KEY_EXPIRED" — switch to the replacement key. Neither is retried.

Framework integrations

Each guide has a 5-minute quick start and a small working example that puts the check where that framework expects it. The code on each page is the file our tests run against the pinned framework version.

What VENZX does NOT do

Three limits worth knowing before you rely on this. We would rather you heard them from us than found them yourself.

1. The action check depends on the SDK. When a human approves a held tool call, the approval is for that exact action — that tool, those arguments. Claiming it requires naming the action, and we refuse anything that is not what was approved. But VENZX never sees your tool execute: it runs inside your process, after we have answered. So a caller that bypasses the SDK, or lies to it about what it is running, is not stopped by this. What it stops is the ordinary case — a retry, a loop, or a bug reusing one approval for a different call.

2. Rows deleted from the end of the audit log are detected only up to the latest public anchor. Each row is sealed with HMAC-SHA256(key, previous seal + this row), so every row commits to the one before it. Change a row, delete one from the middle, reorder two, insert one — the chain stops adding up and verification names the row that broke. Cut rows off the end and there is nothing after them left to point back, so the seals alone say the rest is fine. Catching that needs the latest seal kept somewhere the log cannot reach. So once a day, and on demand, the head of the log — its sequence number, its seal and the UTC time — is published as one line in a public git repository (named by GET /audit/anchors), and verification and every evidence report check every published anchor: the log must still reach the latest anchored row. Not detected: rows cut off the end that were written after the latest anchor, normally the last 24 hours. You can try the seals yourself at the live ledger.

3. Someone with server access can rewrite the log only after the latest public anchor. The signing key lives in the server's environment, so anyone who can read it can rewrite a row and re-seal everything after it. The seals protect you against someone who reaches the database — a stolen backup, a compromised database user — not against us. The public anchors do: re-sealing changes the seal at every anchored row, and those are already published, so a change to any row at or before the latest anchor is detected, key or no key. Not detected: a rewrite confined to rows written after the latest anchor; a row that was never written; and a rewrite of the anchor repository's own history, which needs admin access to it and is visible to anyone who cloned it earlier. You do not have to take our word for the check: download Verifiable JSON from the Audit Log and run tools/verify_audit_export.py (one file, Python standard library, no key) against the public anchors. It shows each anchored record is the one that was published; it cannot show that no record was left out of the export.

Full API reference

This page covers the essentials. The exhaustive reference — every method, parameter, and the typed result objects — ships with the package and on PyPI.

HTTP endpoints

POST/v1/inspectCheck one action — returns allow / block / needs_review (API key)
POST/v1/inspect/streamSame, streamed as server-sent events (API key)
GET/v1/approvals/{approval_id}Poll a held approval’s status — side-effect free (API key)
POST/v1/approvals/{approval_id}/consumeSpend the approval. Body MUST name the action you are about to run (API key)
GET/v1/healthService health (Mongo/Redis/email) + today’s tallies — no auth, for status pages / monitors
GET/decide/{token}Show the Approve / Reject confirmation page. Changes nothing (signed link, no login)
POST/decide/{token}Apply the decision. Only this does — form_token from the page above is required
GET/approve-rule/{token}“Don’t ask again” — show what the auto-allow rule would do. Changes nothing (signed link, no login)
POST/approve-rule/{token}Create the auto-allow rule. Only this does — form_token from the page above is required
GET/status/{token}Read-only status page: pending + recent decisions (signed, expiring link)
GET/api/dashboard/approvals/export.csvApproval audit trail as CSV (dashboard auth)
GET/api/dashboard/approvals/export.pdfApproval audit trail as printable PDF (dashboard auth)
GET/api/dashboard/logs/export.jsonYour audit records, each with a proof against the public anchors, for tools/verify_audit_export.py (dashboard auth)
GET/audit/anchorsWhere the audit log’s head is published: the public repository and file — no auth
POST/api/dashboard/approvals/status-link/rotateRevoke + reissue the status link if it leaks (dashboard auth)

Spending an approval over raw HTTP

An approval authorizes one exact action, so the claim has to say which. Send action, or action_digest if you would rather not put the arguments back on the wire. There is no way to opt out: a claim that names no action is refused.

curl -X POST https://venzx.com/v1/approvals/$APPROVAL_ID/consume \
  -H "X-API-Key: $VENZX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"action": {"name": "send_email", "args": {"to": "customer@acme.com"}}}'

# 200  -> claimed; you may run the action now (exactly once)
# 400  APPROVAL_ACTION_REQUIRED  -> no action named; upgrade to venzx>=1.0.0
# 409  APPROVAL_ACTION_MISMATCH  -> not what was approved; NOT spent, ask again
# 409  APPROVAL_SPENT            -> already claimed, or rejected
# 410  APPROVAL_EXPIRED          -> approved, but the use window closed

→ venzx on PyPI · Product features · Live demo · Support · Blog

Stuck on something? Write to letstalk@venzx.com and include the request_id from the response — it lets us find your exact call instead of guessing. Never send a full API key.