Skip to main content
The @vouch-ai/sdk package exports a single trident object with three methods — init(), scan(), and selfReport() — plus a zero-code register module at @vouch-ai/sdk/register. This page documents every parameter, return value, and supported environment variable.

trident.init(options?)

Initialises Trident tracing for the current Node.js process. Call this once, before you create any LLM client, at the top of your application entry point. Repeat calls are silently ignored (the function is idempotent). init() lazy-loads the OpenLLMetry instrumentation layer, patches all supported LLM clients already in memory, and begins shipping OTel spans to your Trident project. When redactPII is enabled (the default), it also installs a span processor that scrubs PII from span attributes before the HTTP export request leaves your process.

Parameters

string
Project public key. Falls back to the TRIDENT_PROJECT_PUBLIC_KEY or VOUCH_PROJECT_PUBLIC_KEY environment variable. Required — either pass it here or set the env var.
string
Project secret key. Falls back to TRIDENT_PROJECT_SECRET_KEY or VOUCH_PROJECT_SECRET_KEY. Required — either pass it here or set the env var.
string
A logical identifier for this agent (e.g. "prod-rag-bot"). Appears in the Trident dashboard’s connection panel and scopes all spans to a named agent. Falls back to TRIDENT_AGENT_ID / VOUCH_AGENT_ID.
string
Public HTTP endpoint where this agent receives prompts (e.g. "https://api.example.com/api/chat"). When set, the SDK registers the URL with Trident so the Red Team page can auto-target your agent for pen-testing without you having to type an endpoint. Falls back to TRIDENT_AGENT_URL, then VOUCH_AGENT_URL.If neither the option nor the env var is set, the SDK attempts to sniff the URL from hosted-platform env vars (Vercel VERCEL_URL, Fly FLY_APP_NAME, Render, Railway, Heroku, Koyeb, Cloudflare Workers, AWS App Runner, etc.) and then falls back to observing http.Server.prototype.listen combined with PUBLIC_URL / BASE_URL. Disable this behaviour entirely with sniffAgentUrl: false.
string
Path the agent’s HTTP handler is mounted at (e.g. "/api/chat"). Used when constructing a full URL from a sniffed hostname. Defaults to "/". Falls back to TRIDENT_AGENT_PATH / VOUCH_AGENT_PATH.
boolean
default:"true"
Set to false to disable the http.Server.prototype.listen hook and all platform-env sniffing. The SDK will only register a URL when agentUrl or TRIDENT_AGENT_URL / VOUCH_AGENT_URL is explicitly provided.
string
default:"https://app.tryvouch.ai"
Override the Trident host. Useful for on-premise deployments. Falls back to TRIDENT_ENDPOINT / VOUCH_ENDPOINT.
string
OTel resource service.name. Defaults to agentId, then "vouch-app".
boolean
default:"false"
Emit each span immediately via SimpleSpanProcessor instead of batching with BatchSpanProcessor. Useful for short-lived CLI scripts where the process exits before the batch flushes.
boolean | { rules?: PiiRule[] }
default:"true"
Controls edge PII redaction. true uses the built-in rule set (emails, card numbers, SSNs, AWS keys, JWTs, API keys, IBANs, IPs, phone numbers). Pass { rules: [...] } to supply a custom PiiRule[]. false disables redaction entirely and lets raw span attributes reach Trident.
Record<string, unknown>
Extra options forwarded verbatim to the underlying Traceloop.initialize() call. Use this for advanced OpenLLMetry configuration not exposed by the Trident wrapper.

Return value

void. The function does not return a promise — instrumentation is synchronous.

Example

Throws

Throws Error if both projectPk and projectSk are unresolvable (neither passed explicitly nor available in the environment).

trident.scan(input, options?)

Submits untrusted text to Trident’s server-side firewall and returns a pass/block verdict. Use scan() as the gate before any LLM call that carries input you don’t fully control — user messages, scraped web pages, RAG document chunks, MCP tool outputs. The server applies two checks in order: the project’s per-tenant guardrail bank (auto-populated from confirmed findings), then the upstream LLM-Guard firewall. The full round-trip has an 8-second timeout, matching the server’s own firewall timeout.

Parameters

string
required
The untrusted text to evaluate. Maximum 8 KB — the server rejects larger payloads.
string
Optional agent identifier to attach to any finding the firewall later generates. Inherits the value from init() if omitted.
string
Override the Trident base URL for this call. Defaults to the value passed to init().
string
Override the project public key for this call.
string
Override the project secret key for this call.

Return value

Returns Promise<ScanResult>, which is a discriminated union: On success (ok: true):
true
Indicates the HTTP request succeeded and a verdict was returned.
boolean
true means the prompt passed all checks and is safe to forward to your LLM. false means the prompt should be blocked.
Record<string, unknown>
Per-scanner verdicts from the LLM-Guard firewall, present when no tenant rule fired. The shape varies by scanner (prompt injection score, toxicity score, etc.).
string
Which subsystem produced the verdict: "trident.tenantRule" when a project-level deny-list rule matched, or "trident.firewall" when the result came from the upstream firewall.
object
Present only when source is "trident.tenantRule". Contains id, label, kind, scope ("project" | "org"), snippet, and severity.
number
Server-reported latency for the firewall evaluation in milliseconds.
On failure (ok: false):
false
string
Human-readable error message (HTTP status + body excerpt, or network error text).

Example


trident.selfReport(input, options?)

Lets your agent report its own anomalies to Trident as first-class findings. Your agent has more context about what went wrong than any external monitor — selfReport() ships that observation to Trident with a source: SELF_REPORT tag so it routes through the same Slack, GitHub, Jira, and webhook channels as automatically detected findings. Fire-and-forget by default: the function returns immediately and does not block the agent’s request path on a network round-trip to Trident. Pass await: true in the input if you need to confirm delivery.

Parameters (SelfReportInput)

string
required
Short kebab-case category. Validated server-side as ^[a-z][a-z0-9-]*$. Surfaces as the finding category on the Findings page and is the primary field for grouping.Well-known kinds Trident’s Sentinel agent understands:
  • tool-call-failure — a tool returned an error or timed out
  • silent-tool-failure — a tool returned empty/nil and the agent continued
  • refusal-spike — the agent refused a request it normally handles
  • hallucinated-policy — the agent cited a policy or fact that doesn’t exist
  • context-loss — the agent forgot something stated earlier in the conversation
  • infinite-loop — the agent repeated the same action N times
  • data-exfil-suspected — outbound traffic to an unexpected destination
  • prompt-injection — a guardrail detected a prompt injection pattern
  • lethal-trifecta — untrusted input + sensitive data + exfiltration leg
Use any other kebab-case slug for project-specific patterns.
string
required
Human-readable summary of the anomaly, up to 4,000 characters. Shown in the finding card and Slack alert.
string
Which agent is reporting. Defaults to the value passed to init() or TRIDENT_AGENT_ID.
"LOW" | "MEDIUM" | "HIGH" | "CRITICAL"
default:"\"MEDIUM\""
Finding severity. Defaults to "MEDIUM" — agents rarely have full context to assign CRITICAL unilaterally.
string
OTel trace ID to anchor the finding to a specific request.
SelfReportMetadataConventions & Record<string, unknown>
Structured context rendered inline in Trident’s finding evidence panel. The following conventional keys receive rich treatment in the UI — use whichever apply:Extra keys are stored verbatim.
boolean
default:"false"
Block on the network round-trip and surface errors. When false (the default) the SDK fires the request and ignores the response so the agent’s own request path cannot be slowed by a Trident call. The 5-second timeout applies in both modes.

Options (SelfReportOptions)

string
Override the Trident base URL for this call.
string
Override the project public key for this call.
string
Override the project secret key for this call.

Return value

Promise<{ ok: true; findingId: string } | { ok: false; error: string }>. On the fire-and-forget path (await: false) the promise resolves immediately with { ok: true, findingId: "" } — the findingId is only populated when await: true and the server responded successfully.

Examples


@vouch-ai/sdk/register — zero-code auto-init

The register module is a side-effect-only import that calls init() using credentials from environment variables. Use it to enable Trident traces with no source code changes.

How to use it

Environment variables read by the register module

The register module is a silent no-op if TRIDENT_PROJECT_PUBLIC_KEY or TRIDENT_PROJECT_SECRET_KEY are missing. It never throws and never crashes your app. In non-production environments (NODE_ENV !== "production") it prints a console.warn so you notice the missing configuration. Set TRIDENT_REGISTER_DEBUG=1 to force the warning in production.

Environment variables

The SDK reads the following environment variables. Explicitly passed options always take precedence.