opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Allow using Gemini CLI for free Gemini requests

Open SkyfallWasTaken opened this issue 6 months ago • 24 comments

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)

SkyfallWasTaken avatar Jun 25 '25 19:06 SkyfallWasTaken

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 avatar Jun 25 '25 21:06 BasixKOR

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

thdxr avatar Jun 25 '25 21:06 thdxr

one tui to rule them all...

sockthedev avatar Jun 26 '25 03:06 sockthedev

Does something like this work?

izyuumi avatar Jun 26 '25 08:06 izyuumi

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 avatar Jun 26 '25 22:06 aryasaatvik

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

fer-ri avatar Aug 03 '25 15:08 fer-ri

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 avatar Aug 08 '25 19:08 hrstoyanov

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 avatar Sep 24 '25 00:09 frap129

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 avatar Sep 24 '25 02:09 fer-ri

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

hrstoyanov avatar Sep 24 '25 17:09 hrstoyanov

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

frap129 avatar Sep 24 '25 17:09 frap129

@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 avatar Sep 27 '25 16:09 nitish-raj

@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 avatar Sep 27 '25 17:09 frap129

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

JunarisAlf avatar Oct 01 '25 08:10 JunarisAlf

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 avatar Oct 06 '25 09:10 ygit1

@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 avatar Oct 06 '25 13:10 rekram1-node

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

luckycold avatar Oct 24 '25 18:10 luckycold

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

jenslys avatar Nov 01 '25 18:11 jenslys

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

Jonathan-Garcia1 avatar Nov 09 '25 09:11 Jonathan-Garcia1

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 avatar Nov 16 '25 23:11 olafgeibig

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 avatar Nov 20 '25 20:11 ben-vargas

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

iamhenry avatar Nov 20 '25 20:11 iamhenry

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

I think you just got it on pro

bitnom avatar Nov 21 '25 02:11 bitnom

@bitnom it's avaliable for Pro plan users?

iamhenry avatar Nov 24 '25 17:11 iamhenry