# How to use Gemini in Claude Code and Codex

> Use Auto, the Mac app for all your coding agents: it puts Gemini 4 Carbon, Hydrogen and Argon in each one's model picker (Claude Code, Codex, Cursor, etc.) with no key or proxy. Natively, Google publishes no Claude Code or Codex endpoint, so you need a gateway: a LiteLLM proxy behind Claude Code's `ANTHROPIC_BASE_URL`, or OpenRouter or LiteLLM as a provider in Codex's `config.toml`, each with your own key.

Author: Tyler J. Cagle (https://x.com/tjcages)
Published: 2026-11-17T06:03:00.000Z
Updated: 2026-11-19T23:45:00.000Z
Reading time: 7 min
Canonical: https://auto.sh/blog/gemini-in-claude-code-and-codex
Part of: How to choose and change models in Codex and Claude Code (https://auto.sh/blog/models-in-codex-and-claude-code.md)
Publisher: Auto (https://auto.sh)

![Auto puts Gemini in both apps, no proxy. Which app should run Gemini? App Claude Code: LiteLLM proxy and a Gemini key; App Codex: LiteLLM or OpenRouter as provider; App Either, on a Mac: Auto: pick Gemini 4. Source: Google Gemini API, LiteLLM, OpenRouter and Codex docs, and Auto, read November 17, 2026.](https://auto.sh/blog/images/gemini-in-claude-code-and-codex/1-routes.png)

[Auto, the Mac app for all your coding agents](https://autorouter.com/), puts Gemini 4 Carbon, Gemini 4 Hydrogen and Gemini 4 Argon in each one's model picker (Claude Code, Codex, Cursor, etc.) with no key or proxy, next to the AI subscriptions you already pay for. The native route takes a gateway and your own key. Google doesn't publish an endpoint that Claude Code or Codex can use directly, so the native way to use Gemini in either app is a gateway with your own key. For Claude Code, run a [LiteLLM](https://docs.litellm.ai/docs/tutorials/claude_non_anthropic_models) proxy with your Gemini API key and point `ANTHROPIC_BASE_URL` at it; for Codex, add OpenRouter or LiteLLM as a provider in `~/.codex/config.toml`.

Auto wrote this post, and it competes with the gateways below; LiteLLM and OpenRouter are the better fit if you want your own keys or run on Linux or Windows. Every command is copied from Google's, LiteLLM's, OpenRouter's, Anthropic's or OpenAI's docs as checked on November 17, 2026; check the linked page before you paste.

## Why can't Claude Code or Codex reach Gemini directly?

Because each app speaks one API format that Google's Gemini API doesn't document. Claude Code sends Anthropic Messages requests to `ANTHROPIC_BASE_URL` ([Anthropic gateway protocol](https://code.claude.com/docs/en/llm-gateway-protocol)), and Codex sends only OpenAI Responses requests, since `responses` is its only supported `wire_api` ([OpenAI config reference](https://learn.chatgpt.com/docs/config-file/config-reference)). Google's [OpenAI compatibility page](https://ai.google.dev/gemini-api/docs/openai) documents Chat Completions at `https://generativelanguage.googleapis.com/v1beta/openai/`, with no Responses API and no Anthropic-format endpoint. A gateway translates between them.

## How do you use Gemini in Claude Code?

Run LiteLLM's proxy on your machine with your Gemini API key, then point Claude Code at it. LiteLLM's guide for non-Anthropic models in Claude Code takes four steps:

![Gemini in Claude Code runs through a local proxy. 1. Install LiteLLM (uv tool install); 2. Add Gemini models (In config.yaml); 3. Start the proxy (Port 4000); 4. Point Claude Code there (ANTHROPIC_BASE_URL). Source: LiteLLM, use Claude Code with non-Anthropic models, read November 17, 2026.](https://auto.sh/blog/images/gemini-in-claude-code-and-codex/2-litellm-steps.png)

1. Install the proxy with `uv tool install 'litellm[proxy]'`.
2. Create a `config.yaml` that lists the Gemini models you want, using Google's model IDs: `gemini-4-carbon`, `gemini-4-hydrogen` or `gemini-4-argon` ([Gemini models](https://ai.google.dev/gemini-api/docs/models)).
3. Export `GEMINI_API_KEY` and a long random `LITELLM_MASTER_KEY`, then start the proxy with `litellm --config /path/to/config.yaml`; it listens on port 4000.
4. In a new terminal, set `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN`, then start Claude Code with `--model` set to the name from your config.

```yaml
model_list:
  # Google Gemini
  - model_name: gemini-4-hydrogen
    litellm_params:
      model: gemini/gemini-4-hydrogen
      api_key: os.environ/GEMINI_API_KEY
```

```bash
export ANTHROPIC_BASE_URL="http://0.0.0.0:4000"
export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
claude --model gemini-4-hydrogen
```

LiteLLM's example uses an older Gemini model name; the block above swaps in Google's Gemini 4 ID and changes nothing else. Pass the model with `--model` or `ANTHROPIC_MODEL` rather than looking for it in `/model`: Claude Code's gateway model discovery keeps only IDs that contain `claude` or `anthropic` ([Anthropic gateway protocol](https://code.claude.com/docs/en/llm-gateway-protocol)). While the gateway credential is set, it replaces your claude.ai login, so your Claude plan's limits don't apply ([Anthropic docs](https://code.claude.com/docs/en/llm-gateway)).

## How do you use Gemini in Codex?

Add a gateway that speaks the Responses API as a provider in `~/.codex/config.toml`. OpenRouter needs no local proxy: export `OPENROUTER_API_KEY` and add the block from [OpenRouter's Codex guide](https://openrouter.ai/docs/cookbook/coding-agents/codex-cli), with `model` set to a Gemini slug such as `google/gemini-4-carbon`:

```toml
model_provider = "openrouter"
model_reasoning_effort = "high"
model = "google/gemini-4-carbon"

[model_providers.openrouter]
name = "openrouter"
base_url="https://openrouter.ai/api/v1"

[model_providers.openrouter.auth]
command = "sh"
args = ["-c", "echo $OPENROUTER_API_KEY"]
```

OpenRouter's guide uses the `auth` command so Codex can fetch OpenRouter's model catalog; with a plain `env_key`, non-OpenAI models show an "Unknown model" warning. For the Codex app, OpenRouter's [Codex app guide](https://openrouter.ai/docs/cookbook/coding-agents/codex-desktop) sets the key with `launchctl setenv` on macOS, since the app opened from the Dock doesn't see your shell profile. OpenRouter bills inference at the provider's list price and charges 5.5% when you buy credits on its Standard plan ([OpenRouter pricing](https://openrouter.ai/pricing)). LiteLLM's proxy also serves the Responses API, so the proxy from the Claude Code section works as a Codex provider too ([LiteLLM Codex guide](https://docs.litellm.ai/docs/proxy/client_setup/codex_cli)).

## What do the Gemini 4 models cost through Google's API?

Gemini 4 Carbon and Gemini 4 Argon cost $2.00 per million input tokens and $10.00 per million output tokens through November 30, 2026, and $4.00 and $20.00 from December 1, 2026. Gemini 4 Hydrogen costs $1.50 and $7.50. All three have a 1M-token context window ([Gemini pricing](https://ai.google.dev/gemini-api/docs/pricing)). OpenRouter lists the same per-token prices for its Gemini 4 slugs as of November 17, 2026.

| Model             | Input per million | Output per million | From December 1, 2026 |
| ----------------- | ----------------- | ------------------ | --------------------- |
| Gemini 4 Carbon   | $2.00             | $10.00             | $4.00 and $20.00      |
| Gemini 4 Argon    | $2.00             | $10.00             | $4.00 and $20.00      |
| Gemini 4 Hydrogen | $1.50             | $7.50              | No change announced   |

To choose between them, see [Gemini 4 Carbon vs Argon](/blog/gemini-4-carbon-vs-argon) and [Gemini 4 Hydrogen vs Argon](/blog/gemini-4-hydrogen-vs-argon).

## How do you use Gemini with Auto?

Pick it in the model picker. Auto adds frontier and open-weight models to every coding agent you use, with no keys or endpoints to set up, including Gemini 4 Carbon, Gemini 4 Hydrogen and Gemini 4 Argon on [Auto's models page](https://autorouter.com/models) as of November 17, 2026. Choosing a Gemini model sends your requests straight to it. Choosing Auto lets it work out how hard each task is and send each one to the model that fits.

1. Download Auto for macOS from [autorouter.com](https://autorouter.com/).
2. Open it, sign in or create a free account, sign in to your plans, allow Accessibility, and click Enable for each app.
3. Start a new session and choose a model: in Codex, from the model menu under the message box; in Claude Code, with `/model`.

Auto pools the AI subscriptions you already pay for, and any of them can run in any of your coding agents. When one account reaches its limit, Auto moves on to the account with the most room left before it spends any credit. Free connects two subscriptions and Pro connects any number. Gemini models are pay-per-use on [Pro](/pricing), which includes usage each month, billed at the provider's price plus 10%. New accounts get a week of Pro, or until its included usage is spent, whichever comes first.

The limits: Auto runs on macOS 14 or later, and Claude Code needs Node 22.18 or later to use it. Requests pass through Auto's servers; it doesn't store transcripts, but keeps the message that opens each request, up to 4,000 characters, to review routing ([Auto privacy](https://autorouter.com/privacy)). It sometimes misjudges how hard a task is, and you can rate the pick or choose a model yourself.

## Which Gemini setup should you use?

Use LiteLLM if you want to run the gateway yourself on your own keys, OpenRouter for one hosted key, and Auto for Gemini in every coding agent's picker beside your plans on a Mac. As of November 17, 2026:

| Route         | Works in                                                                  | Setup                                 | What pays                                  |
| ------------- | ------------------------------------------------------------------------- | ------------------------------------- | ------------------------------------------ |
| LiteLLM proxy | Claude Code and Codex                                                     | Install, `config.yaml`, run the proxy | Your Gemini API key, per token             |
| OpenRouter    | Codex (`config.toml` provider)                                            | Provider block and an OpenRouter key  | OpenRouter credits, plus 5.5% on purchases |
| Auto (Mac)    | Codex, Claude Code, Cursor, Claude Desktop, T3, OpenCode, Pi and Terminal | Install, sign in, click Enable        | Pro usage at the provider's price plus 10% |

[Try a new model in Codex or Claude Code without another API key](/blog/try-new-models-in-codex-and-claude-code) covers the same setup for other providers, and [LiteLLM alternatives](/blog/litellm-alternatives) compares the gateways.

## Questions

### Why doesn't my Gemini model show up in /model?

Claude Code's gateway model discovery keeps only model IDs that contain `claude` or `anthropic`, so `gemini-4-hydrogen` is filtered out ([Anthropic gateway protocol](https://code.claude.com/docs/en/llm-gateway-protocol)). Start Claude Code with `--model gemini-4-hydrogen`, set `ANTHROPIC_MODEL`, or add it as `ANTHROPIC_CUSTOM_MODEL_OPTION` ([Claude Code model configuration](https://code.claude.com/docs/en/model-config)).

### Can I point Codex at Google's OpenAI-compatible endpoint?

Not as documented. Codex needs a provider that speaks the Responses API, and Google's OpenAI compatibility page documents Chat Completions only ([Gemini OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai)). Use a gateway such as OpenRouter or LiteLLM in between.

### Should I use Google's own coding CLI instead?

If you want Gemini without Claude Code or Codex, yes. The Gemini CLI README says it is now for Enterprise Code Assist and isn't optimized for Gemini 4 and later models, and points other users to Google's Antigravity CLI ([Gemini CLI](https://github.com/google-gemini/gemini-cli)). The routes in this post are for keeping Gemini inside the agent you already use.

### Does my Claude plan pay for Gemini through a LiteLLM proxy?

No. With `ANTHROPIC_AUTH_TOKEN` set, Claude Code sends the gateway credential in place of your claude.ai login, and Gemini requests bill to your Gemini API key ([Anthropic docs](https://code.claude.com/docs/en/llm-gateway)). Unset the variables to go back to your plan.

## Sources

- [Auto](https://autorouter.com/)
- [Auto models](https://autorouter.com/models)
- [Auto privacy](https://autorouter.com/privacy)
- [Gemini API: models](https://ai.google.dev/gemini-api/docs/models)
- [Gemini API: pricing](https://ai.google.dev/gemini-api/docs/pricing)
- [Gemini API: OpenAI compatibility](https://ai.google.dev/gemini-api/docs/openai)
- [Gemini CLI](https://github.com/google-gemini/gemini-cli)
- [LiteLLM: Claude Code with non-Anthropic models](https://docs.litellm.ai/docs/tutorials/claude_non_anthropic_models)
- [LiteLLM: Codex CLI](https://docs.litellm.ai/docs/proxy/client_setup/codex_cli)
- [OpenRouter: Codex CLI](https://openrouter.ai/docs/cookbook/coding-agents/codex-cli)
- [OpenRouter: Codex app](https://openrouter.ai/docs/cookbook/coding-agents/codex-desktop)
- [OpenRouter pricing](https://openrouter.ai/pricing)
- [Claude Code: LLM gateways](https://code.claude.com/docs/en/llm-gateway)
- [Claude Code: gateway protocol](https://code.claude.com/docs/en/llm-gateway-protocol)
- [Claude Code: model configuration](https://code.claude.com/docs/en/model-config)
- [Codex configuration reference](https://learn.chatgpt.com/docs/config-file/config-reference)

## Read next

- [How to choose and change models in Codex and Claude Code](https://auto.sh/blog/models-in-codex-and-claude-code.md): To give each task the right model, use Auto, the Mac app for all your coding agents: it adds models from every leading provider to the picker you already use (Claude Code, Codex, Cursor, etc.) and can pick one for each turn. To choose yourself, give hard, multi-file work a frontier model such as Claude Opus 5.5 or GPT-6.2 Astra and quick edits a fast one such as Claude Haiku 5.5 or GPT-6 Luna. Switch with /model in either app, a launch flag for one session, or a settings file for every session.
- [How to use MiniMax in Claude Code and Codex](https://auto.sh/blog/minimax-in-claude-code-and-codex.md): Use Auto, the Mac app for all your coding agents: it puts MiniMax M3.1 Flash in each one's model picker (Claude Code, Codex, Cursor, etc.) with no MiniMax key or config. Natively, set Claude Code's `ANTHROPIC_BASE_URL` to `https://api.minimax.io/anthropic` with your M Plan key and `MiniMax-M3.1-Flash[1m]` model variables in `~/.claude/settings.json`, and add `https://api.minimax.io/v1` as a provider in Codex's `config.toml`.
- [How to use Kimi in Claude Code and Codex](https://auto.sh/blog/kimi-in-claude-code-and-codex.md): Use Auto, the Mac app for all your coding agents: it puts Kimi K3.1 Pro in each one's model picker (Claude Code, Codex, Cursor, etc.) with no Kimi account, key or config. Natively, set Claude Code's `ANTHROPIC_BASE_URL` to Moonshot's `https://api.moonshot.ai/anthropic` (or `https://api.kimi.ai/coding/` with a Kimi Code plan) with your key and model variables in `~/.claude/settings.json`, and add `https://api.moonshot.ai/v1` as a provider with `kimi-k3.1-pro` in Codex's `config.toml`.

Tags: [Guides](https://auto.sh/blog/tags/guides.md), [Models](https://auto.sh/blog/tags/models.md), [Claude Code](https://auto.sh/blog/tags/claude-code.md)

Drafted with AI from the sources linked above, then checked and edited by the Auto team.

Auto is a Mac app for AI model routing in Codex, Claude Code, Cursor and other supported coding agents. It uses eligible connected subscriptions first. See [setup](https://auto.sh/setup.md) and [pricing](https://auto.sh/pricing).
