---
description: How to use Claude Code with Gemini models by routing requests through Bifrost, an open-source AI gateway. Setup takes a few environment variables.
title: How to Use Claude Code with Gemini Models via Bifrost?
image: https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/07/how-to-use-claude-code-with-gemini-models-via-bifrost-bifrost-weave.optimized.png
---

Try Bifrost Enterprise free for 14 days. [Request access](https://www.getmaxim.ai/#enterprise-trial)

Claude Code is one of the most capable AI-powered coding agents available today, bringing advanced code generation, file editing, and terminal operations directly into your workflow. By default, it works exclusively with Anthropic's Claude models. But what if you want to route your Claude Code sessions through Google's Gemini models for cost optimization, latency reduction, or simply to compare output quality?

[Bifrost](https://docs.getbifrost.ai/overview), an [open-source](https://github.com/maximhq/bifrost), high-performance [AI gateway](https://www.getmaxim.ai/articles/top-5-llm-gateways-in-2026-a-production-ready-comparison/), makes this possible. It acts as a protocol translation layer between Claude Code's Anthropic API requests and Google's Gemini models, letting you swap providers with a few environment variables and zero code changes.

This guide walks you through the full setup, from installing Bifrost to running Claude Code with Gemini as the underlying model.

## Why Use Gemini Models with Claude Code?

Claude Code's terminal-native interface, tool-calling architecture, and agentic capabilities make it a strong choice for developer workflows. However, there are valid reasons to route requests through Gemini instead of defaulting to Anthropic's own models:

- **Cost efficiency:** Gemini models, especially Gemini 2.5 Flash, offer competitive pricing that can significantly reduce per-token costs for high-volume coding tasks
- **Latency optimization:** Depending on your region and infrastructure, Gemini endpoints may provide lower latency for specific workloads
- **Provider diversification:** Running multiple providers through a single gateway reduces single-point-of-failure risk in production environments
- **Model benchmarking:** Testing the same prompts across Claude and Gemini helps teams make data-driven decisions about which model performs best for their use case

Bifrost's [automatic fallback](https://docs.getbifrost.ai/features/fallbacks) and [load balancing](https://docs.getbifrost.ai/features/keys-management) capabilities make this kind of multi-provider strategy straightforward to manage.

## What is Bifrost and How Does It Enable This?

Bifrost is a high-performance AI gateway that unifies access to [23+ providers](https://docs.getbifrost.ai/providers/supported-providers/overview) through a single API. It supports OpenAI, Anthropic, Google Gemini, Google Vertex AI, AWS Bedrock, Azure, Groq, Mistral, and others, all accessible through a unified, OpenAI-compatible interface.

The key capability that makes this workflow possible is Bifrost's [drop-in replacement](https://docs.getbifrost.ai/features/drop-in-replacement) architecture. When Claude Code sends an Anthropic API request, Bifrost intercepts it, translates the request format to match Gemini's API specification, routes it to Google's endpoint, and returns the response in the format Claude Code expects. All of this happens transparently, with only [11 microseconds of overhead per request](https://docs.getbifrost.ai/benchmarking/getting-started) in sustained benchmarks.

Bifrost also provides:

- [**Semantic caching**](https://docs.getbifrost.ai/features/semantic-caching) to reduce redundant API calls and lower costs
- [**Built-in observability**](https://docs.getbifrost.ai/features/observability) with Prometheus metrics and OpenTelemetry tracing
- [**Virtual keys and governance**](https://docs.getbifrost.ai/features/governance) for budget control, rate limiting, and access management
- [**MCP gateway**](https://docs.getbifrost.ai/mcp/overview) support for enabling external tool integrations

## Prerequisites

Before starting, make sure you have the following:

- **Node.js** installed (required for Claude Code)
- **Claude Code** installed globally via npm: `npm install -g @anthropic-ai/claude-code`
- **Bifrost** deployed locally or on your infrastructure ([setup guide](https://docs.getbifrost.ai/quickstart/gateway/setting-up))
- **Google Gemini API key** configured in Bifrost's provider settings
- A Bifrost **virtual key** or an Anthropic API key for authentication

## Step-by-Step Setup

### Step 1: Configure Bifrost with a Gemini Provider

Once Bifrost is running (default at `http://localhost:8080`), add Google Gemini as a provider through Bifrost's web UI or configuration file. You will need to supply your Gemini API key and specify which models you want available.

Bifrost supports both [Google Gemini](https://docs.getbifrost.ai/providers/supported-providers/overview) (direct API) and [Google Vertex AI](https://docs.getbifrost.ai/providers/supported-providers/overview) as separate provider options. For most developers, the direct Gemini API is the simplest path.

### Step 2: Set Environment Variables for Claude Code

Claude Code reads its routing configuration from environment variables. To point it at Bifrost and override the default model tiers with Gemini, set the following:

```bash
# Point Claude Code at Bifrost's Anthropic-compatible endpoint
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic

# Use your Bifrost virtual key or Anthropic API key
export ANTHROPIC_API_KEY=your-bifrost-virtual-key

# Override the default Sonnet tier with Gemini 2.5 Pro
export ANTHROPIC_DEFAULT_SONNET_MODEL="gemini/gemini-2.5-pro"

# Optionally, override the Opus tier as well
export ANTHROPIC_DEFAULT_OPUS_MODEL="gemini/gemini-2.5-pro"

# Use Gemini Flash for the lightweight Haiku tier
export ANTHROPIC_DEFAULT_HAIKU_MODEL="gemini/gemini-2.5-flash"
```

The `provider/model-name` format is how Bifrost identifies which upstream provider to route to. Bifrost then handles the full [API translation](https://docs.getbifrost.ai/cli-agents/claude-code) automatically.

### Step 3: Launch Claude Code

Start Claude Code as you normally would:

```bash
claude
```

All requests now flow through Bifrost and are routed to Gemini. Claude Code's tool-calling features (file operations, terminal commands, code editing) will work as long as the Gemini model supports tool use.

### Step 4: Switch Models Mid-Session

One of the advantages of routing through Bifrost is the ability to swap models on the fly. During an active Claude Code session, use the `/model` command:

```bash
/model gemini/gemini-2.5-pro
/model gemini/gemini-2.5-flash
/model anthropic/claude-sonnet-4-5-20250929   # Switch back to Claude anytime
```

This makes A/B comparisons between Claude and Gemini trivial during a single coding session.

## Important Considerations and Limitations

While this setup works for core coding workflows, there are a few things to keep in mind:

- **Tool use is required:** Claude Code relies heavily on tool calling for file operations, terminal commands, and code editing. Gemini models must support tool use for these features to function. Gemini 2.5 Pro and 2.5 Flash both support function calling
- **Claude-specific features are unavailable:** Extended thinking, web search, computer use, and citations are Anthropic-exclusive features. These will not work when routing through Gemini
- **Provider compatibility varies:** Some proxy providers do not stream function call arguments properly. Bifrost handles this correctly for Gemini, but if you encounter issues with other providers, consult the [provider compatibility notes](https://docs.getbifrost.ai/cli-agents/claude-code) in Bifrost's documentation
- **Persistent configuration:** Add the environment variable exports to your `~/.bashrc` or `~/.zshrc` to avoid re-entering them each session

## Making the Setup Production-Ready

For teams running this at scale, Bifrost offers several enterprise capabilities that strengthen this workflow:

- [Automatic fallbacks](https://docs.getbifrost.ai/features/fallbacks): Configure Gemini as the primary provider with Claude as a fallback, so if Gemini's API experiences downtime, requests automatically reroute to Anthropic
- [Budget management](https://docs.getbifrost.ai/features/governance): Set per-developer or per-team spending limits using virtual keys to control costs across both providers
- [Clustering and high availability](https://docs.getbifrost.ai/enterprise/clustering): Deploy Bifrost in a clustered configuration for zero-downtime operations
- [Guardrails](https://docs.getbifrost.ai/enterprise/guardrails): Add content safety layers using AWS Bedrock Guardrails, Azure Content Safety, or Patronus AI

## Conclusion

Using Claude Code with Gemini models through Bifrost gives development teams the flexibility to optimize for cost, latency, or reliability without changing their tooling. Bifrost's protocol translation handles the complexity, and its governance and observability features ensure the setup remains manageable at scale.

Whether you are experimenting with Gemini's coding capabilities or building a multi-provider fallback strategy, Bifrost makes the integration seamless.

To explore how Bifrost can fit into your AI infrastructure, [book a demo](https://www.getmaxim.ai/book-a-demo) or get started with the [open-source gateway on GitHub](https://github.com/maximhq/bifrost).

## Read next

[![API Key Management for LLM Apps: How to Manage Client Access](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/how-to-enforce-ai-budgets-per-team-project-and-key-bifrost-1920x1080--1-.png) API key management for LLM applications means issuing every app, service, and environment its own revocable credential instead of sharing raw provider keys. This guide shows how to do it with Bifrost virtual keys, covering scoping, rate limits, rotation, revocation, and log attribution.](https://www.getmaxim.ai/articles/api-key-management-for-llm-applications/)

[![Claude Agent SDK Through a Gateway: Routing, Budgets, MCP](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/claude-agent-sdk-through-a-gateway-routing-budgets-mcp-bifrost-1920x1080.png) The Claude Agent SDK packages Claude Code's agent loop, tools, and context management as a Python and TypeScript library. This guide shows how to route Claude Agent SDK traffic through Bifrost for provider routing and failover, per-tenant budgets, and governed MCP tool access.](https://www.getmaxim.ai/articles/claude-agent-sdk-through-a-gateway-routing-budgets-mcp/)

[![How to Enforce AI Budgets Per Team, Project and Key](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/how-to-enforce-ai-budgets-per-team-project-and-key-bifrost-1920x1080.png) An AI budget is a hard spending ceiling enforced in the LLM request path, not a monthly report. This guide covers budget hierarchies, project mapping, reset windows, rate limits, exhausted-budget behavior, and a worked $10,000 example in Bifrost.](https://www.getmaxim.ai/articles/enforce-ai-budgets/)

## More in AI Gateway

[![Best AI Gateway to Use with Claude Code](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/07/best-ai-gateway-to-use-with-claude-code-bifrost-weave.optimized.png) Claude Code has become one of the most widely adopted AI-powered coding tools in enterprise engineering teams. Its run-rate revenue has surpassed $2.5 billion since launch, and organizations like Uber, Salesforce, and Accenture are deploying it across hundreds of developers. But scaling Claude Code beyond a handful](https://www.getmaxim.ai/articles/best-ai-gateway-to-use-with-claude-code/)

[![Best LiteLLM Alternative: Bifrost vs LiteLLM for Enterprise-Grade LLM Apps](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/07/bifrost-vs-litellm-for-enterprise-grade-llm-apps-bifrost-strata.optimized.png) Enterprise AI teams rarely rely on a single model. Production applications typically orchestrate across OpenAI for general tasks, Anthropic for nuanced reasoning, AWS Bedrock for compliance-sensitive workloads, and open-weight models via Groq or Ollama for cost optimization. Managing these providers directly means dealing with fragmented APIs, inconsistent authentication,](https://www.getmaxim.ai/articles/bifrost-vs-litellm-for-enterprise-grade-llm-apps/)

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "publisher": {
        "@type": "Organization",
        "name": "Maxim Articles",
        "url": "https://www.getmaxim.ai/articles/",
        "logo": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w256h256/2025/08/thumbnail.png",
            "width": 60,
            "height": 60
        }
    },
    "author": {
        "@type": "Person",
        "name": "Kuldeep Paul",
        "image": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/2025/08/1727978381919.jpeg",
            "width": 800,
            "height": 800
        },
        "url": "https://www.getmaxim.ai/articles/author/kuldeep/",
        "sameAs": []
    },
    "headline": "How to Use Claude Code with Gemini Models via Bifrost?",
    "url": "https://www.getmaxim.ai/articles/how-to-use-claude-code-with-gemini-models-via-bifrost/",
    "datePublished": "2026-03-23T04:50:00.000Z",
    "dateModified": "2026-10-13T11:03:28.000Z",
    "image": {
        "@type": "ImageObject",
        "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/07/how-to-use-claude-code-with-gemini-models-via-bifrost-bifrost-weave.optimized.png",
        "width": 1200,
        "height": 630
    },
    "keywords": "AI Gateway",
    "description": "Route Claude Code to Google's Gemini models through Bifrost. No code changes, just environment variables.",
    "mainEntityOfPage": "https://www.getmaxim.ai/articles/how-to-use-claude-code-with-gemini-models-via-bifrost/"
}
```
