Environment Setup
Set API keys via environment variables and the providers automatically discover them.
Quick Start
# 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
// Keys are auto-discovered
final agent = Agent('openai');
final result = await agent.send('Hello!');
Platform Environment Variables
Provider | Variable | Required |
---|---|---|
OpenAI | OPENAI_API_KEY | ✅ |
Anthropic | ANTHROPIC_API_KEY | ✅ |
GEMINI_API_KEY | ✅ | |
Mistral | MISTRAL_API_KEY | ✅ |
Cohere | COHERE_API_KEY | ✅ |
OpenRouter | OPENROUTER_API_KEY | ✅ |
Together AI | TOGETHER_API_KEY | ✅ |
Lambda | LAMBDA_API_KEY | ✅ |
Ollama | None (local) | ❌ |
Agent Environment
The environment provided by your platform is a fall-back mechanism and it's not
always available. You can also set the environment variables on the Agent
itself:
// 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 always available. It's useful for loading from .env files, your cloud vendor's secrets database, Flutter's compile-time constant mechanism or wherever fine API keys are grown.
Next Steps
- Quick Start - Start building
- Providers - Available providers