ai_chat_sdk Pro
Streaming LLM chat UI with multi-provider support (OpenAI, Anthropic). Includes chat bubbles, streaming indicator, and
SharedPreferencespersistence.
Version: 1.0.0
Variables
| Variable | Type | Default | Description |
|---|---|---|---|
| aiChatProvider | enum | openai | Which AI provider(s) to include: openai, anthropic, both |
| defaultModel | string | gpt-4o-mini | Default model ID used for chat requests |
Generated Packages
| Package | Condition | Description |
|---|---|---|
ai_chat_api | Always | Contract + models (no provider deps) |
ai_chat_impl | Always | Orchestrator + chat UI pages and widgets |
ai_chat_openai_impl | openai or both | OpenAI streaming provider |
ai_chat_anthropic_impl | anthropic or both | Anthropic streaming provider |
Usage
Interactive
bash
archipelago generate ai_chat_sdkNon-interactive (CI)
bash
archipelago generate ai_chat_sdk --config my_config.jsonGenerated Structure
features/
└── ai_chat/
├── ai_chat_api/
│ └── lib/src/
│ └── models/
├── ai_chat_impl/
│ └── lib/src/
│ ├── data/
│ ├── di/
│ ├── presentation/
│ │ └── widgets/
│ └── router/
├── ai_chat_openai_impl/ # if aiChatProvider=openai or both
│ └── lib/src/
│ └── di/
└── ai_chat_anthropic_impl/ # if aiChatProvider=anthropic or both
└── lib/src/
└── di/Post-Install Steps
OpenAI
Set your API key in the DI module override:
dart
@module
abstract class AppAIModule {
@lazySingleton
AIChatConfig get aiChatConfig => const AIChatConfig(
apiKey: String.fromEnvironment('OPENAI_API_KEY'),
defaultModel: 'gpt-4o-mini',
);
}Anthropic
dart
@module
abstract class AppAIModule {
@lazySingleton
AIChatConfig get aiChatConfig => const AIChatConfig(
apiKey: String.fromEnvironment('ANTHROPIC_API_KEY'),
defaultModel: 'claude-3-haiku-20240307',
);
}WARNING
Never hardcode API keys in source code. Use compile-time String.fromEnvironment with your CI secrets or a .env file managed by shared_app_config.
Runtime API
dart
final chatSDK = getIt<AIChatSDK>();
// Start a streaming message:
final stream = chatSDK.sendMessage(
ChatMessage(role: MessageRole.user, content: 'Explain dependency injection'),
);
await for (final chunk in stream) {
print(chunk.delta); // partial text chunks
}
// Load persisted conversation history:
final history = await chatSDK.loadHistory();Persistence
Chat history is persisted via SharedPreferences. Conversations are stored per-session with an auto-generated session ID. Clear history via chatSDK.clearHistory().
Known Limitations
- Streaming is not supported in debug builds on iOS simulator (throttled by the network stack). Test on device or Android emulator for accurate streaming behaviour.
- The
bothprovider option generates both providers but only one is active at runtime — the orchestrator uses whicheverAIChatProviderHandleris registered first.