> ## 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 Python SDK (vouch-sdk)

> Install vouch-sdk and instrument Python AI agents, LangChain, CrewAI, and more with Trident observability and security in one call.

The `vouch-sdk` package wraps OpenLLMetry auto-instrumentation and points it at your Trident project. One call to `vouch_sdk.init()` patches every LLM client loaded in your Python process — OpenAI, Anthropic, LangChain, CrewAI, LlamaIndex, Bedrock, VertexAI, Cohere, and more — and ships the resulting OpenTelemetry spans to [app.usetrident.dev](https://app.usetrident.dev). PII redaction runs entirely inside your runtime before any trace data leaves, keeping emails, API keys, credit card numbers, and other sensitive values out of the wire.

## Requirements

* **Python 3.10 or later**
* pip

## Install

<Steps>
  <Step title="Install the base package">
    ```bash theme={null}
    pip install vouch-sdk
    ```

    The base package instruments OpenAI, Anthropic, LlamaIndex, Bedrock, VertexAI, Cohere, MCP, and the OpenAI Agents SDK out of the box.
  </Step>

  <Step title="Install optional framework extras (if needed)">
    Add the `[langchain]` extra to enable LangChain and CrewAI instrumentation:

    ```bash theme={null}
    pip install "vouch-sdk[langchain]"
    ```

    | Extra       | Installs                   | Enables                              |
    | ----------- | -------------------------- | ------------------------------------ |
    | `langchain` | `langchain-core>=0.2,<1.0` | LangChain chains, agents, and CrewAI |
  </Step>
</Steps>

## Set your environment variables

Add your project keys from **Settings → API Keys** at [app.usetrident.dev](https://app.usetrident.dev) to your `.env` file or deployment secrets manager:

```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 `vouch_sdk.init()` **once**, before you create any LLM client. Every LLM call made after `init()` is automatically traced.

```python theme={null}
import vouch_sdk

vouch_sdk.init(
    agent_id="prod-rag-bot",  # optional — scopes spans to a named agent
)
```

When `project_pk` and `project_sk` are omitted, `init()` reads them from `TRIDENT_PROJECT_PUBLIC_KEY` / `TRIDENT_PROJECT_SECRET_KEY` automatically.

### All options

| Parameter            | Type           | Default                   | Description                                                                                                        |
| -------------------- | -------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `project_pk`         | `str`          | env                       | Project public key. Reads `TRIDENT_PROJECT_PUBLIC_KEY`.                                                            |
| `project_sk`         | `str`          | env                       | Project secret key. Reads `TRIDENT_PROJECT_SECRET_KEY`.                                                            |
| `agent_id`           | `str`          | env                       | Logical agent identifier shown in the dashboard. Reads `TRIDENT_AGENT_ID`.                                         |
| `endpoint`           | `str`          | `https://app.tryvouch.ai` | Override the Trident host. Reads `TRIDENT_ENDPOINT`.                                                               |
| `agent_url`          | `str`          | env                       | Public HTTP endpoint for Red Team auto-targeting. Reads `VOUCH_AGENT_URL`.                                         |
| `app_name`           | `str`          | `agent_id`                | OTel resource `service.name`. Falls back to `"vouch-app"`.                                                         |
| `disable_batch`      | `bool`         | `False`                   | Emit each span immediately. Useful for short-lived scripts.                                                        |
| `instruments`        | `set`          | `None`                    | Restrict which traceloop instruments are activated.                                                                |
| `redact_pii`         | `bool \| dict` | `True`                    | Edge PII redaction. `True` uses the built-in rule set; pass `{"rules": [...]}` for custom rules; `False` disables. |
| `**traceloop_kwargs` |                |                           | Extra keyword arguments forwarded verbatim to `Traceloop.init()`.                                                  |

## Full working example

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

```python theme={null}
import os
import vouch_sdk
from openai import OpenAI

# 1. Start tracing — do this before creating any LLM client.
vouch_sdk.init(
    agent_id="my-chat-agent",
    # project_pk and project_sk are read from env automatically
)

# 2. Create your LLM client exactly as you normally would.
client = OpenAI()  # picks up OPENAI_API_KEY from env

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

print(response.choices[0].message.content)
```

## LangChain example

Install the `langchain` extra, then call `init()` before building your chain:

```python theme={null}
import vouch_sdk
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

vouch_sdk.init(agent_id="langchain-agent")

llm = ChatOpenAI(model="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant."),
    ("human", "{question}"),
])
chain = prompt | llm

result = chain.invoke({"question": "What is prompt injection?"})
print(result.content)
```

Every chain invocation, LLM call, and retrieval step is automatically captured as a nested OTel span in your Trident project.

## Supported LLM frameworks

The SDK auto-instruments all of the following when they are imported 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>

<Note>
  LangChain and CrewAI require the `[langchain]` extra: `pip install "vouch-sdk[langchain]"`.
</Note>

## PII redaction defaults

`redact_pii=True` is the default. Before any span attribute leaves your process, the SDK scans and replaces the following patterns with `[REDACTED_<TYPE>]` tokens:

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

Pass `redact_pii=False` to disable, or `redact_pii={"rules": [...]}` to supply a custom list of `PiiRule` objects.

## Next steps

<CardGroup cols={1}>
  <Card title="Python SDK API Reference" icon="code" href="/sdk/python/reference">
    Explore the full API: `vouch_sdk.init()`, `firewall_headers()`, `redact_text()`, `redact_value()`, and all configuration options.
  </Card>
</CardGroup>
