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
- Get a keyMake one on aistudio.google.com/apikey.
- 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.
- 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.
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
| API | Base URL | Used for |
|---|---|---|
| Chat Completions (OpenAI-compatible) | https://generativelanguage.googleapis.com/v1beta/openai | the model list, and requests from Claude Code, Codex, OpenCode and other agents |
| Gemini API | https://generativelanguage.googleapis.com/v1beta | Gemini 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
- Where it comes from. magpie asks the OpenAI-compatible endpoint for the list once. It is the Gemini API’s list too, so magpie doesn’t ask twice. Names, reasoning levels and prices come from the
googlecatalog on models.dev. - Image models. At Google, a Gemini image model draws on the Gemini API. Choose one in Settings → Models → Images.
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.
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
- Claude Code speaks Anthropic Messages. magpie translates each request to Gemini’s Chat Completions and the reply back to Messages, streaming and tool calls included. Models in Claude Code.
- Codex speaks only OpenAI Responses. magpie translates it to Chat Completions the same way, and the reply comes back to Codex as Responses. Models in Codex.
- Gemini CLI speaks Gemini’s own API, so its requests go to the Gemini API as it sends them, and its Google Search runs there. Models in Gemini CLI.
- OpenCode speaks Chat Completions, so its requests go to Google as they are. Models in OpenCode.
Thinking
- Visible thoughts. Gemini’s OpenAI-compatible API gives the model’s thoughts only when asked in
thinking_config. When an agent asks for visible reasoning, magpie asks for the thoughts withinclude_thoughts, so a long think shows as thinking instead of a first word that comes late. - Levels and budgets. Gemini 3 and later are sent a thinking level. Gemini 2 models are sent a budget instead: 1024 tokens for minimal and low, 8192 for medium and 24576 for high. xhigh and max are sent as high, and an effort with no level is left to the model.
- Reasoning off. Gemini 3 can’t stop thinking. When an agent turns reasoning off, magpie asks for the model’s lowest level instead.
- A level the model doesn’t have. Not every Gemini 3 has every level:
gemini-3.8-flashhas no minimal. When Google turns a level away with a 400, magpie asks again at the nearest level the model has and remembers it until magpie restarts. thinking_configturned away. That is a different 400: a server in front of Gemini that refuses the field itself. magpie asks again withreasoning_effortalone and stops sendingthinking_configthere.- Proxies. A Gemini model behind a proxy on this computer or your network, such as one on
localhostor a private address, is handled the same way.
Thought signatures and tools
- Thought signatures. Gemini 3 signs the first function call of each step, and the next request fails with 400 “Function call is missing a thought_signature in functionCall parts” if the signature is gone. Agents don’t keep it. magpie carries it in the call id the agent gets, as a short reference to a file in magpie’s folder, and puts it back on the way to Gemini. Signatures are kept for 90 days.
- Calls Gemini didn’t sign. A call from another model earlier in the conversation, or one whose id an agent shortened, goes with Google’s documented
skip_thought_signature_validator, so a conversation can move to Gemini halfway. - One provider’s signature. A signature goes back only to the provider that gave it. In a routing group of Vertex AI and the Gemini API, the other provider gets the call as unsigned history instead of answering “Corrupted thought signature”.
- Tool schemas. magpie gives each untyped schema in an agent’s tools a type, which Vertex AI needs, and removes boolean schemas and
x-keywords such as MCP’sx-mcp-header. Tools that need none of this go as they came. - The end of a stream. Gemini’s OpenAI-compatible API sends a whole function call in one chunk and its
finish_reasonin the next. If that reason is lost after the usage arrived, magpie fills it in; without the usage, the reply is reported as cut off rather than passed on as complete.
Cache, cost and search
- Prompt cache. Gemini keeps a prompt cached without saying so on that turn. magpie counts such a turn as a cache write and keeps the next turn on the same provider and key, and remembers which one answered across restarts.
- Cached and thinking tokens. magpie reads cached tokens and reasoning tokens from each reply, on Chat Completions and on the Gemini API alike, and the Usage tab counts them.
- Cost. The Usage tab prices each call from the
googlecatalog on models.dev. - Web search. Gemini runs Google Search on the Gemini API only for a request that declares no function tools. Claude Code’s and Codex’s requests declare tools, so their web search is magpie’s own, which the Google provider answers itself on your key: those searches spend your Gemini API credit.
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.
- Per-minute 429s. Gemini’s 429 “You exceeded your current quota … Please retry in 33s” for a per-minute limit is read as a rate limit, not a used-up plan, and so is Vertex AI’s
requests_per_minute_per_project. The key rests from a minute, doubling, up torest-cap. - Holding to a rate.
rpmholds each key to a number of requests a minute: one request more waits for room, up to 2 minutes, then gets a 429. - Out of quota.
quota-restsets how long a key rests once its quota is spent: 15 minutes by default, up to 8 days, or until a time of day. - Spend caps and fallbacks.
spend-capstops a key at a dollar amount a day, a month or in all, andfallbacknames where requests go when Gemini is out of quota or down.
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.
gcloud auth application-default login magpie provider add google-vertex project=my-project magpie claude google-vertex/gemini-3.1-pro-preview
- Credentials. magpie signs with gcloud’s Application Default Credentials, or with the file
credentials=names by its full path: a user sign-in, a service account key or an impersonated service account.impersonate=takes a service account’s email, and needsroles/iam.serviceAccountTokenCreatoron it. The metadata server, workload identity federation and Vertex AI’s express-mode API keys aren’t read. - Location.
location=isglobal(the default),us,euor a region such asus-central1. - Models. The preset has its own list, among them
gemini-3.8-flash,gemini-3.1-pro-preview,gemini-2.5-pro, partner models such aszai-org/glm-5.2-maas, and Claude models such asclaude-opus-5-5. Gemini goes to Vertex AI’s Gemini API, a partner model to its OpenAI-compatible chat completions, and Claude to Anthropic’s Messages API, all in your project. - Thinking on Vertex AI. A Gemini 3 level is fitted to the levels that model has, and reasoning off asks for its lowest. Gemini 2.5 takes a budget: Pro from 128 to 32768 tokens (128 when off), Flash up to 24576 (0 when off), Flash-Lite from 512 to 24576 (0 when off).
Google sign-ins
Two Google sign-ins give Gemini models without a key. They are subscriptions, set up as on Subscriptions in any agent.
- Gemini (Code Assist). Gemini CLI’s Google sign-in, as
gemini/…:magpie accounts add gemini. Google answers it only for a Code Assist Standard or Enterprise account with a Google Cloud project of its own;magpie accounts project gemini <email> <project>names the project. - Antigravity. As
antigravity/…:magpie accounts add antigravity. Its sign-in gives Antigravity’s Claude and Gemini models.
Troubleshooting
- “Thinking level MINIMAL is not supported for this model”. The model has no minimal level. magpie asks again at the nearest level it has, so the agent gets its answer, and remembers the level until magpie restarts. Only when no level is left does the error reach the agent as Google sent it.
- “Function call is missing a thought_signature in functionCall parts”. A Gemini 3 call lost its signature. Through magpie the signature rides in the call id and is put back, and a call with none goes with
skip_thought_signature_validator. - “Corrupted thought signature”. The signature was cut short or came from another provider. magpie sends a signature only to the provider that gave it.
- 429 with “Please retry in 33s”. A per-minute limit, not a spent plan. The key rests for a short while, and
rpmkeeps requests under the limit from then on. - Vertex AI: a schema “didn’t specify the schema type field”. magpie types every untyped tool schema it sends to Gemini, so this shouldn’t reach the agent.
- Vertex AI won’t save. “Google Vertex AI needs the id of your Google Cloud project”: add
project=. A credentials file has to be given by its full path. - Checking a key.
magpie provider test googlesends a tiny request through each endpoint, or to each model you name. Add--as codexor--as claude-codeto send it the way that agent would.
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.