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

# Environment Setup

> Set API keys via environment variables and the providers automatically discover them.

While you can configure providers with API keys manually, I wouldn't recommend
it. It's much easier to just use the conventionally API key name and let your
provider grab it from the environment.

## Quick Start

You can just set up the API key values in your environment and let dartantic
find them automatically:

```bash theme={null}
# Set your API keys
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="AI..."

# Use without configuration
dart run
```

```dart theme={null}
// Keys are auto-discovered
final agent = Agent('openai');
final result = await agent.send('Hello!');
```

## Provider Variable Names

| Provider            | Variable             | Required |
| ------------------- | -------------------- | -------- |
| OpenAI              | `OPENAI_API_KEY`     | ✅        |
| Anthropic           | `ANTHROPIC_API_KEY`  | ✅        |
| Google              | `GEMINI_API_KEY`     | ✅        |
| Mistral             | `MISTRAL_API_KEY`    | ✅        |
| Cohere              | `COHERE_API_KEY`     | ✅        |
| OpenRouter          | `OPENROUTER_API_KEY` | ✅        |
| xAI / xAI Responses | `XAI_API_KEY`        | ✅        |
| Ollama              | None (local)         | ❌        |

The optional **Firebase AI** add-on ([`dartantic_firebase_ai`](https://pub.dev/packages/dartantic_firebase_ai))
does not use these environment variables; it relies on Firebase configuration,
and the Google AI backend uses API keys configured in the Firebase project.

## Agent Environment

The environment provided by your platform is a fall-back mechanism and it's not
always available, e.g. when you're running dartantic in your Flutter web app.
The first place that dartantic looks is the environment supplied by the `Agent`
class itself:

```dart theme={null}
// Set programmatically
Agent.environment['OPENAI_API_KEY'] = 'sk-...';
Agent.environment['ANTHROPIC_API_KEY'] = 'sk-ant-...';
```

The agent's environment is the default place for providers to look for API keys
and it's available on all platforms. It's useful for loading from .env files,
your cloud vendor's secrets database, [Flutter's compile-time constant
mechanism](https://dart.dev/language/variables#final-and-const) or wherever fine
API keys are grown. Only if the provider's key isn't found there will your
platforms's environment be checked (if your platform has an environment, that
is).

## Examples

* [Environment
  setup](https://github.com/csells/dartantic_ai/blob/main/packages/dartantic_ai/example/bin/chat.dart)

## Next Steps

* [Quick Start](/quick-start) - Start building
* [Providers](/providers) - Available providers
