Beta
Discord Download

How to use Gemini in Claude Code and Codex

AutoRouter7 min read

AutoRouter, the Mac app for Codex and Claude Code, 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 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), and Codex sends only OpenAI Responses requests, since responses is its only supported wire_api (OpenAI config reference). Google's OpenAI compatibility page 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:

  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).
  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.
model_list:
  # Google Gemini
  - model_name: gemini-4-hydrogen
    litellm_params:
      model: gemini/gemini-4-hydrogen
      api_key: os.environ/GEMINI_API_KEY
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). While the gateway credential is set, it replaces your claude.ai login, so your Claude plan's limits don't apply (Anthropic docs).

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, with model set to a Gemini slug such as google/gemini-4-carbon:

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 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). 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).

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). OpenRouter lists the same per-token prices for its Gemini 4 slugs as of November 17, 2026.

ModelInput per millionOutput per millionFrom 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.50No change announced

To choose between them, see Gemini 4 Carbon vs Argon and 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 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.
  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). 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:

RouteWorks inSetupWhat pays
LiteLLM proxyClaude Code and CodexInstall, config.yaml, run the proxyYour Gemini API key, per token
OpenRouterCodex (config.toml provider)Provider block and an OpenRouter keyOpenRouter credits, plus 5.5% on purchases
AutoRouter (Mac)Claude Code and CodexInstall, sign in, click EnableA 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 covers the same setup for other providers, and 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). Start Claude Code with --model gemini-4-hydrogen, set ANTHROPIC_MODEL, or add it as ANTHROPIC_CUSTOM_MODEL_OPTION (Claude Code model configuration).

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). 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). 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). Unset the variables to go back to your plan.

Sources