How to Use GPT with Claude Code | LiteLLM & Router Configuration
For those who have searched "Claude Code is useful, but can I run it with my existing OpenAI (GPT) account?" — this article walks through the concrete steps to route Claude Code requests to GPT-based models. We cover why direct usage isn't possible, two configuration approaches using a router and an LLM gateway, and the feature limitations and billing considerations to keep in mind after setup, all based on official documentation.
Because Claude Code is designed specifically for Claude, using GPT requires inserting a proxy (relay server) in between that converts the request format. Claude Code allows you to swap the connection destination via ANTHROPIC_BASE_URL, so placing a converter at that endpoint makes it possible to reach GPT.
The easiest option is claude-code-router (which runs a local relay server and routes requests to different models based on use case). For team usage or cost management, the LiteLLM gateway — with officially published setup instructions — is the better fit.
However, switching to GPT restricts some features optimized for Claude. This includes the requirement for OpenAI API billing (not a ChatGPT subscription). It's best to understand the benefits and limitations before making your choice.
目次 (8)
- What Using GPT with Claude Code Means — What's Possible and What Isn't
- Why You Can't Specify GPT Directly — The API Format Difference
- Method 1: Route to GPT Using claude-code-router
- Method 2: Via LiteLLM Gateway (Official Instructions)
- Feature Limitations to Be Aware of After Setup
- Billing and Subscription Considerations
- If You're Serious About GPT, Codex CLI Is Another Option
- Summary — Who Is This For?
What Using GPT with Claude Code Means — What's Possible and What Isn't
Claude Code is a coding tool designed by Anthropic for Claude models. By default, it connects to Anthropic's endpoint and sends requests to Claude. However, Claude Code is structured to allow swapping the connection URL via an environment variable — placing a "format-converting relay server" at that destination makes it possible to route requests to GPT and other third-party models.
In other words, you can "keep the Claude Code interface and workflow intact while swapping the brain for GPT." That said, there is no built-in setting to directly specify GPT within Claude Code — a conversion layer is always required.
Why You Can't Specify GPT Directly — The API Format Difference
The requests Claude Code sends follow the Anthropic Messages format (/v1/messages). GPT, on the other hand, accepts OpenAI Chat Completions format — the two use different communication "grammars." Sending directly to a GPT endpoint results in an uninterpretable request.
That's why you need to insert a proxy with a transformer (conversion layer) in between, which converts bidirectionally between the Anthropic format and the OpenAI format. The official documentation explicitly states that a gateway must "expose at least one endpoint in Anthropic Messages format" as a condition for integrating with Claude Code. Source: Claude Code Official Documentation
Method 1: Route to GPT Using claude-code-router
For quick personal experimentation, the OSS tool claude-code-router (by musistudio) is the go-to option. It runs a local relay server (default: localhost:3456) and routes requests to different models based on use case. Source: GitHub musistudio/claude-code-router
The setup flow is as follows:
- Install the tool with
npm install -g @musistudio/claude-code-router. - In the
config.jsonfile, underProviders, specify the provider you want to use (such as OpenRouter or an OpenAI-compatible endpoint) withname/api_base_url/api_key/models/transformer. - In the
Routersection, assign models to each scenario:default(general tasks),background,think(reasoning),longContext(long text), andwebSearch.
Below is a minimal config.json sample specifying GPT-4o via OpenRouter as a single model. You can use it directly as a template.
{
"Providers": [
{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1",
"api_key": "sk-or-xxxx",
"models": ["openai/gpt-4o"],
"transformer": {"use": "openai"}
}
],
"Router": {
"default": "openrouter,openai/gpt-4o"
}
}
Enter your OpenRouter key in api_key, and update the models and Router.default values to match the model ID you want to use.
- Run
eval "$(ccr activate)". This setsANTHROPIC_BASE_URLto the relay server (http://127.0.0.1:3456). - Launch Claude Code with
ccr code— requests will be routed through the relay server to the specified model.
It supports multiple providers including OpenRouter, DeepSeek, Ollama, and Gemini. Via OpenRouter, GPT-based models can also be specified through this mechanism. The key advantage is smart per-use-case switching — for example, using a cheaper model for general tasks and a more powerful one only when reasoning is required.
Method 2: Via LiteLLM Gateway (Official Instructions)
If you prioritize team-level usage management, cost tracking, and audit logs, the LiteLLM route — for which Claude Code officially publishes setup instructions — is the better choice. LiteLLM is a proxy that aggregates numerous model providers and can expose Anthropic-format endpoints.
The key configuration points are:
- Launch the LiteLLM Proxy Server and configure the target provider (e.g., OpenAI) and the models to use on the LiteLLM side.
- Point Claude Code's connection to the unified endpoint (the officially recommended approach). Example:
export ANTHROPIC_BASE_URL=https://litellm-server:4000. - Set an authentication token. Example:
export ANTHROPIC_AUTH_TOKEN=sk-litellm-static-key(this value is sent as theAuthorizationheader).
The official documentation recommends the "unified endpoint" — which supports load balancing, fallback, and cost tracking — over a provider-specific passthrough approach. Source: Claude Code Official Documentation
Note that the official documentation includes an important warning: LiteLLM PyPI versions 1.82.7 and 1.82.8 contained malware that stole credentials — do not install these versions. It also notes that LiteLLM is a third-party product and Anthropic does not provide guarantees or audits. Always check the latest official information before installation.
Feature Limitations to Be Aware of After Setup
When switching to GPT, some features optimized for Claude may not work as expected. These include extended thinking, prompt caching, and Anthropic-specific beta features. The official documentation also notes that when using the Anthropic Messages format via an alternate route, you may need to set CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1. Source
Additionally, while Claude Code's framework — such as CLAUDE.md and tool integrations — remains usable, the model's actual behavior (code comprehension and instruction-following tendencies) changes to that of GPT. Understanding it as "the same interface, but with a different brain" will help you not be surprised by differences in output.
Billing and Subscription Considerations
One easy-to-overlook aspect is the billing structure. Calling GPT through this method requires an OpenAI API key (pay-as-you-go), which is separate from a ChatGPT monthly subscription. Even if you have ChatGPT Plus, that subscription does not make GPT calls through Claude Code free.
Since requests pass through a relay server, token consumption directly maps to API charges. Using a gateway like LiteLLM with cost tracking and spending limits is a good way to stay on top of costs.
If You're Serious About GPT, Codex CLI Is Another Option
If your goal isn't "try GPT while keeping the Claude Code feel" but rather "use GPT (OpenAI) as the primary tool for terminal-based coding," then Codex CLI — OpenAI's own terminal coding tool — is the natural choice. It's included with a ChatGPT subscription at no additional charge. We've compared the two tools across five dimensions in a separate article. See also: Claude Code vs. Codex CLI Comparison.
Summary — Who Is This For?
Using GPT with Claude Code is suited for the following types of users:
- Those who want to compare models while keeping their existing Claude Code workflow and settings intact.
- Those who want to intelligently switch between cheaper and more powerful models by use case to optimize costs.
- Teams that want to centrally manage multiple providers and track usage and costs.
On the other hand, if you want to take full advantage of Claude-optimized features, or if you'd rather avoid the extra setup, simply using Claude is the more comfortable option. A practical two-step approach would be: start by trying claude-code-router locally, then migrate to a LiteLLM gateway when you're ready to put it into regular use.