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

# Anthropic

> POST /anthropic/v1/messages

Generate messages with automatic PII and secrets protection using the Anthropic Messages API.

```
POST /anthropic/v1/messages
```

<Note>
  This endpoint supports both **mask mode** and **route mode**. Route mode requires a local LLM with Anthropic API support (e.g., Ollama). The request format follows the [Anthropic Messages API](https://platform.claude.com/docs/en/api/messages).
</Note>

## Request

```bash theme={null}
curl http://localhost:3000/anthropic/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello"}
    ]
  }'
```

## Parameters

| Parameter     | Type         | Required | Description                          |
| ------------- | ------------ | -------- | ------------------------------------ |
| `model`       | string       | Yes      | Model ID (e.g., `claude-sonnet-4-6`) |
| `messages`    | array        | Yes      | Conversation messages                |
| `max_tokens`  | number       | Yes      | Maximum tokens to generate           |
| `stream`      | boolean      | No       | Enable streaming                     |
| `system`      | string/array | No       | System prompt                        |
| `temperature` | number       | No       | Sampling temperature (0-1)           |

All [Anthropic Messages API](https://platform.claude.com/docs/en/api/messages) parameters are supported.

## Response

```json theme={null}
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "claude-sonnet-4-6",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 10,
    "output_tokens": 15
  }
}
```

## Streaming

Set `stream: true` for Server-Sent Events:

<CodeGroup>
  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(base_url="http://localhost:3000/anthropic")

  with client.messages.stream(
      model="claude-sonnet-4-6",
      max_tokens=1024,
      messages=[{"role": "user", "content": "Write a haiku"}]
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
  ```

  ```javascript JavaScript theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    baseURL: 'http://localhost:3000/anthropic'
  });

  const stream = client.messages.stream({
    model: 'claude-sonnet-4-6',
    max_tokens: 1024,
    messages: [{ role: 'user', content: 'Write a haiku' }]
  });

  for await (const event of stream) {
    if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
      process.stdout.write(event.delta.text);
    }
  }
  ```
</CodeGroup>

## Response Headers

PasteGuard adds headers to indicate PII and secrets handling:

| Header                          | Description                                   |
| ------------------------------- | --------------------------------------------- |
| `X-PasteGuard-Mode`             | Current mode (`mask` or `route`)              |
| `X-PasteGuard-Provider`         | Provider used (`anthropic` or `local`)        |
| `X-PasteGuard-PII-Detected`     | `true` if PII was found                       |
| `X-PasteGuard-PII-Masked`       | `true` if PII was masked (mask mode only)     |
| `X-PasteGuard-Secrets-Detected` | `true` if secrets were found                  |
| `X-PasteGuard-Secrets-Types`    | Comma-separated list of detected secret types |
| `X-PasteGuard-Secrets-Masked`   | `true` if secrets were masked                 |

## Content Types

PasteGuard scans configured text roles in Anthropic requests. By default it scans:

* **User messages** — String content or text blocks
* **Tool results** — Text content in tool responses

Assistant messages and system prompts are available as scan roles, but are skipped by default. Add them to `pii_detection.scan_roles` or `secrets_detection.scan_roles` if you want PasteGuard to inspect them.
