Skip to content

Providers

Amayyas edited this page Jul 6, 2026 · 3 revisions

Providers

Flutter AI SDK supports multiple AI providers through a unified interface.

Available Providers

enum AIProvider {
  openai,    // OpenAI (GPT-5.5, GPT-5.4, etc.)
  anthropic, // Anthropic (Claude Opus, Sonnet, Haiku)
  googleAI,  // Google AI (Gemini)
}

Provider Comparison

Feature OpenAI Anthropic Google AI
Text Generation
Vision (Images)
Audio Input
Function Calling
Streaming
JSON Mode

OpenAI Provider

Supported Models

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

Usage

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);

Vision with OpenAI

final response = await ai.chatWithContent([
  const TextContent('What is in this image?'),
  const ImageContent.fromUrl(
    'https://example.com/image.jpg',
    detail: ImageDetail.high,
  ),
]);

Get API Key

🔗 platform.openai.com/api-keys


Anthropic Provider

Supported Models

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

Usage

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);
  }
}

Vision with Anthropic

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'),
]);

Get API Key

🔗 console.anthropic.com


Google AI Provider

Supported Models

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

Usage

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);

Multimodal with Google AI

// 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'),
]);

Get API Key

🔗 aistudio.google.com/app/apikey


Switching Providers

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),
);

Provider-Specific Features

OpenAI: Response Format

final config = AIConfig(
  apiKey: 'your-key',
  model: 'gpt-5.5',
  responseFormat: ResponseFormat.jsonObject,
);

Anthropic: Extended Thinking

// 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.',
);

Google AI: Long Context

// 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');

Related

Clone this wiki locally