-
Notifications
You must be signed in to change notification settings - Fork 0
API AIConfig
Configuration class for AI requests.
const AIConfig({
required String apiKey,
String? model,
int? maxTokens,
double? temperature,
double? topP,
double? frequencyPenalty,
double? presencePenalty,
List<String>? stopSequences,
String? systemPrompt,
List<Tool>? tools,
ToolChoice? toolChoice,
ResponseFormat? responseFormat,
String? baseUrl,
Duration? timeout,
Map<String, String>? headers,
Map<String, dynamic>? metadata,
})final String apiKeyRequired. API key for authentication with the provider.
final String? modelThe model to use. If not specified, uses provider's default.
| Provider | Default Model |
|---|---|
| OpenAI | gpt-5.4-mini |
| Anthropic | claude-sonnet-5 |
| Google AI | gemini-3.1-flash-lite |
final int? maxTokensMaximum number of tokens to generate in the response.
final double? temperatureSampling temperature (0.0 to 2.0). Higher values = more random.
| Value | Behavior |
|---|---|
| 0.0 | Deterministic, focused |
| 0.7 | Balanced (default) |
| 1.0+ | Creative, varied |
final double? topPNucleus sampling parameter (0.0 to 1.0). Alternative to temperature.
final double? frequencyPenaltyReduces repetition of frequent tokens (-2.0 to 2.0).
final double? presencePenaltyReduces repetition of any used tokens (-2.0 to 2.0).
final List<String>? stopSequencesSequences that stop text generation.
final config = AIConfig(
apiKey: 'key',
stopSequences: ['END', '\n\n', '```'],
);final String? systemPromptSystem instructions for the AI.
final config = AIConfig(
apiKey: 'key',
systemPrompt: 'You are a helpful coding assistant. Always provide examples.',
);final List<Tool>? toolsAvailable tools/functions for the AI to call.
final ToolChoice? toolChoiceHow the model should use tools.
ToolChoice.auto // Let the model decide (default)
ToolChoice.none // Never use tools
ToolChoice.required // Must use a tool
ToolChoice.function('name') // Use specific toolfinal ResponseFormat? responseFormatOutput format configuration.
ResponseFormat.text // Plain text (default)
ResponseFormat.jsonObject // JSON outputfinal String? baseUrlCustom base URL for the API (for proxies or custom endpoints).
final config = AIConfig(
apiKey: 'key',
baseUrl: 'https://my-proxy.com/v1',
);final Duration? timeoutRequest timeout duration. Default is 60 seconds.
final config = AIConfig(
apiKey: 'key',
timeout: Duration(seconds: 120),
);final Map<String, String>? headersCustom HTTP headers to include in requests.
final config = AIConfig(
apiKey: 'key',
headers: {
'X-Custom-Header': 'value',
'X-Request-ID': uuid(),
},
);final Map<String, dynamic>? metadataAdditional metadata for custom purposes.
Creates a copy with updated fields.
AIConfig copyWith({
String? apiKey,
String? model,
int? maxTokens,
double? temperature,
double? topP,
double? frequencyPenalty,
double? presencePenalty,
List<String>? stopSequences,
String? systemPrompt,
List<Tool>? tools,
ToolChoice? toolChoice,
ResponseFormat? responseFormat,
String? baseUrl,
Duration? timeout,
Map<String, String>? headers,
Map<String, dynamic>? metadata,
})final baseConfig = AIConfig(
apiKey: 'key',
model: 'gpt-5.5',
temperature: 0.7,
);
// Create variations
final creativeConfig = baseConfig.copyWith(temperature: 1.2);
final fastConfig = baseConfig.copyWith(model: 'gpt-5.4-mini');final config = AIConfig(
apiKey: 'your-api-key',
);final config = AIConfig(
apiKey: 'your-api-key',
model: 'gpt-5.5',
maxTokens: 2000,
temperature: 0.7,
topP: 0.9,
frequencyPenalty: 0.5,
presencePenalty: 0.5,
stopSequences: ['END'],
systemPrompt: 'You are a helpful assistant.',
tools: [weatherTool, calculatorTool],
toolChoice: ToolChoice.auto,
responseFormat: ResponseFormat.text,
timeout: Duration(seconds: 60),
headers: {'X-Request-ID': 'abc123'},
metadata: {'user_id': '12345'},
);final codeConfig = AIConfig(
apiKey: 'key',
model: 'gpt-5.5',
temperature: 0.0, // Deterministic
maxTokens: 2000,
stopSequences: ['```\n\n'],
systemPrompt: '''
You are a code generator.
- Output only valid, working code
- Include comments
- Follow best practices
''',
);final creativeConfig = AIConfig(
apiKey: 'key',
model: 'claude-opus-4-8',
temperature: 1.0,
topP: 0.95,
maxTokens: 4000,
systemPrompt: 'You are a creative storyteller.',
);final jsonConfig = AIConfig(
apiKey: 'key',
model: 'gpt-5.5',
temperature: 0.3,
responseFormat: ResponseFormat.jsonObject,
systemPrompt: '''
Always respond with valid JSON in this format:
{
"answer": "your answer",
"confidence": 0.0-1.0,
"sources": ["list", "of", "sources"]
}
''',
);- Configuration - Configuration guide
- API-FlutterAI - Main class reference
- Providers - Provider-specific settings
Getting Started
Core Concepts
Advanced Features
API Reference
Examples
Other