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

# Autoevals Scorer 401 Braintrust gateway error

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "Use case - Running evals via SDK with autoevals when both OPENAI_API_KEY and BRAINTRUST_API_KEY are set"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## Summary

**Issue:** Scorer returns `401 Braintrust gateway error: auth failed [401 Unauthorized]: Invalid API Key` when using `LLMClassifierFromTemplate` or other autoevals scorers.

**Cause:** `autoevals` defaults to `process.env.OPENAI_API_KEY || process.env.BRAINTRUST_API_KEY` as the API key and `process.env.OPENAI_BASE_URL || "https://api.braintrust.dev/v1/proxy"` as the base URL. When `OPENAI_API_KEY` is set, it is sent to the Braintrust proxy instead of `BRAINTRUST_API_KEY`, causing auth to fail.

**Resolution:** Initialize `autoevals` with a custom OpenAI client configured to use `BRAINTRUST_API_KEY` and the Braintrust gateway base URL.

## Resolution steps

### Initialize autoevals with a custom OpenAI client

Call `init()` before any evaluators run, passing a custom `OpenAI` client pointed at the Braintrust gateway with your `BRAINTRUST_API_KEY`.

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import OpenAI from "openai";
import { init } from "autoevals";

init({
  client: new OpenAI({
    apiKey: process.env.BRAINTRUST_API_KEY,
    baseURL: "https://gateway.braintrust.dev",
  }),
});
```

All autoevals scorers (including `LLMClassifierFromTemplate`) will use this client.
