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

# Multi-Provider Setup

> Route OpenAI, Anthropic, Groq, and Gemini through one endpoint.

## Overview

Lectr works with all your AI providers through a single proxy URL. Change `baseURL`
once per client — Lectr figures out where to send each request automatically.

```
your app → proxy.lectr.ai/v1 → OpenAI
                              → Anthropic
                              → Groq
                              → Gemini
                              → Azure OpenAI
```

One dashboard. Your entire AI spend. Every provider.

***

## Supported providers

| Provider      | Detection                 | Notes                                |
| ------------- | ------------------------- | ------------------------------------ |
| OpenAI        | Automatic                 | All current models                   |
| Anthropic     | Automatic                 | Via OpenAI-compatible endpoint       |
| Groq          | Automatic                 | Via OpenAI-compatible endpoint       |
| Google Gemini | Automatic                 | Via OpenAI-compatible endpoint       |
| Azure OpenAI  | `X-Lectr-Provider: azure` | Requires endpoint config — see below |

***

## How detection works

Lectr detects the provider from the `model` field in your request body. You do not
need to tell it which provider you're using — it already knows.

```
model: "gpt-4o"                     → OpenAI
model: "claude-3-5-sonnet-20241022" → Anthropic
model: "llama-3.1-70b-versatile"    → Groq
model: "gemini-1.5-pro"             → Gemini
```

If Lectr can't determine the provider, it defaults to OpenAI and logs
`provider_unknown` on the event. The request is never blocked.

***

## Setup

The integration is identical across providers — same URL, same header, same pattern.

<CodeGroup>
  ```typescript OpenAI (Node.js) theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY,
    baseURL: "https://proxy.lectr.ai/v1",
    defaultHeaders: {
      "X-Lectr-Key": process.env.LECTR_KEY,
    },
  });
  ```

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

  const client = new Anthropic({
    apiKey: process.env.ANTHROPIC_API_KEY,
    baseURL: "https://proxy.lectr.ai/v1",
    defaultHeaders: {
      "X-Lectr-Key": process.env.LECTR_KEY,
    },
  });
  ```

  ```typescript Groq (Node.js) theme={null}
  import Groq from "groq-sdk";

  const client = new Groq({
    apiKey: process.env.GROQ_API_KEY,
    baseURL: "https://proxy.lectr.ai/v1",
    defaultHeaders: {
      "X-Lectr-Key": process.env.LECTR_KEY,
    },
  });
  ```

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

  // Gemini exposes an OpenAI-compatible endpoint
  const client = new OpenAI({
    apiKey: process.env.GEMINI_API_KEY,
    baseURL: "https://proxy.lectr.ai/v1",
    defaultHeaders: {
      "X-Lectr-Key": process.env.LECTR_KEY,
    },
  });
  ```
</CodeGroup>

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

  client = OpenAI(
      api_key=os.environ["OPENAI_API_KEY"],
      base_url="https://proxy.lectr.ai/v1",
      default_headers={"X-Lectr-Key": os.environ["LECTR_KEY"]},
  )
  ```

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

  client = Anthropic(
      api_key=os.environ["ANTHROPIC_API_KEY"],
      base_url="https://proxy.lectr.ai/v1",
      default_headers={"X-Lectr-Key": os.environ["LECTR_KEY"]},
  )
  ```

  ```python Groq (Python) theme={null}
  from groq import Groq

  client = Groq(
      api_key=os.environ["GROQ_API_KEY"],
      base_url="https://proxy.lectr.ai/v1",
      default_headers={"X-Lectr-Key": os.environ["LECTR_KEY"]},
  )
  ```

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

  # Gemini exposes an OpenAI-compatible endpoint
  client = OpenAI(
      api_key=os.environ["GEMINI_API_KEY"],
      base_url="https://proxy.lectr.ai/v1",
      default_headers={"X-Lectr-Key": os.environ["LECTR_KEY"]},
  )
  ```
</CodeGroup>

Your provider API key passes through Lectr in memory and is forwarded directly.
It is never stored, never logged. See [Security & Trust](/security) for the full picture.

***

## Manual provider override

If Lectr misdetects a provider — or if you're using a model name that isn't in
its registry yet — use the `X-Lectr-Provider` header to override:

```typescript theme={null}
const response = await client.chat.completions.create(
  { model: "my-custom-model", messages },
  {
    headers: {
      "X-Lectr-Provider": "anthropic",
    },
  },
);
```

Valid values: `openai` `anthropic` `groq` `gemini` `azure`

***

## Azure OpenAI

Azure is the exception — every org has its own endpoint, so Lectr can't
auto-detect it from the model name alone. Two steps required.

**Step 1 — Configure your Azure endpoint in the dashboard**

Go to **Settings → Providers → Azure** and enter:

* Your Azure endpoint: `https://<resource-name>.openai.azure.com`
* API version: `2024-02-01` (or your preferred version)

