How to use Gemini CLI through one API
Gemini CLI is a fast, open-source way to bring Google's models into your terminal. But once you start mixing models across a project, juggling separate keys, billing accounts, and SDKs gets old quickly. The cleaner path is to route Gemini CLI through a single OpenAI-compatible gateway, so the same key that runs Gemini also runs GPT, Claude, DeepSeek, Qwen, and the rest.
This guide shows how to do exactly that with AnyModel: one base_url, one API key, and a model id you can swap at will.
Why route Gemini CLI through one API
The native Gemini CLI talks to Google's endpoint with a Google key. That's fine until you want to compare a Gemini answer against Claude or GPT in the same workflow. With a unified gateway you get:
- One key for every model. Switch providers by changing the
modelid — nothing else in your config moves. - One bill, pay-per-token. No per-provider subscriptions, no minimums.
- A drop-in OpenAI-compatible surface. Any tool that speaks the OpenAI Chat Completions format just works.
AnyModel exposes a single endpoint at https://anymodel.org/v1. One key reaches GPT, Claude, Gemini, DeepSeek, GLM, Kimi, Qwen, and Grok. If you want to see how models stack up before wiring anything in, the compare page is a good first stop.
What you need first
Sign up and grab a key — you get 1,000,000 free tokens on signup, and a total of 6,000,000 if you link Telegram. No credit card required. After the free tokens, it's simple pay-per-token.
You'll also need Gemini CLI installed:
npm install -g @google/gemini-cli
Connect Gemini CLI to AnyModel
Gemini CLI isn't one of AnyModel's one-line install targets (those are codex, claude, opencode, and hermes). For Gemini CLI you use the standard manual OpenAI-compatible setup — which the CLI supports natively. Set three environment variables so the CLI sends requests to AnyModel instead of Google:
export GEMINI_API_KEY="YOUR_ANYMODEL_KEY"
export GOOGLE_GEMINI_BASE_URL="https://anymodel.org/v1"
export GEMINI_MODEL="gemini-2.5-pro"
gemini
Add those export lines to your ~/.zshrc or ~/.bashrc so they persist across sessions. From there, run gemini as usual — prompts, file context, and tool calls all flow through the single endpoint.
If your version of the CLI prefers an OpenAI-style config block, the same three values map cleanly: base_url is https://anymodel.org/v1, the key is your AnyModel key, and the model is whatever id you want to call.
Switch models without re-wiring anything
This is the real payoff. Because every model lives behind the same endpoint, you change providers by changing one string. Want to send the same prompt to a different model? Set GEMINI_MODEL to another id:
| Goal | Model id |
|---|---|
| Long-context Google reasoning | gemini-2.5-pro |
| Frontier coding from OpenAI | gpt-5 |
| Strong writing and analysis | claude-opus-4.6 |
| Budget-friendly throughput | deepseek-v3 |
Browse the full, current list on the models page — ids there are exactly what you paste into the config.
Verify it works
A quick curl confirms the endpoint and key are good before you trust the CLI:
curl https://anymodel.org/v1/chat/completions \
-H "Authorization: Bearer YOUR_ANYMODEL_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gemini-2.5-pro","messages":[{"role":"user","content":"Say hi"}]}'
A normal JSON completion means you're set. If you get a 401, re-check the key; a 404 usually means a typo in the model id.
A note on privacy
If you handle sensitive code or data, enable Ghost Mode — opt-in, zero-retention keys where prompts and responses aren't stored on our side, only a token counter for billing. Be realistic about what that means: the underlying model provider still receives your prompt to generate a response, so it isn't end-to-end secrecy. Ghost Mode removes our storage from the equation, nothing more.
Wrap up
Routing Gemini CLI through AnyModel turns a single-vendor terminal tool into a multi-model workbench: one key, one endpoint, and instant switching between Gemini, GPT, Claude, and more. For setup guides and model deep-dives, keep an eye on the blog.
Ready to try it? Create a free account and start with a million tokens — no card needed.
AnyModel