-
Notifications
You must be signed in to change notification settings - Fork 0
Providers
Amayyas edited this page Jul 6, 2026
·
3 revisions
Flutter AI SDK supports multiple AI providers through a unified interface.
enum AIProvider {
openai, // OpenAI (GPT-5.5, GPT-5.4, etc.)
anthropic, // Anthropic (Claude Opus, Sonnet, Haiku)
googleAI, // Google AI (Gemini)
}| Feature | OpenAI | Anthropic | Google AI |
|---|---|---|---|
| Text Generation | ✅ | ✅ | ✅ |
| Vision (Images) | ✅ | ✅ | ✅ |
| Audio Input | ✅ | ❌ | ✅ |
| Function Calling | ✅ | ✅ | ✅ |
| Streaming | ✅ | ✅ | ✅ |
| JSON Mode | ✅ | ✅ | ✅ |
| Model | Context | Vision | Audio | Best For |
|---|---|---|---|---|
gpt-5.5 |
400K | ✅ | ❌ | Complex tasks, coding |
gpt-5.4 |
400K | ✅ | ✅ | Affordable all-rounder |
gpt-5.4-mini |
400K | ✅ | ✅ | Cost-effective |
gpt-5.4-nano |
400K | ✅ | ❌ | Fast & cheap |
gpt-5.1 |
400K | ✅ | ❌ | Agentic coding |
final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'sk-...',
model: 'gpt-5.5',
temperature: 0.7,
maxTokens: 1000,
),
);
final response = await ai.chat('Explain quantum computing');
print(response.text);final response = await ai.chatWithContent([
const TextContent('What is in this image?'),
const ImageContent.fromUrl(
'https://example.com/image.jpg',
detail: ImageDetail.high,
),
]);🔗 platform.openai.com/api-keys
| Model | Context | Vision | Best For |
|---|---|---|---|
claude-opus-4-8 |
1M | ✅ | Maximum capability |
claude-sonnet-5 |
1M | ✅ | General use, coding |
claude-sonnet-4-6 |
1M | ✅ | Previous generation |
claude-haiku-4-5 |
200K | ✅ | Speed & cost |
final ai = FlutterAI(
provider: AIProvider.anthropic,
config: AIConfig(
apiKey: 'sk-ant-...',
model: 'claude-opus-4-8',
systemPrompt: 'You are a helpful coding assistant.',
maxTokens: 4096,
),
);
// Streaming response
await for (final chunk in ai.streamChat('Write a haiku about coding')) {
if (chunk.isDelta) {
stdout.write(chunk.delta);
}
}import 'dart:io';
import 'dart:typed_data';
// From file
final bytes = await File('image.png').readAsBytes();
final response = await ai.chatWithContent([
const TextContent('Describe this image'),
ImageContent.fromBytes(bytes, mimeType: 'image/png'),
]);| Model | Context | Vision | Audio | Best For |
|---|---|---|---|---|
gemini-3.5-flash |
1M | ✅ | ✅ | Speed & quality |
gemini-3.1-pro-preview |
1M | ✅ | ✅ | Maximum capability |
gemini-3.1-flash-lite |
1M | ✅ | ❌ | Lowest cost |
final ai = FlutterAI(
provider: AIProvider.googleAI,
config: AIConfig(
apiKey: 'AIza...',
model: 'gemini-3.5-flash',
),
);
final response = await ai.chat('What are the planets in our solar system?');
print(response.text);// Analyze image
final response = await ai.chatWithContent([
const TextContent('Analyze this image in detail'),
const ImageContent.fromUrl('https://example.com/chart.png'),
]);
// With audio (Gemini only)
final audioBytes = await File('audio.mp3').readAsBytes();
final response = await ai.chatWithContent([
const TextContent('Transcribe this audio'),
AudioContent.fromBytes(audioBytes, mimeType: 'audio/mp3'),
]);🔗 aistudio.google.com/app/apikey
The SDK makes it easy to switch providers with minimal code changes:
// Configuration factory
AIConfig createConfig(AIProvider provider, String apiKey) {
return AIConfig(
apiKey: apiKey,
model: switch (provider) {
AIProvider.openai => 'gpt-5.5',
AIProvider.anthropic => 'claude-opus-4-8',
AIProvider.googleAI => 'gemini-3.5-flash',
},
temperature: 0.7,
maxTokens: 1000,
);
}
// Usage
final openai = FlutterAI(
provider: AIProvider.openai,
config: createConfig(AIProvider.openai, openaiKey),
);
final anthropic = FlutterAI(
provider: AIProvider.anthropic,
config: createConfig(AIProvider.anthropic, anthropicKey),
);final config = AIConfig(
apiKey: 'your-key',
model: 'gpt-5.5',
responseFormat: ResponseFormat.jsonObject,
);// Claude models excel at step-by-step reasoning
final config = AIConfig(
apiKey: 'your-key',
model: 'claude-opus-4-8-latest',
systemPrompt: 'Think step by step before answering.',
);// Gemini 3 supports up to 1M tokens
final config = AIConfig(
apiKey: 'your-key',
model: 'gemini-3.5-flash',
maxTokens: 8192,
);
// Analyze a large document
final doc = await File('large-doc.txt').readAsString();
final response = await ai.chat('Summarize this: $doc');- OpenAI Provider - Detailed OpenAI guide
- Anthropic Provider - Detailed Anthropic guide
- Google AI Provider - Detailed Google AI guide
- Configuration - Configuration options
Getting Started
Core Concepts
Advanced Features
API Reference
Examples
Other