> ## 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.

# Authentication

> How to authenticate your requests with Metrion.

Metrion supports two authentication modes. Choose the one that fits your workflow.

<Tabs>
  <Tab title="Stored mode (recommended)">
    In stored mode, you use your Metrion token (`sk-metrion-xxx`) as the API key. Metrion looks up your provider key from encrypted storage and forwards it to the provider on your behalf. Your provider key never leaves Metrion's secure vault.

    **How to get your token**

    Find your Metrion token in one of two places:

    * **Settings → Metrion Key**
    * **The Integrate page** (shown during onboarding)

    Your token starts with `sk-metrion-` followed by 32 hex characters.

    **Anthropic SDK**

    Set `api_key` to your Metrion token. The SDK sends it as the `x-api-key` header.

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

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

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

      ```javascript Node.js theme={null}
      import Anthropic from "@anthropic-ai/sdk";

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

      const message = await client.messages.create({
        model: "claude-opus-4-6",
        max_tokens: 1024,
        messages: [{ role: "user", content: "Hello" }],
      });
      ```
    </CodeGroup>

    **OpenAI-compatible SDKs** (OpenAI, Gemini, Mistral, Grok)

    Set `api_key` to your Metrion token. The SDK sends it as `Authorization: Bearer`.

    <CodeGroup>
      ```python Python theme={null}
      from openai import OpenAI

      client = OpenAI(
          api_key="sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          base_url="https://www.metrion.dev/api/proxy/openai",
      )

      response = client.chat.completions.create(
          model="gpt-4o",
          messages=[{"role": "user", "content": "Hello"}],
      )
      ```

      ```javascript Node.js theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({
        apiKey: "sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        baseURL: "https://www.metrion.dev/api/proxy/openai",
      });

      const response = await client.chat.completions.create({
        model: "gpt-4o",
        messages: [{ role: "user", content: "Hello" }],
      });
      ```
    </CodeGroup>

    Before using stored mode, add your provider API key in **Settings → Providers** or on the **Integrate** page.
  </Tab>

  <Tab title="Pass-through mode">
    In pass-through mode, you use your provider API key directly as the API key. Metrion detects that it is not a Metrion token and forwards it to the provider as-is. You do not need to configure any keys in Metrion's settings.

    Your usage is still tracked and logged in your dashboard.

    <Note>
      In pass-through mode, your provider key is forwarded directly to the provider and is never stored by Metrion.
    </Note>

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

      client = anthropic.Anthropic(
          api_key="sk-ant-your-actual-anthropic-key",
          base_url="https://www.metrion.dev/api/proxy",
      )
      ```

      ```javascript Node.js (OpenAI) theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({
        apiKey: "sk-your-actual-openai-key",
        baseURL: "https://www.metrion.dev/api/proxy/openai",
      });
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Token format

Metrion tokens follow this format:

```
sk-metrion-<32 hex characters>
```

Example: `sk-metrion-a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4`

## Security

<Warning>
  Never share your Metrion token or commit it to version control. Anyone with your token can make requests billed to your account.
</Warning>

If your token is compromised, regenerate it from **Settings → Metrion Key**. Your old token is immediately invalidated.
