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

# Autoevals Scorer 401 Braintrust gateway error

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Any
> *
> * Use case - Running evals via SDK with autoevals when both OPENAI\_API\_KEY and BRAINTRUST\_API\_KEY are set

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.