Skip to main content
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:
# 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!');

Provider Variable Names

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, 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:
// 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 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

Next Steps