Genkit Dart Model-Agnostic API: Switch Between Google, Anthropic, and OpenAI
How Genkit Dart's model-agnostic API lets you integrate and switch between Google Gemini, Anthropic Claude, OpenAI GPT, and compatible providers with minimal code changes.
Published on • September 18, 2026
AI Assistant

One of Genkit Dart’s most powerful features is its model-agnostic API. Instead of coupling your app to a single LLM provider, Genkit provides a unified interface that works across Google Gemini, Anthropic Claude, OpenAI GPT, and any OpenAI API-compatible service. This means you can switch providers with minimal code changes.
Why Model-Agnostic Matters
LLM providers differ in pricing, capabilities, latency, and availability. A model-agnostic approach gives you:
- Flexibility — Use the best model for each task without rewriting your app
- Cost optimization — Route requests to cheaper models for simple tasks
- Resilience — Fall back to an alternate provider if one goes down
- Future-proofing — Adopt new models as they launch without major refactors
Supported Providers
Genkit Dart ships with first-class plugins for:
| Provider | Package | Models |
|---|---|---|
| Google AI | genkit_google_genai | Gemini 3.1 Pro, Gemini Flash, Gemini Nano |
| Anthropic | genkit_anthropic | Claude Opus 4, Claude Sonnet 4, Claude Haiku |
| OpenAI | genkit_openai | GPT-4o, GPT-4, GPT-3.5-turbo, o1 |
| Chrome | genkit_chrome | Gemini Nano (on-device) |
| Firebase AI | genkit_firebase_ai | Vertex AI models via Firebase |
| Compatible | genkit_openai | Groq, DeepSeek, xAI/Grok, Together AI, Ollama |
Installation
Add the core package and whichever provider plugins you need:
dependencies:
genkit: ^0.13.0
genkit_google_genai: ^0.3.0
genkit_anthropic: ^0.3.0
genkit_openai: ^0.3.0
Setting Up Multiple Providers
Initialize Genkit with all the providers you want to use:
import 'dart:io';
import 'package:genkit/genkit.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
import 'package:genkit_anthropic/genkit_anthropic.dart';
import 'package:genkit_openai/genkit_openai.dart';
void main() async {
final ai = Genkit(
plugins: [
googleAI(),
anthropic(apiKey: Platform.environment['ANTHROPIC_API_KEY']!),
openAI(apiKey: Platform.environment['OPENAI_API_KEY']!),
],
);
}
Each plugin registers its models with Genkit. You reference them by name when calling ai.generate().
Switching Between Models
Once configured, switching between providers is a single-line change:
// Use Gemini
final gemini = await ai.generate(
model: googleAI.gemini('gemini-3.1-pro-preview'),
prompt: 'Summarize this document',
);
// Switch to Claude
final claude = await ai.generate(
model: anthropic.model('claude-opus-4.6'),
prompt: 'Summarize this document',
);
// Switch to GPT-4o
final gpt = await ai.generate(
model: openAI.model('gpt-4o'),
prompt: 'Summarize this document',
);
The prompt parameter stays identical. Only the model reference changes.
OpenAI-Compatible APIs
The genkit_openai plugin works with any service that implements the OpenAI API format. For example, to use Groq or DeepSeek:
// Groq
final ai = Genkit(plugins: [
openAI(
name: 'groq',
apiKey: Platform.environment['GROQ_API_KEY'],
baseUrl: 'https://api.groq.com/openai/v1',
models: [
CustomModelDefinition(
name: 'llama-3.3-70b-versatile',
info: ModelInfo(
label: 'Llama 3.3 70B',
supports: {
'multiturn': true,
'tools': true,
'systemRole': true,
},
),
),
],
),
]);
final response = await ai.generate(
model: openAI.model('llama-3.3-70b-versatile', namespace: 'groq'),
prompt: 'Hello from Groq!',
);
You can register multiple OpenAI-compatible backends side by side by giving each a unique name.
Consistent Features Across Providers
Genkit normalizes behavior across providers. These features work the same regardless of which model you choose:
- Streaming — Token-by-token output via
ai.generateStream() - Structured output — Typed Dart objects via
outputSchema - Tool calling — Models invoke your Dart functions during generation
- Multi-turn conversations — Message history handled automatically
- System prompts — Consistent system role support
Some provider-specific features (like Anthropic’s “thinking” mode) are exposed through provider-specific config options:
// Anthropic thinking
final response = await ai.generate(
model: anthropic.model('claude-sonnet-4-6'),
prompt: 'Solve this logic puzzle',
config: AnthropicOptions(
thinking: ThinkingConfig(budgetTokens: 2048),
),
);
Middleware for Resilience
Genkit’s middleware system lets you add retries, model fallback, and tool approval across any provider:
final ai = Genkit(
plugins: [googleAI(), anthropic(), openAI()],
middleware: [
// Retry on failure
retryMiddleware(maxRetries: 3),
// Fall back to Claude if Gemini fails
fallbackMiddleware(
fallbackModels: [anthropic.model('claude-sonnet-4-6')],
),
],
);
This means your app degrades gracefully instead of crashing when a provider has issues.
When to Choose Which Provider
| Use Case | Recommended Provider | Why |
|---|---|---|
| Rapid prototyping | Gemini Flash | Free tier, fast responses |
| Complex reasoning | Claude Opus | Strong multi-step reasoning |
| Tool-heavy agents | GPT-4o | Mature function calling |
| On-device inference | Gemini Nano | Runs locally via Chrome |
| Cost-sensitive tasks | Groq/DeepSeek | Low-cost API access |
| Enterprise compliance | Vertex AI via Firebase | Google Cloud security |
Conclusion
Genkit Dart’s model-agnostic API eliminates vendor lock-in while keeping your code clean and portable. By abstracting provider differences behind a unified interface, you can focus on building features instead of managing API quirks. Whether you start with Gemini and later add Claude as a fallback, or run GPT-4o for complex tasks and Gemini Flash for simple ones — Genkit makes it a configuration change, not a rewrite.
References:
- Genkit Dart Model Configuration — genkit.dev
- Anthropic Plugin for Genkit Dart — genkit.dev
- OpenAI Plugin for Genkit Dart — genkit.dev
- Genkit Dart GitHub — github.com