---
title: How to Use Claude Code with Any Model or Provider Using Bifrost
description: "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,"
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-any-model-or-provider-using-bifr-bifrost-weave.optimized.png
---

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

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](https://docs.getbifrost.ai/overview) 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 [23+ providers](https://docs.getbifrost.ai/providers/supported-providers/overview) 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](https://docs.getbifrost.ai/quickstart/gateway/setting-up):

```bash
# 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](https://docs.getbifrost.ai/quickstart/gateway/provider-configuration)

## Step 1: Point Claude Code at Bifrost

Bifrost provides a [100% compatible Anthropic API endpoint](https://docs.getbifrost.ai/integrations/anthropic-sdk/overview) 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:

```bash
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](https://docs.getbifrost.ai/features/governance/virtual-keys) with Virtual Keys, use your Bifrost Virtual Key value instead.

Now launch Claude Code:

```bash
claude
```

All Claude Code traffic now flows through Bifrost. This setup also [automatically detects](https://docs.getbifrost.ai/quickstart/gateway/cli-agents#claude-code) 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](https://docs.getbifrost.ai/quickstart/gateway/cli-agents#model-configuration) to remap each tier:

```bash
# 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](https://docs.getbifrost.ai/providers/supported-providers/groq), [Vertex AI](https://docs.getbifrost.ai/providers/supported-providers/vertex), [Bedrock](https://docs.getbifrost.ai/providers/supported-providers/bedrock), [Ollama](https://docs.getbifrost.ai/providers/supported-providers/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:

```bash
# 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:

```bash
# 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](https://docs.getbifrost.ai/quickstart/gateway/cli-agents#switching-models-mid-session) 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](https://docs.getbifrost.ai/mcp/overview). 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:

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

If you have [Virtual Key authentication](https://docs.getbifrost.ai/features/governance/virtual-keys) enabled, use the JSON configuration format instead:

```bash
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](https://docs.getbifrost.ai/features/governance/mcp-tools). You can modify tool permissions through the Bifrost dashboard or the [MCP Gateway URL](https://docs.getbifrost.ai/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](https://docs.getbifrost.ai/features/observability/default) 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](https://docs.getbifrost.ai/features/telemetry) with native metrics at the `/metrics` endpoint, and [OpenTelemetry](https://docs.getbifrost.ai/features/observability/otel) 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](https://docs.getbifrost.ai/quickstart/gateway/cli-agents#provider-compatibility).

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:

```bash
# 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](https://docs.getbifrost.ai/features/fallbacks), [load balancing](https://docs.getbifrost.ai/features/keys-management), [semantic caching](https://docs.getbifrost.ai/features/semantic-caching), [budget controls](https://docs.getbifrost.ai/features/governance/budget-and-limits), 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](https://www.getmaxim.ai/book-a-demo) to explore enterprise features like clustering, guardrails, vault support, and in-VPC deployments.

## Read next

[![9 Best Self-Hosted AI Tools for Enterprise Teams](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/9-best-self-hosted-ai-tools-for-enterprise-teams-bifrost-1920x1080@2x.png) Self-hosted AI runs models, apps, and data services on infrastructure a team controls. This guide ranks nine tools by stack layer, including Bifrost, vLLM, Ollama, Open WebUI, and Qdrant, and shows how one gateway governs the whole stack.](https://www.getmaxim.ai/articles/self-hosted-ai-tools/)

[![7 Best Private AI Platforms for Regulated Enterprises](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/7-best-private-ai-platforms-for-regulated-enterprises-bifrost-1920x1080@2x.png) A private AI platform runs models and AI traffic inside infrastructure the organization controls. This guide ranks seven options, including Bifrost, NVIDIA AI Enterprise, Red Hat OpenShift AI, and Google Distributed Cloud air-gapped, on deployment, isolation, and governance.](https://www.getmaxim.ai/articles/private-ai-platforms/)

[![9 Best Open Source LLMs to Self-Host](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/9-best-open-source-llms-to-self-host-bifrost-1920x1080@2x.png) The best open source LLM to self-host is the one whose license, hardware footprint, and runtime support fit the deployment. This guide ranks nine open-weight models, including Qwen3.8, DeepSeek V4.1, GLM-5.3, and gpt-oss, and shows how to serve them behind Bifrost.](https://www.getmaxim.ai/articles/best-open-source-llms/)

## More in AI Gateway

[![Top 5 Enterprise AI Gateways for Semantic Caching and Dynamic Routing for Cost Optimization of AI Applications](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/07/top-5-enterprise-ai-gateways-for-semantic-caching-and-dynami-bifrost-weave--1-.optimized.png) As production AI applications scale, two infrastructure challenges dominate engineering budgets: redundant LLM API calls and inefficient provider routing. Organizations running high-volume inference workloads routinely overpay due to repeated queries hitting provider APIs instead of being served from cache, and static routing configurations that ignore real-time provider performance.](https://www.getmaxim.ai/articles/top-5-enterprise-ai-gateways-for-semantic-caching-and-dynamic-routing-for-cost-optimization-of-ai-applications/)

[![Best AI Gateways for Routing Claude Code Requests in Production](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/10/best-ai-gateways-for-routing-claude-code-requests-in-product-bifrost-isometric.png) Routing Claude Code through an AI gateway takes two environment variables, but provider compatibility decides whether it works at all. This guide compares Bifrost, LiteLLM, Cloudflare, Kong, and OpenRouter on tool-call support, attribution, and latency.](https://www.getmaxim.ai/articles/best-ai-gateways-for-routing-claude-code-requests-in-production/)

```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 Any Model or Provider Using Bifrost",
    "url": "https://www.getmaxim.ai/articles/how-to-use-claude-code-with-any-model-or-provider-using-bifrost/",
    "datePublished": "2026-03-11T18:05:00.000Z",
    "dateModified": "2026-10-13T11:03:31.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-any-model-or-provider-using-bifr-bifrost-weave.optimized.png",
        "width": 1200,
        "height": 630
    },
    "keywords": "AI Gateway",
    "description": "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.\n\nBifrost solves this by acting as a fully compatible A",
    "mainEntityOfPage": "https://www.getmaxim.ai/articles/how-to-use-claude-code-with-any-model-or-provider-using-bifrost/"
}
```
