-
-
Notifications
You must be signed in to change notification settings - Fork 93
feat(gemini): add native API translator #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a2879c1
feat(gemini): add native API translator
SantiagoDePolonia b2527e3
fix(gemini): account for native usage pricing
SantiagoDePolonia ec2e666
fix(gemini): handle native stream edge cases
SantiagoDePolonia bfd9ee5
fix(gemini): address native api review findings
SantiagoDePolonia 1af3d32
fix(gemini): preserve models URL and document image limits
SantiagoDePolonia 841b0f8
docs: group provider guides in navigation
SantiagoDePolonia 5e3cacb
fix(gemini): derive native base from configured url
SantiagoDePolonia 32261b5
fix(gemini): emit one native stream usage chunk
SantiagoDePolonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| --- | ||
| title: "GoModel & Google Gemini" | ||
| description: "Configure Google Gemini in GoModel, choose native or OpenAI-compatible routing, and understand image_url behavior." | ||
| icon: "sparkles" | ||
| --- | ||
|
|
||
| GoModel routes Gemini chat and Responses API requests through Gemini's native | ||
| `generateContent` API by default. You can switch those requests back to | ||
| Gemini's OpenAI-compatible API when you need compatibility behavior that the | ||
| native adapter does not implement yet. | ||
|
|
||
| ## Configure Gemini | ||
|
|
||
| Env-only configuration is enough: | ||
|
|
||
| ```bash | ||
| export GEMINI_API_KEY="..." | ||
| ``` | ||
|
|
||
| Or in `config.yaml`: | ||
|
|
||
| ```yaml | ||
| providers: | ||
| gemini: | ||
| type: gemini | ||
| api_key: "${GEMINI_API_KEY}" | ||
| ``` | ||
|
|
||
| ## Native versus OpenAI-compatible mode | ||
|
|
||
| Gemini native mode is enabled by default: | ||
|
|
||
| ```bash | ||
| export USE_GOOGLE_GEMINI_NATIVE_API=true | ||
| ``` | ||
|
|
||
| Set it to `false` to route chat and Responses API requests through Gemini's | ||
| OpenAI-compatible `/chat/completions` endpoint: | ||
|
|
||
| ```bash | ||
| export USE_GOOGLE_GEMINI_NATIVE_API=false | ||
| ``` | ||
|
|
||
| `GEMINI_BASE_URL` configures the Gemini base. GoModel keeps separate internal | ||
| bases for native Gemini and the OpenAI-compatible API: | ||
|
|
||
| - native chat/models default: `https://generativelanguage.googleapis.com/v1beta` | ||
| - OpenAI-compatible default: `https://generativelanguage.googleapis.com/v1beta/openai` | ||
|
|
||
| When `GEMINI_BASE_URL` ends in `/openai`, GoModel uses that value for the | ||
| OpenAI-compatible client and derives the native base by stripping `/openai`. | ||
| Gemini embeddings, files, and batches still use the OpenAI-compatible surface. | ||
|
|
||
| ```bash | ||
| export GEMINI_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai" | ||
| ``` | ||
|
|
||
| <Note> | ||
| `USE_GOOGLE_GEMINI_NATIVE_API` decides whether chat and Responses API calls | ||
| use native Gemini or the OpenAI-compatible API. `GEMINI_BASE_URL` only | ||
| configures the upstream base URLs. | ||
| </Note> | ||
|
|
||
| ## Image URL behavior | ||
|
|
||
| Gemini models support image input, but the two GoModel routing modes handle | ||
| OpenAI-style `image_url` values differently. | ||
|
|
||
| In native mode, GoModel converts OpenAI-compatible messages to Gemini | ||
| `generateContent` requests. That adapter currently supports inline image data | ||
| only: | ||
|
|
||
| ```json | ||
| { | ||
| "type": "image_url", | ||
| "image_url": { | ||
| "url": "data:image/jpeg;base64,..." | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Remote image URLs such as `https://example.com/image.png` are rejected in native | ||
| mode. Google's native Gemini API supports inline image data and Files API | ||
| references; for URL-hosted images, Google's examples fetch the URL first and | ||
| send the bytes to `generateContent`. | ||
|
|
||
| Set `USE_GOOGLE_GEMINI_NATIVE_API=false` when you need GoModel to pass the | ||
| OpenAI-compatible `image_url` request shape through to Gemini's | ||
| OpenAI-compatible endpoint instead. Google documents image input for that | ||
| endpoint using the OpenAI `image_url` field. | ||
|
|
||
| ## Current support | ||
|
|
||
| Integrated: | ||
|
|
||
| - chat completions and streaming | ||
| - Responses API and streaming | ||
| - model listing through Gemini's native `/models` | ||
| - usage metadata normalization for native responses | ||
| - tool calls and function-call results | ||
| - inline image data via `data:` URLs in native mode | ||
|
|
||
| Not integrated in native mode yet: | ||
|
|
||
| - fetching remote `image_url` values | ||
| - uploading remote images through the Gemini Files API before a chat request | ||
|
|
||
| References: | ||
|
|
||
| - [Gemini image understanding](https://ai.google.dev/gemini-api/docs/image-understanding) | ||
| - [Gemini OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai) |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.