> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usetrident.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Install the Trident TypeScript SDK

> Install @vouch-ai/sdk to auto-trace LLM calls in your Node.js agent. One init() instruments OpenAI, Anthropic, LangChain, and Bedrock.

The `@vouch-ai/sdk` package wires OpenLLMetry auto-instrumentation into every LLM client running in your Node.js process — OpenAI, Anthropic, LangChain, Bedrock, LlamaIndex, and more — and ships the resulting OpenTelemetry spans to your Trident project at [app.usetrident.dev](https://app.usetrident.dev). PII redaction runs entirely inside your process before any trace data leaves, so emails, API keys, credit card numbers, and other sensitive values are scrubbed at the edge, never in transit.

## Requirements

* **Node.js 20 or later** (the SDK is published as native ESM)
* npm, yarn, or pnpm

## Install

<CodeGroup>
  ```bash npm theme={null}
  npm install @vouch-ai/sdk
  ```

  ```bash yarn theme={null}
  yarn add @vouch-ai/sdk
  ```

  ```bash pnpm theme={null}
  pnpm add @vouch-ai/sdk
  ```
</CodeGroup>

## Set your environment variables

Open your project's `.env` file (or your deployment platform's secrets manager) and add the keys from your project's **Settings → API Keys** page at [app.usetrident.dev](https://app.usetrident.dev):

```bash .env theme={null}
TRIDENT_PROJECT_PUBLIC_KEY=pk-...
TRIDENT_PROJECT_SECRET_KEY=sk-...
```

The SDK also accepts the legacy `VOUCH_PROJECT_PUBLIC_KEY` / `VOUCH_PROJECT_SECRET_KEY` names for backwards compatibility.

## Initialize Trident

Call `trident.init()` **once**, at the very top of your application entry point, before you import or instantiate any LLM client. Every LLM call made after `init()` is automatically traced.

```typescript theme={null}
import { trident } from "@vouch-ai/sdk";

trident.init({
  projectPk: process.env.TRIDENT_PROJECT_PUBLIC_KEY,
  projectSk: process.env.TRIDENT_PROJECT_SECRET_KEY,
  agentId: "prod-rag-bot", // optional — scopes spans to a named agent
});
```

When `projectPk` and `projectSk` are omitted, `init()` reads them from `TRIDENT_PROJECT_PUBLIC_KEY` / `TRIDENT_PROJECT_SECRET_KEY` automatically, so the call can be reduced to a bare `trident.init()` if you prefer to keep credentials only in the environment.

### All options

| Option             | Type                               | Default                   | Description                                                                                                                                                                                                                                                                                                                       |
| ------------------ | ---------------------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `projectPk`        | `string`                           | env                       | Project public key.                                                                                                                                                                                                                                                                                                               |
| `projectSk`        | `string`                           | env                       | Project secret key.                                                                                                                                                                                                                                                                                                               |
| `agentId`          | `string`                           | env                       | Logical agent identifier shown in the dashboard. Reads `TRIDENT_AGENT_ID`.                                                                                                                                                                                                                                                        |
| `agentUrl`         | `string`                           | env / sniffed             | Public HTTP endpoint where the agent receives prompts, used by the Red Team page. Reads `TRIDENT_AGENT_URL`, then `VOUCH_AGENT_URL`. If not set the SDK sniffs the URL from platform env vars (Vercel, Fly, Render, Railway, Heroku, Koyeb, Cloudflare Workers, AWS App Runner) and falls back to observing `http.Server.listen`. |
| `agentPath`        | `string`                           | `/`                       | Path the agent's handler is mounted at (e.g. `/api/chat`). Reads `TRIDENT_AGENT_PATH`. Used when assembling a URL from a sniffed host.                                                                                                                                                                                            |
| `sniffAgentUrl`    | `boolean`                          | `true`                    | Set `false` to disable the `http.Server.prototype.listen` hook entirely.                                                                                                                                                                                                                                                          |
| `endpoint`         | `string`                           | `https://app.tryvouch.ai` | Override the Trident host. Reads `TRIDENT_ENDPOINT`.                                                                                                                                                                                                                                                                              |
| `appName`          | `string`                           | `agentId`                 | OTel resource app name. Falls back to `"vouch-app"`.                                                                                                                                                                                                                                                                              |
| `disableBatch`     | `boolean`                          | `false`                   | Emit each span immediately instead of batching. Useful for short-lived scripts.                                                                                                                                                                                                                                                   |
| `redactPII`        | `boolean \| { rules?: PiiRule[] }` | `true`                    | Edge PII redaction. `true` uses the built-in rule set; pass `{ rules }` for custom rules; `false` disables.                                                                                                                                                                                                                       |
| `traceloopOptions` | `Record<string, unknown>`          | —                         | Extra options forwarded verbatim to the underlying `Traceloop.init()` call.                                                                                                                                                                                                                                                       |

