Allow using Gemini CLI for free Gemini requests
I'm going to apologise in advance if this is a unreasonable request, but Gemini CLI has a very generous free tier and it would be quite nice to route Gemini requests through it (especially since it costs Google the same amount of money anyway)
Note that the authentication scheme Gemini CLI uses is public: https://github.com/google-gemini/gemini-cli/blob/main/packages/core/src/code_assist/oauth2.ts
this would honestly be a great PR it might fit in very nicely into how claude pro/max is implemented
one tui to rule them all...
Does something like this work?
got it working with with custom ai sdk provider. here is my config ~/.config/opencode.json.
this needs you to use gemini cli to login initially
https://gist.github.com/aryasaatvik/4eb60e53290b4d483bd1fe40dae6fc48
any update? I open gist from @aryasaatvik but seems not working anymore too.
With Qwen Coder CLI now out, this is becoming very interesting:
- Gemini CLI and Qwen CLI are very similar (Qwen CLI is fork of the Gemini cli code)
- Both provide very generous daily limits of free requests! They are practically free for individuals ....
- Both use OAuth for the free personal access, not tokens.
I suspect more (Chineses) AI labs will clone Gemini CLI and couple it with OAuth + generaous free daily usage quota.
That is an opportunity for OpenCode to rule them all, @thdxr
In case anyone else is also trying to get this working, I was able to do it using https://github.com/router-for-me/CLIProxyAPI.
I configured it per the README on that project, and set up the provider in opencode. The only quirk is that I was getting invalid JSON errors when setting it up as an OpenAI compatible provider, it needed to be configured as a google provider:
"provider": {
"cli-proxy-api-google": {
"npm": "@ai-sdk/google",
"name": "CLIProxyAPI (Google)",
"options": {
"baseURL": "http://localhost:8317/v1beta",
"apiKey": "<key you set in the CLIProxyAPI config>"
},
"models": {
"gemini-2.5-pro": {
"name": "Gemini 2.5 Pro"
},
"gemini-2.5-flash": {
"name": "Gemini 2.5 Flash"
},
"gemini-2.5-flash-lite": {
"name": "Gemini 2.5 Flash Lite"
}
}
}
}
Hope this helps
In case anyone else is also trying to get this working, I was able to do it using https://github.com/router-for-me/CLIProxyAPI.
I configured it per the README on that project, and set up the provider in opencode. The only quirk is that I was getting invalid JSON errors when setting it up as an OpenAI compatible provider, it needed to be configured as a google provider:
"provider": { "cli-proxy-api-google": { "npm": "@ai-sdk/google", "name": "CLIProxyAPI (Google)", "options": { "baseURL": "http://localhost:8317/v1beta", "apiKey": "<key you set in the CLIProxyAPI config>" }, "models": { "gemini-2.5-pro": { "name": "Gemini 2.5 Pro" }, "gemini-2.5-flash": { "name": "Gemini 2.5 Flash" }, "gemini-2.5-flash-lite": { "name": "Gemini 2.5 Flash Lite" } } } }Hope this helps
Thanks a lot
So CLIProxyAPI doesn't not use OAuth, you need to provide API key?
@hrstoyanov It uses oauth. The API key in the opencode config is for connecting to the local CLIProxyAPI server.
@frap129 is this still working for you? For me it doesn't seem to connect. Could you share your config file rom CLIProxyAPI?
@nitish-raj Yeah, sometimes messages hang and I have to abort and resend, but otherwise it works well. My config is just the example from the CLIProxyAPI readme, with different local keys, a different auth directory, and no API keys added:
# Server port
port: 8317
# Management API settings
remote-management:
# Whether to allow remote (non-localhost) management access.
# When false, only localhost can access management endpoints (a key is still required).
allow-remote: false
# Management key. If a plaintext value is provided here, it will be hashed on startup.
# All management requests (even from localhost) require this key.
# Leave empty to disable the Management API entirely (404 for all /v0/management routes).
secret-key: "REDACTED"
# Authentication directory (supports ~ for home directory)
auth-dir: "~/.cache/cli-proxy-api"
# Enable debug logging
debug: true
# Proxy URL. Supports socks5/http/https protocols. Example: socks5://user:[email protected]:1080/
proxy-url: ""
# Number of times to retry a request. Retries will occur if the HTTP response code is 403, 408, 500, 502, 503, or 504.
request-retry: 3
# Quota exceeded behavior
quota-exceeded:
switch-project: true # Whether to automatically switch to another project when a quota is exceeded
switch-preview-model: true # Whether to automatically switch to a preview model when a quota is exceeded
# API keys for authentication
api-keys:
- "REDACTED"
@frap129 very nice, the openAI compatible is work well on kilo code, but i'm wondering why is not on opencode
I successfully installed gemini api key with cliproxyapi,
""" CLIProxyAPI Version: dev, Commit: none, BuiltAt: unknown API server started successfully server clients and configuration updated: 11 clients (2 auth files + 4 GL API keys + 2 Claude API keys + 1 Codex keys + 2 OpenAI-compat) """
but in opencode, I tried call gemini,
Generating... Build gemini-2.5-flash (04:21 PM)
then nothing shows up. Stack forever
@ygit1 unfamiliar with it, could you try doing:
opencode run hello --print-logs
and show output?
is the proxy gemini api compliant or does it do openai compatible?
Someone just quietly made this apparently: https://github.com/shantur/opencode-gemini-auth
I have also created a plugin for this https://github.com/jenslys/opencode-gemini-auth
does https://github.com/shantur/opencode-gemini-auth or https://github.com/jenslys/opencode-gemini-auth work? are they safe?
Very cool. I was just searching for that to prepare for the launch of Gemini 3 next week. Google has actually 1500 requests per day included with the $20 Google AI Pro subscription.
https://developers.google.com/gemini-code-assist/resources/quotas
I've submitted a PR to @jenslys plugin repo to add better retry handling for the tight rate limits Gemini 3 Pro has right now. That should make it work better for everyone.
@olafgeibig unfortunately Pro sub cant access G3 yet. Only Ultra
@bitnom it's avaliable for Pro plan users?