# AI Provider Configuration

## Choose and configure the LLM provider that powers Donobu's autonomous test flows, including Donobu hosted, Anthropic, OpenAI, and Google Gemini.

Donobu delegates all AI reasoning to an external large language model. You choose the provider by setting environment variables before running your tests. No code changes are required to switch providers.

### Supported providers

#### Donobu hosted (recommended)

The simplest option is to use a Donobu API key. Obtain one from the [Donobu website](/content/home/index.html) and set it:

```bash
export DONOBU_API_KEY=your_key_here
```

Using the Donobu-hosted provider also enables automatic result syncing to the Donobu cloud.

#### Anthropic

```bash
export ANTHROPIC_API_KEY=your_key_here

# Optional: pin a specific model (defaults to the latest recommended model)
export ANTHROPIC_MODEL_NAME=claude-sonnet-4-5
```

#### Google Gemini

```bash
export GOOGLE_GENERATIVE_AI_API_KEY=your_key_here

# Optional: pin a specific model (defaults to the latest recommended model)
export GOOGLE_GENERATIVE_AI_MODEL_NAME=gemini-2.5-flash
```

#### OpenAI

```bash
export OPENAI_API_KEY=your_key_here

# Optional: pin a specific model (defaults to the latest recommended model)
export OPENAI_API_MODEL_NAME=gpt-5.1
```

## Priority order

When multiple provider keys are present, Donobu selects the provider in this order:

1. `DONOBU_API_KEY`
2. `ANTHROPIC_API_KEY`
3. `GOOGLE_GENERATIVE_AI_API_KEY`
4. `OPENAI_API_KEY`

To avoid ambiguity, set only the variables for the provider you intend to use.

## Per-test and per-call overrides

You can override the provider for an entire test file using `test.use()`:

```ts
import { anthropicClientFixture, test } from 'donobu';

// All tests in this file use the Anthropic client
test.use({ gptClient: anthropicClientFixture('claude-sonnet-4-6') });

test('my test', async ({ page }) => {
  await page.ai('Complete the checkout flow');
});
```

The following fixture factories are available for this purpose:

| Factory | Provider | GptClient class |
| --- | --- | --- |
| `donobuGptClientFixture(apiKey?)` | Donobu hosted | `DonobuGptClient` |
| `anthropicClientFixture(modelName, apiKey?)` | Anthropic | `AnthropicGptClient` |
| `googleGeminiClientFixture(modelName, apiKey?)` | Google Gemini | `GoogleGeminiGptClient` |
| `openAiClientFixture(modelName, apiKey?)` | OpenAI | `OpenAiGptClient` |

Or override for a single `page.ai()` call using the `gptClient` option:

```ts
import { AnthropicGptClient, test } from 'donobu';

test('my test', async ({ page }) => {
  await page.ai('Complete the checkout flow', {
    gptClient: new AnthropicGptClient({
      type: 'ANTHROPIC',
      modelName: 'claude-sonnet-4-6',
      apiKey: process.env.ANTHROPIC_API_KEY!,
    }),
  });
});
```

## Storing API keys securely

Never commit API keys to version control. Use:

- **Local development**: a `.env` file — see [Playwright's guide to `.env` files](https://playwright.dev/docs/test-parameterize#env-files) for details
- **CI/CD**: repository secrets — see [CI/CD Integration](/content/docs/playwright/ci-cd/index.html) for GitHub Actions examples
