-
Notifications
You must be signed in to change notification settings - Fork 0
Providers
Amayyas edited this page Dec 5, 2025
·
3 revisions
Flutter AI SDK supports multiple AI providers through a unified interface.
enum AIProvider {
openai, // OpenAI (GPT-4, GPT-3.5, etc.)
anthropic, // Anthropic (Claude 3)
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-4-turbo |
128K | ✅ | ❌ | Complex tasks |
gpt-4o |
128K | ✅ | ✅ | Multimodal |
gpt-4o-mini |
128K | ✅ | ✅ | Cost-effective |
gpt-4 |
8K/32K | ❌ | ❌ | High accuracy |
gpt-3.5-turbo |
16K | ❌ | ❌ | Fast & cheap |
final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'sk-...',
model: 'gpt-4-turbo',
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-3-5-sonnet-latest |
200K | ✅ | Balanced |
claude-3-opus-latest |
200K | ✅ | Maximum capability |
claude-3-sonnet-20240229 |
200K | ✅ | General use |
claude-3-haiku-20240307 |
200K | ✅ | Speed & cost |
final ai = FlutterAI(
provider: AIProvider.anthropic,
config: AIConfig(
apiKey: 'sk-ant-...',
model: 'claude-3-5-sonnet-latest',
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-1.5-pro |
2M | ✅ | ✅ | Long context |
gemini-1.5-flash |
1M | ✅ | ✅ | Speed |
gemini-1.0-pro |
32K | ❌ | ❌ | Legacy |
gemini-1.0-pro-vision |
16K | ✅ | ❌ | Legacy vision |
final ai = FlutterAI(
provider: AIProvider.googleAI,
config: AIConfig(
apiKey: 'AIza...',
model: 'gemini-1.5-pro',
),
);
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 1.5 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-4-turbo',
AIProvider.anthropic => 'claude-3-5-sonnet-latest',
AIProvider.googleAI => 'gemini-1.5-pro',
},
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-4-turbo',
responseFormat: ResponseFormat.jsonObject,
);// Claude models excel at step-by-step reasoning
final config = AIConfig(
apiKey: 'your-key',
model: 'claude-3-opus-latest',
systemPrompt: 'Think step by step before answering.',
);// Gemini 1.5 supports up to 2M tokens
final config = AIConfig(
apiKey: 'your-key',
model: 'gemini-1.5-pro',
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