feat(gemini-adapter): prefer HTTP API when GEMINI_API_KEY is set#1365
Closed
abigail-atheryon wants to merge 2 commits intogarrytan:mainfrom
Closed
feat(gemini-adapter): prefer HTTP API when GEMINI_API_KEY is set#1365abigail-atheryon wants to merge 2 commits intogarrytan:mainfrom
abigail-atheryon wants to merge 2 commits intogarrytan:mainfrom
Conversation
added 2 commits
May 8, 2026 07:34
gemini-cli >=0.30 stores OAuth credentials at ~/.gemini/oauth_creds.json instead of the legacy ~/.config/gemini/ directory. The benchmark adapter's availability check now succeeds for users on recent gemini-cli releases who have authenticated via interactive login. Both paths are accepted so users on older versions still work.
The OAuth tier hits hard daily quotas on gemini-2.5-pro after a handful
of calls, and the CLI's stream-json output reports 0/0 tokens for
OAuth runs (so cost numbers were always $0.0000). Switch to the
Generative Language HTTP API directly when GEMINI_API_KEY (or
GOOGLE_API_KEY) is set — paid quotas, full usage data including
reasoning ("thoughts") tokens which are folded into output for accurate
cost estimation.
CLI fallback retained for free-OAuth users with no API key, so /benchmark
still works out of the box on a fresh install.
Auth precedence:
1. GEMINI_API_KEY → HTTP path (preferred)
2. GOOGLE_API_KEY → HTTP path
3. ~/.gemini/oauth_creds.json or ~/.config/gemini/ → CLI path
Owner
|
Thanks @abigail-atheryon — closing as deferred. Gemini HTTP API preference is a substantial behavioral change to the gemini adapter (112 lines). Companion #1362 (oauth path detect) shipped in a prior wave; the HTTP API switch warrants focused review on its own. Happy to revisit. |
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.
Summary
The OAuth tier hits hard daily quotas on
gemini-2.5-proafter a handful of calls (verified empirically — repeated/benchmark-modelsruns trip "You have exhausted your capacity on this model"). The CLI'sstream-jsonoutput also reports 0/0 tokens for OAuth runs, so cost numbers in the benchmark table were always $0.0000 — even when real billing was happening on paid accounts.This patch prefers the Generative Language HTTP API directly when
GEMINI_API_KEY(orGOOGLE_API_KEY) is set:thoughtsTokenCountfor reasoning models — folded into output token count so cost estimation matches the real billCLI fallback retained for free-OAuth users with no API key, so
/benchmark-modelsstill works out of the box on a fresh install.Stacked on
Stacks on top of #1362 (the OAuth path-detection fix). Targets
main; will rebase cleanly once #1362 lands.Auth precedence
GEMINI_API_KEY→ HTTP path (preferred)GOOGLE_API_KEY→ HTTP path~/.gemini/oauth_creds.jsonor~/.config/gemini/→ CLI pathVerification
Before (OAuth, gemini-2.5-pro):
```
gemini-2.5-pro 275.6s 0→0 $0.0000 ERROR rate_limit
```
After (HTTP, GEMINI_API_KEY set):
```
gemini-2.5-pro 12.7s 23→1294 $0.0065 OK
```
Same prompt, same gstack-model-benchmark invocation. Only
GEMINI_API_KEYwas added.Test plan
gemini-2.5-proandgemini-2.5-flashNotes
The HTTP rewrite is roughly the same shape as the existing GPT adapter (CLI shell-out) but uses
fetch()for the API-key path. No new deps, no test infra changes.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.