AIBridge class

The main entry point for Flutter AI Bridge.

AIBridge ties together providers, routing, conversation management, cost control, and caching into a single, easy-to-use API.

final bridge = AIBridge(
  providers: [
    OpenAIProvider(config: AIConfig(apiKey: 'sk-...', model: 'gpt-4o')),
    GeminiProvider(config: AIConfig(apiKey: 'AI...', model: 'gemini-2.0-flash')),
  ],
  strategy: RoutingStrategy.costOptimized,
  budget: TokenBudget(maxTokensPerDay: 100000),
);

final response = await bridge.complete('Hello, AI!');

Constructors

AIBridge({required List<AIProvider> providers, RoutingStrategy strategy = RoutingStrategy.primary, TokenBudget? budget, ResponseCache? cache, RetryHandler? retryHandler})

Properties

budget TokenBudget?
Optional token budget for cost control.
final
cache ResponseCache?
Optional response cache.
final
hashCode int
The hash code for this object.
no setterinherited
primaryProvider AIProvider
The primary (first) provider.
no setter
providers List<AIProvider>
The list of registered providers.
no setter
retryHandler RetryHandler
Retry handler for transient failures.
final
router AIRouter
The smart router handling provider selection.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tokenTracker TokenTracker
Token usage tracker.
final

Methods

complete(String prompt, {String? systemPrompt, int? maxTokens, double? temperature, bool useCache = false, List<AITool>? tools}) Future<AIResponse>
Sends a simple text completion request.
completeMessages(List<AIMessage> messages, {int? maxTokens, double? temperature, bool useCache = false, List<AITool>? tools}) Future<AIResponse>
Sends a completion request with full message history.
completeStream(String prompt, {String? systemPrompt, int? maxTokens, double? temperature, List<AITool>? tools}) Stream<AIStreamChunk>
Sends a streaming completion request.
createConversationManager({AIProvider? provider, int maxContextTokens = 4096}) ConversationManager
Creates a new conversation.
dispose() Future<void>
Releases all resources.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited