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

ProviderVariableRequired
OpenAIOPENAI_API_KEY
AnthropicANTHROPIC_API_KEY
GoogleGEMINI_API_KEY
MistralMISTRAL_API_KEY
CohereCOHERE_API_KEY
OpenRouterOPENROUTER_API_KEY
Together AITOGETHER_API_KEY
LambdaLAMBDA_API_KEY
OllamaNone (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