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

> ## Agent Instructions
> These docs moved from docs.flintai.dev to docs.switchagents.ai. Use docs.switchagents.ai for every link and request.
> To search these docs from an AI tool, connect the MCP server at https://docs.switchagents.ai/mcp. The page index is at https://docs.switchagents.ai/llms.txt.
> The source code for these products is public on GitHub. Switch Rooms: https://github.com/sandbox-quantum/switch. Switch Trust CLI: https://github.com/sandbox-quantum/switch-trust-cli. Switch Trust CodeScan action: https://github.com/sandbox-quantum/switch-trust-codescan-action. Switch Trust MCP server: https://github.com/sandbox-quantum/switch-trust-mcp. Switch Trust Python SDK: https://github.com/sandbox-quantum/switch-trust-sdk-py. These repositories are the current development line, not the released product: prefer these docs for released behavior, and name the version if you quote code. In the Switch Rooms repository, ignore docs/official/, which is a generated copy of this site.

# Integrations

> OpenAI, Anthropic, Google GenAI, LangChain, and Google ADK

The Switch Trust TypeScript SDK supports the same integrations as the Python SDK. Standard LLM clients use `wrap()`, while Google ADK uses a dedicated plugin.

| Integration | Method |
| - | - |
| OpenAI | `wrap()` |
| Anthropic | `wrap()` |
| Google GenAI | `wrap()` |
| LangChain (`ChatOpenAI`, `ChatAnthropic`, `ChatGoogleGenerativeAI`) | `wrap()` |
| Google ADK | `ADKGuardrailsPlugin` |

## OpenAI

Wrap an `OpenAI` client to route completions through the guardrails proxy.

```typescript theme={null}
import OpenAI from "openai";
import { wrap } from "@sandboxaq/switch-trust-sdk-ts";

const client = new OpenAI({ apiKey: "your-openai-api-key" });
wrap(client, {
  gatewayUrl: "https://api.switchagents.ai",
  apiKey: "your-switch-trust-api-key",
});

const response = await client.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Hello" }],
});
```

After wrapping, use the client exactly as before — the SDK redirects traffic transparently.

## Anthropic

Wrap an `Anthropic` client the same way.

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";
import { wrap } from "@sandboxaq/switch-trust-sdk-ts";

const client = new Anthropic({ apiKey: "your-anthropic-api-key" });
wrap(client, {
  gatewayUrl: "https://api.switchagents.ai",
  apiKey: "your-switch-trust-api-key",
});

const message = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
});
```

## Google GenAI

Wrap a `GoogleGenAI` client. Set your Gemini key the way you normally would (shown here on the client). The SDK does not require any additional LLM provider key of its own.

```typescript theme={null}
import { GoogleGenAI } from "@google/genai";
import { wrap } from "@sandboxaq/switch-trust-sdk-ts";

const client = new GoogleGenAI({ apiKey: "your-gemini-api-key" });
wrap(client, {
  gatewayUrl: "https://api.switchagents.ai",
  apiKey: "your-switch-trust-api-key",
});

const response = await client.models.generateContent({
  model: "gemini-2.5-flash",
  contents: "Hello",
});
```

> [!NOTE]
>
> The SDK normalizes the gateway URL with a trailing slash for Google GenAI — do not add one yourself.

## LangChain

`wrap()` auto-detects LangChain chat models, extracts the underlying SDK client, and applies guardrails routing. Supported models:

* `ChatOpenAI` (from `@langchain/openai`)
* `ChatAnthropic` (from `@langchain/anthropic`)
* `ChatGoogleGenerativeAI` (from `@langchain/google-genai`)

```typescript theme={null}
import { ChatOpenAI } from "@langchain/openai";
import { wrap } from "@sandboxaq/switch-trust-sdk-ts";

const llm = new ChatOpenAI({ model: "gpt-4" });
wrap(llm, {
  gatewayUrl: "https://api.switchagents.ai",
  apiKey: "your-switch-trust-api-key",
});

