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

# Anthropic

> Route your Anthropic Claude requests through Metrion to track token usage, costs, and latency — with a one-line SDK change.

Use Metrion as a drop-in proxy for Anthropic's API. Your requests pass through `https://www.metrion.dev/api/proxy`, Metrion logs the usage, and the response comes back unchanged.

## Prerequisites

* A Metrion account with your `sk-metrion-xxx` token (find it on the [Integrate page](https://www.metrion.dev/integrate))
* An Anthropic API key saved in Metrion's Integrate page

## Setup

<Steps>
  ### Install the Anthropic SDK

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

    ```bash Python theme={null}
    pip install anthropic
    ```
  </CodeGroup>

  ### Configure the client

  Replace the default Anthropic base URL with Metrion's proxy and use your `sk-metrion-xxx` token as the API key. The SDK automatically appends `/v1/messages` to the `baseURL`.

  <CodeGroup>
    ```typescript TypeScript theme={null}
    import Anthropic from '@anthropic-ai/sdk'

    const client = new Anthropic({
      apiKey: 'sk-metrion-xxx',       // your Metrion token
      baseURL: 'https://www.metrion.dev/api/proxy',
    })
    ```

    ```python Python theme={null}
    import anthropic

    client = anthropic.Anthropic(
        api_key="sk-metrion-xxx",     # your Metrion token
        base_url="https://www.metrion.dev/api/proxy",
    )
    ```
  </CodeGroup>

  ### Send a request

  <CodeGroup>
    ```typescript TypeScript theme={null}
    import Anthropic from '@anthropic-ai/sdk'

    const client = new Anthropic({
      apiKey: 'sk-metrion-xxx',
      baseURL: 'https://www.metrion.dev/api/proxy',
    })

    const message = await client.messages.create({
      model: 'claude-sonnet-4-6',
      max_tokens: 1024,
      messages: [{ role: 'user', content: 'Hello, world!' }],
    })

    console.log(message.content)
    ```

    ```python Python theme={null}
    import anthropic

    client = anthropic.Anthropic(
        api_key="sk-metrion-xxx",
        base_url="https://www.metrion.dev/api/proxy",
    )

    message = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Hello, world!"}],
    )

    print(message.content)
    ```
  </CodeGroup>
</Steps>

## Direct HTTP

If you prefer to call the API without a SDK, `POST` directly to the messages endpoint:

```bash theme={null}
curl https://www.metrion.dev/api/proxy/messages \
  -H 'x-api-key: sk-metrion-xxx' \
  -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, world!"}]
  }'
```

## Supported models

| Model ID                    | Display name    |
| --------------------------- | --------------- |
| `claude-opus-4-6`           | Claude Opus 4   |
| `claude-sonnet-4-6`         | Claude Sonnet 4 |
| `claude-haiku-4-5-20251001` | Claude Haiku 4  |

Metrion uses prefix matching, so versioned model IDs (e.g. `claude-opus-4-6`) are automatically mapped to the correct pricing tier.

## Pass-through mode

If you want to manage your Anthropic key yourself instead of storing it in Metrion, use pass-through mode. Pass your Anthropic key in `x-api-key` and your Metrion token in `x-metrion-token`:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import Anthropic from '@anthropic-ai/sdk'

  const client = new Anthropic({
    apiKey: process.env.ANTHROPIC_API_KEY,   // your Anthropic key directly
    baseURL: 'https://www.metrion.dev/api/proxy',
    defaultHeaders: {
      'x-metrion-token': 'sk-metrion-xxx',   // identifies your Metrion account
    },
  })
  ```

  ```python Python theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key=os.environ["ANTHROPIC_API_KEY"],
      base_url="https://www.metrion.dev/api/proxy",
      default_headers={"x-metrion-token": "sk-metrion-xxx"},
  )
  ```
</CodeGroup>

<Note>
  In pass-through mode, your Anthropic key is forwarded directly to Anthropic's API and is never stored by Metrion.
</Note>

## Track requests by user or service

Add the optional `x-metrion-user` header to tag individual requests with a user ID, agent name, or service label. These labels appear in your Metrion logs and dashboards.

<Tip>
  Use `x-metrion-user` to break down costs by team member, bot, or application — for example `"x-metrion-user": "agent-summarizer"` or `"x-metrion-user": "user-42"`.
</Tip>

<CodeGroup>
  ```typescript TypeScript theme={null}
  const client = new Anthropic({
    apiKey: 'sk-metrion-xxx',
    baseURL: 'https://www.metrion.dev/api/proxy',
    defaultHeaders: {
      'x-metrion-user': 'user-42',
    },
  })
  ```

  ```python Python theme={null}
  client = anthropic.Anthropic(
      api_key="sk-metrion-xxx",
      base_url="https://www.metrion.dev/api/proxy",
      default_headers={"x-metrion-user": "user-42"},
  )
  ```
</CodeGroup>
