-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start Guide
Amayyas edited this page Jul 6, 2026
·
2 revisions
Get up and running with Flutter AI SDK in minutes!
import 'package:flutter_ai_sdk/flutter_ai_sdk.dart';
// Create an instance with your preferred provider
final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'your-api-key',
model: 'gpt-5.5',
),
);// Send a chat message
final response = await ai.chat('Hello! How are you?');
// Get the response text
print(response.text);
// Check token usage
print('Tokens used: ${response.usage?.totalTokens}');// Stream responses for real-time output
await for (final chunk in ai.streamChat('Tell me a story')) {
if (chunk.isDelta) {
print(chunk.delta); // Print each chunk as it arrives
}
}// Always dispose when done
ai.dispose();Here's a complete example you can copy and run:
import 'package:flutter_ai_sdk/flutter_ai_sdk.dart';
Future<void> main() async {
// Initialize
final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'your-api-key',
model: 'gpt-5.5',
temperature: 0.7,
systemPrompt: 'You are a helpful assistant.',
),
);
try {
// Simple chat
final response = await ai.chat('What is Flutter?');
print('AI: ${response.text}');
// Follow-up (context is maintained)
final followUp = await ai.chat('Can you give me a code example?');
print('AI: ${followUp.text}');
} catch (e) {
print('Error: $e');
} finally {
ai.dispose();
}
}The SDK makes it easy to switch between providers:
final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'your-openai-key',
model: 'gpt-5.5', // or 'gpt-5.4', 'gpt-5.4-mini'
),
);final ai = FlutterAI(
provider: AIProvider.anthropic,
config: AIConfig(
apiKey: 'your-anthropic-key',
model: 'claude-opus-4-8', // or 'claude-opus-4-8', 'claude-haiku-4-5'
),
);final ai = FlutterAI(
provider: AIProvider.googleAI,
config: AIConfig(
apiKey: 'your-google-key',
model: 'gemini-3.5-flash', // or 'gemini-3.5-flash'
),
);final ai = FlutterAI(
provider: AIProvider.anthropic,
config: AIConfig(
apiKey: 'your-key',
systemPrompt: 'You are a coding expert. Provide concise, accurate answers.',
),
);final ai = FlutterAI(
provider: AIProvider.openai,
config: AIConfig(
apiKey: 'your-key',
maxTokens: 1000, // Limit response length
temperature: 0.5, // More focused responses
),
);try {
final response = await ai.chat('Hello');
print(response.text);
} on AIAuthenticationError catch (e) {
print('Check your API key: ${e.message}');
} on AIRateLimitError catch (e) {
print('Rate limited. Retry after: ${e.retryAfter}');
} on AIError catch (e) {
print('AI Error: ${e.message}');
}Now that you have the basics, explore these topics:
- Configuration - All configuration options
- Streaming - Real-time streaming responses
- Multimodal Content - Images, audio, and more
- Function Calling - Tool/function support
- Error Handling - Comprehensive error management
Getting Started
Core Concepts
Advanced Features
API Reference
Examples
Other