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

# Anthropic SDK

> Wrap @anthropic-ai/sdk with Inviolet so every tool call is gated before Claude executes.

Wrap `@anthropic-ai/sdk` with Inviolet so every tool call goes through the
gateway before Claude executes.

## Install

```bash theme={"dark"}
npm install @inviolet/agent-sdk-anthropic @inviolet/agent-sdk-core
```

## Use

```ts theme={"dark"}
import Anthropic from '@anthropic-ai/sdk'
import { Inviolet } from '@inviolet/agent-sdk-core'
import { wrapAnthropic } from '@inviolet/agent-sdk-anthropic'

const inviolet = new Inviolet({
  gatewayUrl: process.env.INVIOLET_GATEWAY_URL!,
  apiKey: process.env.INVIOLET_API_KEY!,
  agentId: 'support-copilot',
})

const anthropic = wrapAnthropic(new Anthropic(), {
  inviolet,
  intentId: 'intents:customer_support_lookup',
  actor: 'alice@example.com',
  audience: 'postgres-prod',
})

// Use the wrapped client exactly as you would the real one.
const message = await anthropic.messages.create({
  model: 'claude-opus-4-8',
  tools: [/* your tool defs */],
  messages: [{ role: 'user', content: 'Look up Bob Smith' }],
})
```

## What the wrapper does

1. Mints a mandate at the start of the conversation (or reuses one from a
   session cache).
2. Intercepts every `tool_use` block in Claude's response.
3. Calls `inviolet.guard()` with the tool name + arguments.
4. On `allowed`: forwards to the real tool. On `request_approval`: returns a
   tool result indicating the request was queued. On `block`: returns a tool
   result with the deny reason so Claude can choose a different path.

## Streaming

The wrapper supports both batch and streaming. With streaming, the guard is
applied as each `tool_use` arrives — the model sees an immediate tool result
without breaking the stream.

See [Quickstart](/quickstart) for the end-to-end walkthrough.
