Repository navigation
fix(gemini): migrate to google.golang.org/genai SDK - #127
Merged
Merged
Conversation
The provider used github.com/google/generative-ai-go, which Google deprecated and which cannot parse Gemini 3.x responses: every stream ended in "invalid character ']'" (turning complete answers into errors), and function-calling turns came back as an unknown finish reason with no text. - Rewrite the Gemini provider on google.golang.org/genai. - Carry Gemini 3 thought signatures on ToolCall.ThoughtSignature and replay them, so multi-step tool loops are accepted. - Give each function call a unique ID and Index (parallel calls to the same tool used to collide on the function name). - Without declared tools, replay tool history as text (Gemini rejects function-call history when no tools are declared). - Report usage (thinking tokens count as completion), pass tool schemas through as raw JSON Schema, surface the API's real error and status, skip thought parts, honour BaseURL and CustomHeaders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devops-bda
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Gemini provider used
github.com/google/generative-ai-go, which Google has deprecated. It can't parse current Gemini 3.x responses:invalid character ']' looking for beginning of value, even after a complete answer, so callers treat good answers as errors.FinishReason(10)) with no content.Older models that worked with that SDK (e.g.
gemini-2.5-flash) are retired for new users, so a model change can't fix it. In cai-llm-router this broke the Gemini model and thetool-retry-fallback(Groq → Gemini) recovery.Changes
google.golang.org/genai(v1.73.0) inproviders/gemini; the old SDK is removed fromgo.mod.ToolCall.ThoughtSignaturefield (json:"thought_signature,omitempty"), set from the function-call part and replayed in history. Gemini 3 rejects follow-up tool-loop requests without it. Empty for every other provider.parametersJsonSchema), so keywords aren't dropped.APIError.BaseURLandCustomHeadersare honoured.No other provider changes. Only cai-llm-router depends on this module.
Tests
New
providers/gemini/provider_test.goagainst a fake Gemini server (no key needed):Complete()works;go vet ./...clean; all packages pass.Live check: cai-llm-router run locally against this branch (
go.modreplace) with the real API andgemini-3.5-flash-lite:🤖 Generated with Claude Code