GeminiAiBackend

public sealed class GeminiAiBackend : IAiBackend
IAiBackend implementation talking to Google's Gemini generateContent endpoint. The same conversation loop, tools, and docs corpus that drive the Anthropic backend work here -- only the wire format and a few naming conventions differ (role "model" instead of "assistant", systemInstruction as a top-level field, functionCall / functionResponse parts, no tool-use ids needed for round-tripping). Gemini has a no-credit-card free tier that's adequate for tyre-kicking and light usage. Quality is below Claude Opus on code generation but Flash is adequate for simple components and trivial to test.

Constructors

GeminiAiBackend

#
public GeminiAiBackend(string apiKey)
apiKey (string)

Properties

MaxRetries

#
public int MaxRetries { get; set; }
Maximum number of automatic 429 retries before giving up.

MaxTokens

#
public int MaxTokens { get; set; }
Maximum tokens the model may produce in a single turn.

Model

#
public string Model { get; set; }
Model identifier passed to the API. Defaults to the flagship -- a failed generation costs the user far more frustration than the cents saved by running on Flash. The retry loop already absorbs the lower RPM the Pro tier has on the free quota.

Provider

#
public AiProvider Provider { get; }
Provider

TranscriptCallback

#
public Action<string, string> TranscriptCallback { get; set; }
Optional hook invoked with (requestJson, responseBody) after every HTTP exchange, including non-2xx responses and retries. The host uses this to maintain a complete transcript of what was sent and received. Backends must invoke this before throwing on non-success status codes.
TranscriptCallback

Methods

Generate

#
public Task<AiBackendResponse> Generate(AiMessage[] history, AiTool[] tools, CancellationToken cancellation)
history (AiMessage[])
tools (AiTool[])
cancellation (CancellationToken)
Generate