**Step 2 — Add the provider header to your requests**

```typescript theme={null}
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.AZURE_OPENAI_API_KEY,
  baseURL: "https://proxy.lectr.ai/v1",
  defaultHeaders: {
    "X-Lectr-Key": process.env.LECTR_KEY,
    "X-Lectr-Provider": "azure",
  },
});
```

Lectr will route requests to your configured Azure endpoint and handle
the `api-key` header format Azure expects — your client doesn't need to know.

<Warning>
  Azure requests without a configured endpoint in the dashboard will return a
  400 error. Configure the endpoint first.
</Warning>

***

## Dashboard

Once traffic is flowing from multiple providers, your dashboard shows a unified
view across all of them.

**Model distribution** shows requests, cost, and latency per model across every
provider in a single table — filterable by provider:

| Model                     | Provider  | Requests |     Cost | Avg latency |
| ------------------------- | --------- | -------: | -------: | ----------: |
| `gpt-4o`                  | OpenAI    |    1,204 | \$142.00 |       1.38s |
| `claude-3-5-sonnet`       | Anthropic |      856 |  \$89.00 |       1.12s |
| `gpt-4o-mini`             | OpenAI    |      401 |   \$8.00 |       0.94s |
| `llama-3.1-70b-versatile` | Groq      |      214 |   \$2.10 |       0.78s |

**Cost breakdown** shows per-provider spend with period-over-period comparison.

**Provider health** shows recent error rates per provider — derived from your
own traffic, not external status pages.

***

## Model recommendations across providers

Lectr's recommendation engine works across all supported providers. Recommendations
stay within provider — it won't suggest switching from `claude-3-5-sonnet` to
`gpt-4o-mini`. Cross-provider quality comparisons require data Lectr doesn't have.

Within a provider, the usual rules apply:

```
claude-3-opus     → claude-3-5-sonnet (conservative)
claude-3-opus     → claude-3-5-haiku  (aggressive)
llama-3.1-70b     → llama-3.1-8b      (moderate)
gemini-1.5-pro    → gemini-1.5-flash  (moderate)
```

Add [task type tagging](/guides/task-types) to get high-confidence recommendations
rather than heuristic ones.

***

## What's coming

Routing rules (coming soon) will let you automatically route requests to specific
provider + model combinations based on feature tag or task type — without touching
your code.

***

## Reference

| Header       | `X-Lectr-Provider`                           |
| ------------ | -------------------------------------------- |
| Required     | Only for Azure                               |
| Valid values | `openai` `anthropic` `groq` `gemini` `azure` |
| Default      | Auto-detected from model name                |
| Fallback     | Defaults to `openai` if detection fails      |

***

## FAQ

<AccordionGroup>
  <Accordion title="Can I use multiple providers in the same org?">
    Yes — that's the whole point. All traffic from all providers flows through
    the same org key and appears in the same dashboard.
  </Accordion>

  <Accordion title="Do I need a separate org key per provider?">
    No. One org key covers all providers.
  </Accordion>

  <Accordion title="What if a new model isn't detected correctly?">
    Use `X-Lectr-Provider` to override. New models are added to the detection
    registry regularly — if you're missing one, let us know.
  </Accordion>

  <Accordion title="Are provider API keys stored anywhere?">
    No. Your provider API key passes through Lectr in memory for the duration of
    the request and is forwarded directly to your provider. It is never persisted,
    never logged, never included in event metadata.
  </Accordion>

  <Accordion title="Does Lectr support streaming for all providers?">
    Yes. Streaming works identically across all supported providers.
  </Accordion>
</AccordionGroup>