const response = await llm.invoke("Hello");
```

> [tab] ChatAnthropic
>
> ```typescript theme={null}
> import { ChatAnthropic } from "@langchain/anthropic";
> import { wrap } from "@sandboxaq/switch-trust-sdk-ts";
>
> const llm = new ChatAnthropic({ model: "claude-sonnet-4-20250514" });
> wrap(llm, {
>   gatewayUrl: "https://api.switchagents.ai",
>   apiKey: "your-switch-trust-api-key",
> });
>
> const response = await llm.invoke("Hello");
> ```

> [tab] ChatGoogleGenerativeAI
>
> ```typescript theme={null}
> import { ChatGoogleGenerativeAI } from "@langchain/google-genai";
> import { wrap } from "@sandboxaq/switch-trust-sdk-ts";
>
> const llm = new ChatGoogleGenerativeAI({ model: "gemini-2.5-flash" });
> wrap(llm, {
>   gatewayUrl: "https://api.switchagents.ai",
>   apiKey: "your-switch-trust-api-key",
> });
>
> const response = await llm.invoke("Hello");
> ```

## Google ADK

ADK agents lazily create their GenAI client at runtime, so `wrap()` cannot be used. Use `ADKGuardrailsPlugin` to configure guardrails routing at the agent level:

```typescript theme={null}
import { ADKGuardrailsPlugin } from "@sandboxaq/switch-trust-sdk-ts/plugins/adk";
import { Agent } from "@google/adk";

const plugin = new ADKGuardrailsPlugin({
  gatewayUrl: "https://api.switchagents.ai",
  apiKey: "your-switch-trust-api-key",
});

const agent = new Agent({
  model: "gemini-2.5-flash",
  generateContentConfig: plugin.contentConfig,
  beforeModelCallback: plugin.beforeModelCallback,
  onModelErrorCallback: ADKGuardrailsPlugin.onModelError,
});
```

The plugin handles three concerns:

* **Routing** — `contentConfig` directs LLM traffic through the guardrails proxy.
* **Identity** — `beforeModelCallback` attaches the ADK session ID as an `X-Agent-Session-Id` header on each call.
* **Error handling** — the static `ADKGuardrailsPlugin.onModelError` converts guardrails blocks into an `LlmResponse` the agent can handle gracefully.

See [Usage](https://docs.switchagents.ai/switch-trust/sdk/typescript/usage.md#google-adk) for the `contentConfig` cloning caveat.

## Version compatibility

Pin your provider SDK to the tested ranges to avoid breakage from private API changes:

| Provider package | Supported range |
| - | - |
| `openai` | `^6.41.0` |
| `@anthropic-ai/sdk` | `^0.100.1` |
| `@google/genai` | `^2.8.0` |
| `@google/adk` | `^1.2.0` |
| `@langchain/openai` | `^1.4.7` |
| `@langchain/anthropic` | `^1.4.0` |
| `@langchain/google-genai` | `^2.1.31` |

For the three LLM SDKs, `wrap()` resolves the installed version and warns if it falls outside the supported range.

## Known limitations

* **Private attribute mutation** — `wrap()` redirects traffic by rewriting each client's base URL and injecting the guardrails headers (`X-FlintAI-API-Key`, `X-Guardrails-Policy-Id`). For OpenAI and Anthropic this uses the internal `_options.defaultHeaders`, and for Google the internal `apiClient.clientOptions.httpOptions`. These internal attributes are not part of the providers' public APIs and may change without notice, so pin your provider SDK versions to the tested ranges.
* **Google GenAI URL normalization**: the Google GenAI SDK requires a trailing slash on the base URL. The SDK adds it automatically, so do not add one to `gatewayUrl`.
* **Multiple provider keys in environment** — if several provider API keys are set (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`), auto-detection fails. Pass `provider` explicitly to `init()`.

## Next steps

> [card] [Usage](https://docs.switchagents.ai/switch-trust/sdk/typescript/usage.md)
>
> Advanced patterns, error handling, and best practices

> [card] [Configuration](https://docs.switchagents.ai/switch-trust/sdk/typescript/configuration.md)
>
> Environment variables, credentials, and gateway setup
