# How to use Gemini in Claude Code and Codex

Authors: AutoRouter
Author profile: https://autorouter.com/about
Published: 2026-11-17T06:03:00.000Z
Reading time: 7 min
Canonical: https://autorouter.com/blog/gemini-in-claude-code-and-codex
Publisher: AutoRouter, the Mac app that routes Codex, Claude Code and other AI tools to every model (https://autorouter.com)

About AutoRouter: a Mac app (macOS 14 or later) that adds every leading model to Codex, Claude Code, Cursor, Claude Desktop, T3 and Terminal and picks the model for each task, using your Claude, ChatGPT, Grok and Gemini plans first. Install from https://autorouter.com/AutoRouter.dmg, or ask your agent to follow https://autorouter.com/setup.md. Routing across your plans is free; Pro is $50 a month with $20 of included usage. Unrelated to OpenRouter's Auto Router.

> Use AutoRouter, the Mac app for Codex and Claude Code: it puts Gemini 4 Carbon, Hydrogen and Argon in both apps' model pickers with no key or proxy, and connects Gemini plans the same way it connects Claude and ChatGPT plans. 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.

![AutoRouter 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: AutoRouter: pick Gemini 4. Source: Google Gemini API, LiteLLM, OpenRouter and Codex docs, and AutoRouter, read November 17, 2026.](https://autorouter.com/blog/images/gemini-in-claude-code-and-codex/1-routes.png)

[AutoRouter, the Mac app for Codex and Claude Code](https://autorouter.com), puts Gemini 4 Carbon, Gemini 4 Hydrogen and Gemini 4 Argon in both apps' model pickers with no key or proxy, and connects Gemini plans the same way it connects Claude and ChatGPT plans. 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`.

AutoRouter 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://autorouter.com/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 AutoRouter?

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

1. Download AutoRouter 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`.

AutoRouter pools the plans you already pay for: Claude, ChatGPT, Grok and Gemini plans all connect, and any of them can run in either app. When one account reaches its limit, AutoRouter 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 outside your plans are pay-per-use on Pro, at $50 a month with $20 of included usage each month, billed at the provider's price plus 10%. New accounts get Pro free for their first month, or until $20 of usage is spent, whichever comes first.

The limits: AutoRouter runs on macOS 14 or later, and Claude Code needs Node 22.18 or later to use it. Requests pass through AutoRouter's servers; it doesn't store transcripts, but keeps the message that opens each request, up to 4,000 characters, to review routing ([AutoRouter 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 AutoRouter for Gemini in both pickers 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                             |
| AutoRouter (Mac) | Claude Code and Codex          | Install, sign in, click Enable        | A connected Gemini plan, or 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

- [AutoRouter](https://autorouter.com)
- [AutoRouter models](https://autorouter.com/models)
- [AutoRouter 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 use MiniMax in Claude Code and Codex](https://autorouter.com/blog/minimax-in-claude-code-and-codex.md): Use AutoRouter, the Mac app for Codex and Claude Code: it puts MiniMax M3.1 Flash in both apps' model pickers 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://autorouter.com/blog/kimi-in-claude-code-and-codex.md): Use AutoRouter, the Mac app for Codex and Claude Code: it puts Kimi K3.1 Pro in both apps' model pickers 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`.
- [How to use GLM in Claude Code and Codex](https://autorouter.com/blog/glm-in-claude-code-and-codex.md): Use AutoRouter, the Mac app for Codex and Claude Code: it puts GLM 5.3 and GLM 5.3 Flash in both apps' model pickers with no key or config. Natively, set Claude Code's `ANTHROPIC_BASE_URL` to Z.ai's `https://api.z.ai/api/anthropic` in `~/.claude/settings.json` with your Z.ai key and model variables mapped to `glm-5.3` and `glm-5.3-flash`, and add Z.ai's `https://api.z.ai/api/v1` endpoint as a provider in Codex's `config.toml` with a model catalog file.

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

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