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

# Anthropic

> Scan Claude traffic through the PromptGuard proxy with the Anthropic SDK, or with the SDK auto-instrumentation

Two ways in: point the Anthropic client at the proxy, or call `init()` and keep the client as it is ([auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md) patches the `anthropic` package in Python and `@anthropic-ai/sdk` in Node).

## Proxy

> [!NOTE]
>
> **Proxy Base URL:** `https://api.promptguard.co/api/v1`
>
> Point your LLM SDK's `base_url` / `baseURL` to this endpoint. Your existing provider API key goes in the `Authorization` header as usual; add your PromptGuard key via `X-API-Key`.

The proxy serves Anthropic's Messages API at `/messages` and its token counter at `/messages/count_tokens`, so the official Anthropic SDK works unchanged. Every model id starting `claude-` goes to Anthropic.

The Anthropic SDK adds `/v1` to its base URL itself, so its base URL is `https://api.promptguard.co/api`, one segment shorter than the proxy URL above.

> [!WARNING]
>
> The Anthropic SDK sends its own credential in `X-Api-Key`, the header PromptGuard reads its key from, and current SDKs (`anthropic` 2.x, `@anthropic-ai/sdk` 1.x) refuse `api_key` and `auth_token` together. So set both headers yourself in `default_headers`: your **PromptGuard** key as `X-API-Key`, and your Anthropic key as `Authorization: Bearer`. PromptGuard forwards the bearer token to Anthropic in the `x-api-key` header Anthropic expects. Headers set this way win over an `ANTHROPIC_API_KEY` in the environment.

```python Python theme={"system"}
# pip install "anthropic>=2"
import os
import anthropic

client = anthropic.Anthropic(
    base_url="https://api.promptguard.co/api",
    default_headers={
        "X-API-Key": os.environ["PROMPTGUARD_API_KEY"],  # authenticates you to PromptGuard
        "Authorization": f"Bearer {os.environ['ANTHROPIC_API_KEY']}",  # forwarded to Anthropic
    },
)

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(message.content[0].text)
```

```typescript Node.js theme={"system"}
// npm install @anthropic-ai/sdk@^1
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://api.promptguard.co/api',
  defaultHeaders: {
    'X-API-Key': process.env.PROMPTGUARD_API_KEY, // authenticates you to PromptGuard
    Authorization: `Bearer ${process.env.ANTHROPIC_API_KEY}`, // forwarded to Anthropic
  },
});

const message = await client.messages.create({
  model: 'claude-sonnet-4-5',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello!' }],
});
const block = message.content[0];
if (block.type === 'text') console.log(block.text);
```

```bash cURL theme={"system"}
curl https://api.promptguard.co/api/v1/messages \
  -H "X-API-Key: $PROMPTGUARD_API_KEY" \
  -H "Authorization: Bearer $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-5", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello!"}]}'
```

To keep the Anthropic key out of your application, [store it as a provider key](https://docs.promptguard.co/gateway/provider-keys.md) under `anthropic` and drop the `Authorization` header. PromptGuard then sends the stored key.

The `anthropic-version` and `anthropic-beta` headers your SDK sends are forwarded as sent. Only when you send no `anthropic-version` does PromptGuard add `2023-06-01`.

> [!NOTE]
>
> Claude model ids are accepted on `/chat/completions` too, but the reply comes back in Anthropic's Messages shape (`content`, `stop_reason`), not OpenAI's (`choices`). An OpenAI client cannot read it, so use the Anthropic SDK or the `/messages` route.

## Auto-instrumentation

```python Python theme={"system"}
import promptguard
promptguard.init()  # reads PROMPTGUARD_API_KEY

import anthropic
client = anthropic.Anthropic()  # talks to Anthropic directly; each messages.create is scanned first
```

```typescript Node.js theme={"system"}
import { init } from 'promptguard-sdk';
import Anthropic from '@anthropic-ai/sdk';

init(); // reads PROMPTGUARD_API_KEY
const client = new Anthropic(); // talks to Anthropic directly; each messages.create is scanned first
```

## Claude on AWS Bedrock

Claude models served by Bedrock are Bedrock traffic: see [AWS Bedrock](https://docs.promptguard.co/integrations/providers/bedrock.md).

## Next steps

> [card] [Amazon Bedrock](https://docs.promptguard.co/integrations/providers/bedrock.md)
>
> Bedrock Runtime calls with boto3 or the AWS SDK

> [card] [Provider keys](https://docs.promptguard.co/gateway/provider-keys.md)
>
> Store your provider credentials once, forwarded server-side

> [card] [Auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md)
>
> Which provider calls `init()` patches, and which it does not


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.