📑 Table of Contents

How to Use OpenAI-Compatible APIs With Claude Code

📅 · 📁 Tutorials · 👁 8 views · ⏱️ 5 min read
💡 Developers struggle to connect Claude Code with OpenAI-compatible endpoints. Here is a step-by-step guide to configuring third-party API providers.

Claude Code users are increasingly trying to connect the tool with third-party OpenAI-compatible API endpoints — and running into frustrating configuration errors. While a simple cURL call to these endpoints works fine, getting Claude Code to properly route requests through them remains a common pain point in developer communities.

The core issue: Claude Code was designed to work with Anthropic's native API, not the widely adopted v1/chat/completions format that OpenAI popularized. Bridging this gap requires specific configuration steps that aren't always well-documented.

Why Developers Want OpenAI-Compatible Endpoints

The OpenAI v1/chat/completions interface has become a de facto standard across the AI industry. Dozens of providers — from open-source model hosts to enterprise API gateways — support this format. Developers want to use Claude Code's powerful agentic coding capabilities while routing requests through:

  • Alternative model providers hosting models like Llama, Qwen, or custom fine-tunes
  • API proxy services that offer cost savings or regional access
  • Self-hosted endpoints running open-weight models like the KAT-Coder-Exp-72B
  • Gateway services that aggregate multiple model providers under one API key
  • Corporate proxy layers required by enterprise IT policies

Common Configuration Mistakes to Avoid

Many developers attempt to solve this by directly editing the settings.json file, adding environment variables like ANTHROPIC_BASE_URL or modifying the API key fields. This approach alone typically fails because Claude Code validates the endpoint format and expects Anthropic-specific response structures.

Another frequent mistake involves using tools like ccswitch with proxy mode enabled. While ccswitch can help manage multiple Claude Code configurations, simply toggling proxy mode on doesn't automatically translate between Anthropic's message format and the OpenAI chat completions format. The two APIs differ in request structure, response formatting, and streaming behavior.

Step-by-Step: The Correct Approach

To properly connect Claude Code with an OpenAI-compatible endpoint, you need a translation layer that converts between the 2 API formats. Here is the recommended workflow:

1. Use a compatible proxy or adapter. Tools like litellm or one-api can sit between Claude Code and your target endpoint. LiteLLM, for example, accepts Anthropic-format requests and translates them into OpenAI-format calls.

2. Configure environment variables properly. Set these in your shell profile or Claude Code's environment config:

ANTHROPIC_BASE_URL — Point this to your proxy's local address (e.g., http://localhost:4000)

ANTHROPIC_API_KEY — Set this to the API key your proxy or target endpoint expects

3. Verify the proxy handles model mapping. Your proxy must map Claude model names to whatever model your endpoint serves. For example, mapping claude-sonnet-4-20250514 to KAT-Coder-Exp-72B-1010 on the backend.

4. Test streaming support. Claude Code relies heavily on streaming responses. Ensure your endpoint and proxy both support server-sent events (SSE) in the Anthropic Messages API format.

LiteLLM: The Most Reliable Bridge

LiteLLM has emerged as the go-to solution for this use case. It supports over 100 model providers and can expose them through an Anthropic-compatible interface. A basic setup takes under 5 minutes:

Install with pip install litellm[proxy], create a config mapping your models, then launch the proxy server. Claude Code connects to the local proxy as if it were talking to Anthropic's servers directly.

The key advantage is that LiteLLM handles all the format translation — including tool use, system prompts, and streaming — automatically.

What to Expect Going Forward

Anthropic has not officially announced plans to add native OpenAI-compatible endpoint support to Claude Code. However, the growing demand from the developer community suggests this could change. For now, the proxy-based approach remains the most stable solution.

Developers should also watch for updates to Claude Code's --model and --provider flags, which Anthropic has been expanding in recent releases to support additional backends including Amazon Bedrock and Google Vertex AI. These official integrations may eventually pave the way for broader third-party endpoint support.