Skip to content

GeminiClient ​

Category: LLM Providers

Source: gemini_client.dart

Streaming client for the Gemini Developer API (v1beta).

Talks to generativelanguage.googleapis.com via SSE streams. Unlike the other built-in LLM clients this also doubles as the data-parser that [GeminiProvider] delegates to — parseStreamEvents is exposed as a static for testability.

Classes ​

GeminiClient ​

Constructor ​

dart
GeminiClient({
    required this.apiKey,
    required this.model,
    required this.systemPrompt,
    String baseUrl = _defaultBaseUrl,
    http.Client Function()? requestClientFactory,
    this.reasoning = const ReasoningConfig(),
    this.maxOutputTokens,
    this.extraHeaders = const {},
  })

Properties ​

PropertyTypeDescription
apiKeyString
modelString
systemPromptString
reasoningReasoningConfig
maxOutputTokensint?Output cap for a turn, from the catalog's max_output_tokens.
extraHeadersMap<String, String>Extra request headers declared by the provider (request_headers:).

Methods ​

Stream<LlmChunk> stream(List<Message> messages, {List<Tool>? tools}) ​
`static Stream<LlmChunk> parseStreamEvents( ​
Stream&lt;Map&lt;String, dynamic&gt;&gt; events, {
bool showThoughts = true,

})`

Parse Gemini SSE event payloads into [LlmChunk]s.

Exposed as static for testability — callers feed already-decoded JSON objects (one per SSE data: event).

Released under the MIT License.