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

# Request Headers

> Optional and required headers for Metrion proxy requests.

## Required headers

Your SDK sets these headers automatically when you configure the `api_key` and `base_url`. You do not need to set them manually.

| Header          | Provider                      | Value                                         |
| --------------- | ----------------------------- | --------------------------------------------- |
| `x-api-key`     | Anthropic                     | Your Metrion token or Anthropic API key       |
| `Authorization` | OpenAI, Gemini, Mistral, Grok | `Bearer <your-metrion-token-or-provider-key>` |
| `Content-Type`  | All                           | `application/json`                            |

## Metrion-specific headers

### x-metrion-user

<ParamField header="x-metrion-user" type="string">
  An identifier for the user, bot, or workflow that made the request. This value appears in the **Requester** column in your logs and can be used to filter by requester.

  Use any string that makes sense for your setup — a user ID, an agent name, or a workflow label.
</ParamField>

This header is optional but strongly recommended when you run multiple users, agents, or workflows through the same Metrion token.

**What it enables:**

* Filter your logs by requester in the dashboard
* Track costs per user, per agent, or per workflow
* Identify which part of your system is responsible for a given request

<Tip>
  If you run multiple AI agents or n8n workflows through Metrion, add `x-metrion-user` to each one with a distinct identifier. This makes it easy to pinpoint cost spikes or errors in your logs.
</Tip>

**Examples:**

<CodeGroup>
  ```javascript Node.js (Anthropic SDK) theme={null}
  import Anthropic from "@anthropic-ai/sdk";

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

  ```python Python (Anthropic SDK) theme={null}
  import anthropic

  client = anthropic.Anthropic(
      api_key="sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      base_url="https://www.metrion.dev/api/proxy",
      default_headers={"x-metrion-user": "user_123"},
  )
  ```

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

  const client = new OpenAI({
    apiKey: "sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    baseURL: "https://www.metrion.dev/api/proxy/openai",
    defaultHeaders: {
      "x-metrion-user": "n8n-workflow-payments",
    },
  });
  ```

  ```python Python (OpenAI SDK) theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      base_url="https://www.metrion.dev/api/proxy/openai",
      default_headers={"x-metrion-user": "n8n-workflow-payments"},
  )
  ```
</CodeGroup>

### x-metrion-cache

<ParamField header="x-metrion-cache" type="string">
  Enable response caching for the request. Metrion hashes the request (model + message content) and stores the response. Identical future requests return the cached response instantly, with zero tokens consumed.

  Accepted values:

  * `true` — serve from cache if a match exists; cache the response on a miss
  * `refresh` — bypass the cache and always fetch a fresh response, then update the cache
</ParamField>

Use `Cache-Control: max-age=<seconds>` alongside `x-metrion-cache: true` to control how long the cached response is retained (default: 7 days, maximum: 365 days).

When a cached response is returned, the proxy sets `x-metrion-cache: HIT` on the response and records the request in your logs with a **Cached** badge — no tokens are billed for cached responses.

<CodeGroup>
  ```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",
    defaultHeaders: {
      "x-metrion-cache": "true",
      "Cache-Control": "max-age=86400", // cache for 24 hours
    },
  });
  ```

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

  client = anthropic.Anthropic(
      api_key="sk-metrion-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      base_url="https://www.metrion.dev/api/proxy",
      default_headers={
          "x-metrion-cache": "true",
          "Cache-Control": "max-age=86400",
      },
  )
  ```
</CodeGroup>

<Tip>
  Use `x-metrion-cache: true` for repeated queries with identical prompts — classification tasks, fixed-input workflows, or test suites. Cached responses return in milliseconds and cost zero tokens.
</Tip>

## Forwarded headers

Metrion forwards the standard provider headers required by each API. For Anthropic, the `anthropic-version` header is set server-side to a fixed, tested version — do not set it manually in your requests, as Metrion will override it.
