Allow using Gemini CLI for free Gemini requests #286

Open
opened 2026-02-16 17:26:03 -05:00 by yindo · 24 comments
Owner

Originally created by @skyfallwastaken on GitHub (Jun 25, 2025).

Originally assigned to: @thdxr on GitHub.

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)

Originally created by @skyfallwastaken on GitHub (Jun 25, 2025). Originally assigned to: @thdxr on GitHub. 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)
Author
Owner

@BasixKOR commented on GitHub (Jun 25, 2025):

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

@BasixKOR commented on GitHub (Jun 25, 2025): 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
Author
Owner

@thdxr commented on GitHub (Jun 25, 2025):

this would honestly be a great PR it might fit in very nicely into how claude pro/max is implemented

@thdxr commented on GitHub (Jun 25, 2025): this would honestly be a great PR it might fit in very nicely into how claude pro/max is implemented
Author
Owner

@sockthedev commented on GitHub (Jun 25, 2025):

one tui to rule them all...

@sockthedev commented on GitHub (Jun 25, 2025): one tui to rule them all...
Author
Owner

@izyuumi commented on GitHub (Jun 26, 2025):

Does something like this work?

@izyuumi commented on GitHub (Jun 26, 2025): Does something like [this](https://github.com/izyuumi/opencode/commit/d2864716ec72d871a067b9df18bfebd93194a578) work?
Author
Owner

@aryasaatvik commented on GitHub (Jun 26, 2025):

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

@aryasaatvik commented on GitHub (Jun 26, 2025): 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
Author
Owner

@fer-ri commented on GitHub (Aug 3, 2025):

any update? I open gist from @aryasaatvik but seems not working anymore too.

@fer-ri commented on GitHub (Aug 3, 2025): any update? I open gist from @aryasaatvik but seems not working anymore too.
Author
Owner

@hrstoyanov commented on GitHub (Aug 8, 2025):

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

@hrstoyanov commented on GitHub (Aug 8, 2025): 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
Author
Owner

@frap129 commented on GitHub (Sep 23, 2025):

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

@frap129 commented on GitHub (Sep 23, 2025): 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](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
Author
Owner

@fer-ri commented on GitHub (Sep 23, 2025):

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

@fer-ri commented on GitHub (Sep 23, 2025): > 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
Author
Owner

@hrstoyanov commented on GitHub (Sep 24, 2025):

So CLIProxyAPI doesn't not use OAuth, you need to provide API key?

@hrstoyanov commented on GitHub (Sep 24, 2025): So CLIProxyAPI doesn't not use OAuth, you need to provide API key?
Author
Owner

@frap129 commented on GitHub (Sep 24, 2025):

@hrstoyanov It uses oauth. The API key in the opencode config is for connecting to the local CLIProxyAPI server.

@frap129 commented on GitHub (Sep 24, 2025): @hrstoyanov It uses oauth. The API key in the opencode config is for connecting to the local CLIProxyAPI server.
Author
Owner

@nitish-raj commented on GitHub (Sep 27, 2025):

@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 commented on GitHub (Sep 27, 2025): @frap129 is this still working for you? For me it doesn't seem to connect. Could you share your config file rom CLIProxyAPI?
Author
Owner

@frap129 commented on GitHub (Sep 27, 2025):

@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:pass@192.168.1.1: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 commented on GitHub (Sep 27, 2025): @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:pass@192.168.1.1: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" ```
Author
Owner

@JunarisAlf commented on GitHub (Oct 1, 2025):

@frap129 very nice, the openAI compatible is work well on kilo code, but i'm wondering why is not on opencode

@JunarisAlf commented on GitHub (Oct 1, 2025): @frap129 very nice, the openAI compatible is work well on kilo code, but i'm wondering why is not on opencode
Author
Owner

@ygit1 commented on GitHub (Oct 6, 2025):

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 commented on GitHub (Oct 6, 2025): 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
Author
Owner

@rekram1-node commented on GitHub (Oct 6, 2025):

@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?

@rekram1-node commented on GitHub (Oct 6, 2025): @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?
Author
Owner

@luckycold commented on GitHub (Oct 24, 2025):

Someone just quietly made this apparently:
https://github.com/shantur/opencode-gemini-auth

@luckycold commented on GitHub (Oct 24, 2025): Someone just quietly made this apparently: https://github.com/shantur/opencode-gemini-auth
Author
Owner

@jenslys commented on GitHub (Nov 1, 2025):

I have also created a plugin for this https://github.com/jenslys/opencode-gemini-auth

@jenslys commented on GitHub (Nov 1, 2025): I have also created a plugin for this https://github.com/jenslys/opencode-gemini-auth
Author
Owner

@Jonathan-Garcia1 commented on GitHub (Nov 9, 2025):

does https://github.com/shantur/opencode-gemini-auth or https://github.com/jenslys/opencode-gemini-auth work? are they safe?

@Jonathan-Garcia1 commented on GitHub (Nov 9, 2025): does https://github.com/shantur/opencode-gemini-auth or https://github.com/jenslys/opencode-gemini-auth work? are they safe?
Author
Owner

@olafgeibig commented on GitHub (Nov 16, 2025):

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

@olafgeibig commented on GitHub (Nov 16, 2025): 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
Author
Owner

@ben-vargas commented on GitHub (Nov 20, 2025):

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.

@ben-vargas commented on GitHub (Nov 20, 2025): 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.
Author
Owner

@iamhenry commented on GitHub (Nov 20, 2025):

@olafgeibig unfortunately Pro sub cant access G3 yet. Only Ultra

@iamhenry commented on GitHub (Nov 20, 2025): @olafgeibig unfortunately Pro sub cant access G3 yet. Only Ultra
Author
Owner

@bitnom commented on GitHub (Nov 20, 2025):

@olafgeibig unfortunately Pro sub cant access G3 yet. Only Ultra

I think you just got it on pro

@bitnom commented on GitHub (Nov 20, 2025): > [@olafgeibig](https://github.com/olafgeibig) unfortunately Pro sub cant access G3 yet. Only Ultra I think you just got it on pro
Author
Owner

@iamhenry commented on GitHub (Nov 24, 2025):

@bitnom it's avaliable for Pro plan users?

@iamhenry commented on GitHub (Nov 24, 2025): @bitnom it's avaliable for Pro plan users?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#286