Docs · Provider

Gemini in Claude Code, Codex, Gemini CLI and OpenCode

Google serves Gemini on the Gemini Developer API, the one an AI Studio key opens, and on Vertex AI in your own Google Cloud project. Add either to magpie once, and Claude Code, Codex, Gemini CLI, OpenCode and every other agent you connect can use Gemini 3 models such as gemini-3.1-pro-preview through magpie’s gateway at 127.0.0.1:3425, each agent on a model of its own.

Add a Gemini API key

  1. Get a keyMake one on aistudio.google.com/apikey.
  2. Add the providerIn magpie’s Providers tab, press + Add provider, pick Google Gemini, paste the key and save. magpie asks Google which models it serves.
  3. Pick it for an agentIn the Agents tab, click the model on the agent’s row and choose a Gemini model such as gemini-3.1-pro-preview.
Terminal
magpie provider add google AIza…
magpie provider test google

Model ids in magpie are provider/model, so the Gemini API’s read google/gemini-3.1-pro-preview: the provider, then Google’s own id. The key is kept in magpie’s settings; magpie doesn’t take it from your shell.

Endpoints

APIBase URLUsed for
Chat Completions (OpenAI-compatible)https://generativelanguage.googleapis.com/v1beta/openaithe model list, and requests from Claude Code, Codex, OpenCode and other agents
Gemini APIhttps://generativelanguage.googleapis.com/v1betaGemini CLI’s requests, Google Search, image models

The preset fills in the Gemini API URL once. If you clear it, it stays empty. Every request that doesn’t come from a Gemini client goes to Chat Completions.

Model list

In each agent

Pick the model on an agent’s row in the Agents tab, or from a terminal. Each guide says what magpie writes in that agent’s config and how to switch back.

Terminal
magpie claude google/gemini-3.1-pro-preview
magpie codex google/gemini-3.1-pro-preview
magpie gemini model google/gemini-3.8-flash
magpie opencode google/gemini-3.1-pro-preview

Thinking

Thought signatures and tools

Cache, cost and search

Several keys and rate limits

One Google Gemini provider can hold several keys: press Add another key under it, or paste several at once. Requests go to the first key that’s on, and when it runs out or is rate limited the next one takes over. The provider’s routing can also rotate, weight or drain them instead.

Terminal
magpie provider rpm google 10
magpie provider spend-cap google <key> 20 month
magpie provider fallback google google-vertex/gemini-3.1-pro-preview

Vertex AI

The Google Vertex AI preset asks Gemini in your Google Cloud project, with no API key. Give it the project’s id; the project in each request is the one billed.

Terminal
gcloud auth application-default login
magpie provider add google-vertex project=my-project
magpie claude google-vertex/gemini-3.1-pro-preview

Google sign-ins

Two Google sign-ins give Gemini models without a key. They are subscriptions, set up as on Subscriptions in any agent.

Troubleshooting

FAQ

How do I use Gemini in Claude Code?

Add a Gemini API key in magpie (Providers, Add provider, Google Gemini), then pick a model such as gemini-3.1-pro-preview on Claude Code’s row, or run magpie claude google/gemini-3.1-pro-preview. magpie writes Claude Code’s settings.json and translates each Messages request to Gemini’s Chat Completions, tool calls and streaming included.

Can Codex use Gemini models?

Yes. Codex speaks only the Responses API. magpie translates each Codex request to Gemini’s Chat Completions and the reply back to Responses. Run magpie codex google/gemini-3.1-pro-preview, or pick the model on Codex’s row.

Does Gemini 3 Pro keep working across tool calls in Claude Code?

Yes. Gemini 3 signs its function calls and refuses the next request without the signature. magpie carries each signature in the call id the agent gets and puts it back on the way to Gemini, so tool loops keep going, and a call from another model is sent as unsigned.

Can Gemini CLI and OpenCode use my Gemini key through magpie?

Yes. Gemini CLI’s requests go to the Gemini API as it sends them, Google Search included. OpenCode speaks Chat Completions, so its requests go to Gemini’s OpenAI-compatible API as they are.

Why does Gemini answer 429 with “Please retry in 33s”?

That is a per-minute limit, not a spent quota. magpie reads it as a rate limit and rests the key briefly. Run magpie provider rpm google 10, with your own limit, and magpie holds requests to that rate.

Can I use Gemini through Vertex AI instead of an API key?

Yes. Add the Google Vertex AI preset with your project’s id, for example magpie provider add google-vertex project=my-project. magpie signs with gcloud’s Application Default Credentials or a credentials file, and your project is billed.

Can I use my Gemini Code Assist or Antigravity sign-in instead?

Yes. Both are subscriptions: magpie accounts add gemini or magpie accounts add antigravity, then pick a gemini/… or antigravity/… model. Code Assist needs a Standard or Enterprise account with a Google Cloud project of its own.

By provider: DeepSeek · Kimi and Kimi Code · GLM Coding Plan · Qwen · MiniMax · Grok · Mistral · OpenRouter · GitHub Copilot · Ollama

Every agent: Models in Claude Code, Models in Codex, Models in Gemini CLI, Models in OpenCode. Ask on Discord if you get stuck.