How to Use Claude Code with Any Model or Provider Using Bifrost

How to Use Claude Code with Any Model or Provider Using Bifrost

Claude Code is Anthropic's terminal-based AI coding agent. Out of the box, it connects to Anthropic's API and uses Claude models exclusively. This works well for many use cases, but production engineering teams often need more flexibility: the ability to route Claude Code traffic through alternative providers, use non-Claude models for specific tiers, enforce governance policies, or gain centralized observability over all agent interactions.

Bifrost solves this by acting as a fully compatible Anthropic API endpoint that sits between Claude Code and any LLM provider. By changing a single environment variable, you can route all Claude Code traffic through Bifrost and unlock access to 20+ providers including OpenAI, AWS Bedrock, Google Vertex, Azure, Groq, Mistral, and more.

This guide walks through the complete setup, from installation to model overrides to MCP tool integration.

Prerequisites

Before connecting Claude Code to Bifrost, ensure you have:

  • Node.js installed (for both Claude Code and Bifrost)
  • Claude Code installed globally via npm install -g @anthropic-ai/claude-code
  • Bifrost running locally or on a remote server. The fastest way to get started is with zero-config startup:
# Install and run Bifrost locally
npx -y @maximhq/bifrost
  • At least one AI provider configured in Bifrost's web UI at http://localhost:8080 or via config.json

Step 1: Point Claude Code at Bifrost

Bifrost provides a 100% compatible Anthropic API endpoint at /anthropic. Claude Code uses two environment variables to determine where it sends requests: ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY. Redirecting traffic to Bifrost requires setting both:

export ANTHROPIC_API_KEY=dummy-key
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic

The ANTHROPIC_API_KEY value can be a placeholder string when Bifrost handles key management internally. If you have governance enabled with Virtual Keys, use your Bifrost Virtual Key value instead.

Now launch Claude Code:

claude

All Claude Code traffic now flows through Bifrost. This setup also automatically detects if you are using an Anthropic MAX account instead of standard API key authentication.

Step 2: Override Default Model Tiers

Claude Code organizes its model usage into three tiers: Sonnet (the default for most tasks), Opus (for complex reasoning), and Haiku (for fast, lightweight operations). With Bifrost, you can override any of these tiers to use a model from any configured provider.

Set the following environment variables to remap each tier:

# Replace the Sonnet tier with OpenAI GPT-5
export ANTHROPIC_DEFAULT_SONNET_MODEL="openai/gpt-5"

# Replace the Opus tier with Claude Opus 4.5
export ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-4-5-20251101"

# Replace the Haiku tier with Azure-hosted Claude
export ANTHROPIC_DEFAULT_HAIKU_MODEL="azure/claude-haiku-4-5"

The provider/model format tells Bifrost exactly which provider and model to route to. Any provider configured in your Bifrost instance is available here, including Groq, Vertex AI, Bedrock, Ollama for local inference, and others.

One important constraint: alternative models must support tool use capabilities for file operations, terminal commands, and code editing to function properly with Claude Code. Models that lack tool calling support will fail on core Claude Code operations.

You can also launch Claude Code with a specific model using the --model flag:

# Start Claude Code with Opus
claude --model claude-opus-4-5-20251101

# Start with Haiku for lightweight tasks
claude --model claude-haiku-4-5-20251001

Step 3: Switch Models Mid-Session

Claude Code supports on-the-fly model switching during an active session using the /model command. With Bifrost handling routing, you can switch not just between Claude models but across providers dynamically:

# Shorthand for Claude model tiers
/model opus
/model sonnet
/model haiku

# Full model names
/model claude-opus-4-5-20251101
/model claude-sonnet-4-5-20250929

# Cross-provider models via Bifrost
/model vertex/claude-haiku-4-5
/model azure/claude-sonnet-4-5
/model bedrock/claude-sonnet-4-5

Running /model without arguments shows the currently active model. The switch is instantaneous and Claude Code seamlessly continues your conversation context with the new model.

If you use Claude-specific features like web search, computer use, or citations, ensure the target model also supports those capabilities. Non-Claude models or Claude models on certain providers may not support all features.

Step 4: Connect Bifrost MCP Tools to Claude Code

Bifrost functions as both an MCP client and server. It connects to external MCP tool servers (filesystem, web search, databases, custom APIs) and exposes them through a single MCP endpoint at /mcp. Claude Code can connect to this endpoint to access all aggregated tools.

Add Bifrost as an MCP server to Claude Code with a single command:

claude mcp add --transport http bifrost <http://localhost:8080/mcp>

If you have Virtual Key authentication enabled, use the JSON configuration format instead:

claude mcp add-json bifrost '{"type":"http","url":"<http://localhost:8080/mcp","headers":{"Authorization":"Bearer> bf-virtual-key"}}'

Replace bf-virtual-key with your actual Virtual Key. Claude Code will then only have access to the specific MCP tools permitted by that key's configuration. You can modify tool permissions through the Bifrost dashboard or the MCP Gateway URL API.

This MCP integration is available on Bifrost v1.4.0-prerelease1 and above.

Step 5: Monitor All Claude Code Activity

Every request Claude Code sends through Bifrost is automatically logged with full metadata: input messages, model parameters, provider context, token usage, costs, and latency. You can view all agent interactions in real time through the built-in observability dashboard at http://localhost:8080/logs, with the ability to filter by provider, model, or conversation content.

For production deployments, Bifrost also supports Prometheus-based telemetry with native metrics at the /metrics endpoint, and OpenTelemetry integration for distributed tracing with platforms like Grafana, Datadog, and New Relic.

Provider Compatibility Notes

Not all providers work equally well with Claude Code. Since Claude Code heavily relies on tool calling for file operations, terminal commands, and code editing, providers must properly support and stream tool call arguments.

Known issues documented in Bifrost's docs:

  • OpenRouter does not stream function call arguments properly, causing tool calls to return with empty arguments fields. This breaks Claude Code's file and terminal operations.
  • Some proxy providers may not fully implement the Anthropic API streaming specification for tool calls.

If you experience tool call failures, switching to a different provider in your Bifrost configuration typically resolves the issue. Direct provider endpoints (Anthropic, OpenAI, Azure, Bedrock, Vertex) tend to have the most reliable tool calling support.

Putting It All Together

Here is a complete setup that configures Claude Code with Bifrost, custom model tiers, and persistent configuration:

# Core Bifrost connection
export ANTHROPIC_API_KEY=your-bifrost-virtual-key
export ANTHROPIC_BASE_URL=http://localhost:8080/anthropic

# Custom model tier overrides
export ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-4-5-20250929"
export ANTHROPIC_DEFAULT_OPUS_MODEL="openai/gpt-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="azure/claude-haiku-4-5"

# Launch Claude Code
claude

Add these exports to your ~/.bashrc or ~/.zshrc for persistent configuration across terminal sessions.

With this setup, every Claude Code session benefits from Bifrost's automatic fallbacks, load balancing, semantic caching, budget controls, and centralized observability, all without any changes to how you use Claude Code.

For teams evaluating Bifrost for production Claude Code deployments at scale, book a demo to explore enterprise features like clustering, guardrails, vault support, and in-VPC deployments.