Skip to main content
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

npm install @anthropic-ai/sdk @averta-security/sdk-anthropic
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

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

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

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:
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:
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

Messages API

Understand the guarded Anthropic surface.

Tools

Learn how tool exposure and tool-call checks work.

Tool results

Screen returned tool content before continuation calls.

Events

Investigate decisions in the dashboard.