Repository navigation
Let Gemini clients use any provider - #27
Merged
Merged
Conversation
Gemini generateContent requests are translated to Anthropic Messages (ported from CPA's Gemini-to-Claude translator) and sent to a Claude key or on to the provider's own format. Answers stream back as Gemini chunks, over SSE with ?alt=sse or as one JSON array without, or come back whole. countTokens gets an estimate. With every client format now reaching every provider, the servable() check goes away.
…logins to every client
…-y9ekd4 # Conflicts: # free/README.md # free/src/app.ts
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.
What
Gemini clients (
/v1beta/models/{model}:generateContent,:streamGenerateContent,:countTokens) could only reach Gemini and Vertex. Now they reach every provider through Anthropic Messages, which completes the client-format work started in #23. Every client format now reaches every provider.free/src/gemini-claude.ts(new), ported from CPA'stranslator/claude/gemini:systemInstruction,contentswith text,inlineData/inline_data(images and documents) and httpsfileData. Gemini's own thought parts are dropped, since their signatures can't be replayed to Claude.functionCallbecomestool_use, with ids synthesized when the client sent none.functionResponsepairs with its call by id or by name in order; unanswered calls get an "interrupted" error result and orphaned results become text. Also handled:functionDeclarations(parametersorparametersJsonSchema, with Gemini's upper-case types lowered),toolConfigmodes (NONE, ANY, one allowed name),maxOutputTokens,topP,stopSequences,thinkingConfig(level or budget mapped to Claude thinking), andresponseMimeType: application/jsonas a system instruction.GeminiStreamemits Gemini chunks (text,thought: trueparts,functionCallwith id, a finalfinishReasonandusageMetadata). It writes SSE with?alt=sseand one streamed JSON array without it, as Google's API does.geminiResponsecoversgenerateContent.countTokensreturns an estimate.free/src/app.ts:viaClaudeMessagesnow serves Gemini clients too.servable()is gone, since every combination is served.free/src/proxy.ts: a Gemini-shaped 403 is nowPERMISSION_DENIED.Security and safety
fileDataURLs are passed on only when https, and the Worker never fetches them; Anthropic does.?key=is never forwarded.Tests
npm run verify: typecheck, lint and 205 tests pass.free/test/gemini-claude.test.tscovers request translation, call/result pairing, thinking mapping, SSE and JSON-array streaming, cut-off streams and whole responses.app.test.tsadds:Generated by Claude Code