## Full working example

The snippet below starts Trident tracing, then makes a standard OpenAI chat completion. The completion call is traced automatically — no wrapping or middleware required.

```typescript theme={null}
import { trident } from "@vouch-ai/sdk";
import OpenAI from "openai";

// 1. Start tracing — do this before creating any LLM client.
trident.init({
  agentId: "my-chat-agent",
});

// 2. Create your LLM client exactly as you normally would.
const openai = new OpenAI(); // picks up OPENAI_API_KEY from env

// 3. Make LLM calls — tracing is automatic.
const response = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Summarise the Trident docs in one sentence." }],
});

console.log(response.choices[0].message.content);
```

## Zero-code option (no source changes)

If you want Trident traces without touching your source code, use the `@vouch-ai/sdk/register` module with Node's `--import` flag. The module reads your credentials from environment variables and calls `init()` automatically before your application starts.

<Tabs>
  <Tab title="Command line">
    ```bash theme={null}
    TRIDENT_PROJECT_PUBLIC_KEY=pk-... \
    TRIDENT_PROJECT_SECRET_KEY=sk-... \
    TRIDENT_AGENT_ID=my-agent \
    node --import @vouch-ai/sdk/register dist/server.js
    ```
  </Tab>

  <Tab title="NODE_OPTIONS (Next.js / Vercel)">
    ```bash theme={null}
    # Set in your deployment platform or .env
    NODE_OPTIONS="--import @vouch-ai/sdk/register"
    TRIDENT_PROJECT_PUBLIC_KEY=pk-...
    TRIDENT_PROJECT_SECRET_KEY=sk-...
    TRIDENT_AGENT_ID=my-agent
    ```
  </Tab>

  <Tab title="package.json scripts">
    ```json theme={null}
    {
      "scripts": {
        "start": "node --import @vouch-ai/sdk/register dist/server.js"
      }
    }
    ```
  </Tab>
</Tabs>

<Note>
  The register module is a silent no-op if `TRIDENT_PROJECT_PUBLIC_KEY` or `TRIDENT_PROJECT_SECRET_KEY` are not set — it never throws and never breaks your app. In non-production environments it prints a warning to help you catch misconfigurations early.
</Note>

## Supported LLM frameworks

The SDK auto-instruments all of the following when they are loaded in the same process:

<CardGroup cols={2}>
  <Card title="OpenAI" icon="bolt" />

  <Card title="Anthropic" icon="bolt" />

  <Card title="LangChain" icon="bolt" />

  <Card title="CrewAI" icon="bolt" />

  <Card title="LlamaIndex" icon="bolt" />

  <Card title="Amazon Bedrock" icon="bolt" />

  <Card title="Google VertexAI" icon="bolt" />

  <Card title="Cohere" icon="bolt" />

  <Card title="MCP (Model Context Protocol)" icon="bolt" />

  <Card title="OpenAI Agents SDK" icon="bolt" />
</CardGroup>

No code changes are required in your LLM client calls. Instrumentation attaches at the module level as soon as `init()` runs.

<Note>
  **PII redaction is on by default.** Before any span attribute leaves your process, the SDK scans it for and replaces the following patterns with `[REDACTED_<TYPE>]` tokens:

  * **EMAIL** — email addresses
  * **CREDIT\_CARD** — card numbers (Luhn-validated to avoid false positives)
  * **SSN** — US Social Security Numbers (`XXX-XX-XXXX`)
  * **AWS\_KEY** — AWS access key IDs (`AKIA…`, `ASIA…`)
  * **JWT** — JSON Web Tokens
  * **API\_KEY** — API keys (`sk-…`, `sk-ant-…`)
  * **IBAN** — International Bank Account Numbers
  * **IP** — IPv4 addresses
  * **PHONE** — phone numbers

  Pass `redactPII: false` to `init()` to disable, or `redactPII: { rules: [...] }` to supply your own rule set.
</Note>

## Next steps

<CardGroup cols={1}>
  <Card title="TypeScript SDK API Reference" icon="code" href="/sdk/typescript/reference">
    Explore the full API: `trident.init()`, `trident.scan()`, `trident.selfReport()`, and all configuration options.
  </Card>
</CardGroup>
