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

# Quickstart

> Protect an Anthropic Messages agent loop with Averta decisions.

Use this page when your application already calls the Anthropic JavaScript SDK. The wrapper keeps the Anthropic client shape and adds Averta checkpoints around `messages.create(...)`.

## Install

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

  ```bash yarn theme={null}
  yarn add @anthropic-ai/sdk @averta-security/sdk-anthropic
  ```

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

```bash theme={null}
export ANTHROPIC_API_KEY="your-anthropic-key"
export AVERTA_API_KEY="your-averta-key"
```

The Anthropic wrapper reads `AVERTA_API_KEY` from the environment. Pass `avertaApiKey` only when this client should use a different Averta key.

## Wrap the Client

```typescript theme={null}
import Anthropic from "@anthropic-ai/sdk";
import { wrapAnthropic } from "@averta-security/sdk-anthropic";

let client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY!,
});

client = wrapAnthropic(client);
```

## Send a Guarded Message

```typescript theme={null}
const message = await client.messages.create({
  model: process.env.ANTHROPIC_MODEL ?? "claude-sonnet-4-5",
  max_tokens: 512,
  messages: [
    {
      role: "user",
      content: "Explain password reset link expiration in one sentence.",
    },
  ],
});

console.log(
  message.content
    .map((block) => (block.type === "text" ? block.text : ""))
    .join("\n")
);
```

For this call, Averta runs a request checkpoint before Anthropic sees the message and an output checkpoint before your app receives the final text.

## Add Tools

```typescript theme={null}
const tools = [
  {
    name: "search_docs",
    description: "Search internal support documentation.",
    input_schema: {
      type: "object",
      properties: {
        query: { type: "string" },
      },
      required: ["query"],
      additionalProperties: false,
    },
  },
];

const toolMessage = await client.messages.create({
  model: process.env.ANTHROPIC_MODEL ?? "claude-sonnet-4-5",
  max_tokens: 512,
  messages: [
    {
      role: "user",
      content: "Search the docs for password reset guidance.",
    },
  ],
  tools,
});
```

If Anthropic returns `tool_use` blocks, Averta has already checked those tool calls before your app receives them. When your app sends `tool_result` blocks back, Averta checks those results before Anthropic sees them.

## Confirm Decisions

With an allowing policy and a tool call, Events should show a sequence like:

```text theme={null}
request -> tool_call -> tool_result -> output
```

The exact sequence depends on whether the model calls a tool. A request with no tool call can skip `tool_call` and `tool_result`. The SDK generates `requestId` and `traceId` automatically; pass `requestContext` only when you need your own `conversationId`, `requestId`, or `traceId`.

## Runnable Example

The SDK repository includes a complete Anthropic Messages tool-loop example:

```bash theme={null}
cp examples/.env.example examples/.env
npm --prefix examples/anthropic/basic install
npm run example:anthropic:basic:start
```

Fill `ANTHROPIC_API_KEY` and `AVERTA_API_KEY` in `examples/.env` before running it.

## Current Limit

Anthropic streaming is not supported yet. Streaming calls fail closed before provider execution. Use non-streaming `messages.create(...)` for guarded Anthropic flows today.

## Next Steps

<CardGroup cols={2}>
  <Card title="Messages API" icon="message" href="/anthropic/messages-api">
    Understand the guarded Anthropic surface.
  </Card>

  <Card title="Tools" icon="toolbox" href="/anthropic/tool-use">
    Learn how tool exposure and tool-call checks work.
  </Card>

  <Card title="Tool results" icon="file-shield" href="/anthropic/tool-results">
    Screen returned tool content before continuation calls.
  </Card>

  <Card title="Events" icon="activity" href="/dashboard/events">
    Investigate decisions in the dashboard.
  </Card>
</CardGroup>
