How to Use Claude Code with Gemini Models via Bifrost?
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, an open-source, high-performance AI gateway, 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 and load balancing 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 20+ providers 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 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 in sustained benchmarks.
Bifrost also provides:
- Semantic caching to reduce redundant API calls and lower costs
- Built-in observability with Prometheus metrics and OpenTelemetry tracing
- Virtual keys and governance for budget control, rate limiting, and access management
- MCP gateway 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)
- 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 (direct API) and Google Vertex AI 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:
# 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 automatically.
Step 3: Launch Claude Code
Start Claude Code as you normally would:
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:
/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 in Bifrost's documentation
- Persistent configuration: Add the environment variable exports to your
~/.bashrcor~/.zshrcto 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: 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: Set per-developer or per-team spending limits using virtual keys to control costs across both providers
- Clustering and high availability: Deploy Bifrost in a clustered configuration for zero-downtime operations
- 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 or get started with the open-source gateway on GitHub.