claude-code-proxy
Connect Claude Code to alternative models from OpenAI or Gemini.
Forked from: 1rgs/claude-code-proxy
Quick start
uvx claude-code-proxy
Installation
Prerequisites
- Set
OPENAI_API_KEYorGEMINI_API_KEYin your environment. - Install
uv:- Install docs here: https://docs.astral.sh/uv/getting-started/installation
- On MacOS:
brew install uv - On Windows:
winget install astral-sh.uv
Configuration
[!WARNING]
Readme rewrite is in progress on everything below
-
Configure Environment Variables: Copy the example environment file:
cp .env.example .env
Edit
.envand fill in your API keys and model configurations:ANTHROPIC_API_KEY: (Optional) Needed only if proxying to Anthropic models.OPENAI_API_KEY: Your OpenAI API key (Required if using the default OpenAI preference or as fallback).GEMINI_API_KEY: Your Google AI Studio (Gemini) API key (Required if PREFERRED_PROVIDER=google).PREFERRED_PROVIDER(Optional): Set toopenai(default) orgoogle. This determines the primary backend for mappinghaiku/sonnet.BIG_MODEL(Optional): The model to mapsonnetrequests to. Defaults togpt-4.1(ifPREFERRED_PROVIDER=openai) orgemini-2.5-pro-preview-03-25.SMALL_MODEL(Optional): The model to maphaikurequests to. Defaults togpt-4.1-mini(ifPREFERRED_PROVIDER=openai) orgemini-2.0-flash.
Mapping Logic:
- If
PREFERRED_PROVIDER=openai(default),haiku/sonnetmap toSMALL_MODEL/BIG_MODELprefixed withopenai/. - If
PREFERRED_PROVIDER=google,haiku/sonnetmap toSMALL_MODEL/BIG_MODELprefixed withgemini/if those models are in the server's knownGEMINI_MODELSlist (otherwise falls back to OpenAI mapping).
-
Run the server:
uv run uvicorn server:app --host 0.0.0.0 --port 8082 --reload
(
--reloadis optional, for development)
Using with Claude Code 🎮
-
Install Claude Code (if you haven't already):
npm install -g @anthropic-ai/claude-code
-
Connect to your proxy:
ANTHROPIC_BASE_URL=http://localhost:8082 claude
-
That's it! Your Claude Code client will now use the configured backend models (defaulting to Gemini) through the proxy. 🎯
Model Mapping 🗺️
The proxy automatically maps Claude models to either OpenAI or Gemini models based on the configured model:
| Claude Model | Default Mapping | When BIG_MODEL/SMALL_MODEL is a Gemini model |
|---|---|---|
| haiku | openai/gpt-4o-mini | gemini/[model-name] |
| sonnet | openai/gpt-4o | gemini/[model-name] |
Supported Models
OpenAI Models
The following OpenAI models are supported with automatic openai/ prefix handling:
- o3-mini
- o1
- o1-mini
- o1-pro
- gpt-4.5-preview
- gpt-4o
- gpt-4o-audio-preview
- chatgpt-4o-latest
- gpt-4o-mini
- gpt-4o-mini-audio-preview
- gpt-4.1
- gpt-4.1-mini
Gemini Models
The following Gemini models are supported with automatic gemini/ prefix handling:
- gemini-2.5-pro-preview-03-25
- gemini-2.0-flash
Model Prefix Handling
The proxy automatically adds the appropriate prefix to model names:
- OpenAI models get the
openai/prefix - Gemini models get the
gemini/prefix - The BIG_MODEL and SMALL_MODEL will get the appropriate prefix based on whether they're in the OpenAI or Gemini model lists
For example:
gpt-4obecomesopenai/gpt-4ogemini-2.5-pro-preview-03-25becomesgemini/gemini-2.5-pro-preview-03-25- When BIG_MODEL is set to a Gemini model, Claude Sonnet will map to
gemini/[model-name]
Customizing Model Mapping
Control the mapping using environment variables in your .env file or directly:
Example 1: Default (Use OpenAI)
No changes needed in .env beyond API keys, or ensure:
OPENAI_API_KEY="your-openai-key"
GEMINI_API_KEY="your-google-key" # Needed if PREFERRED_PROVIDER=google
# PREFERRED_PROVIDER="openai" # Optional, it's the default
# BIG_MODEL="gpt-4.1" # Optional, it's the default
# SMALL_MODEL="gpt-4.1-mini" # Optional, it's the default
Example 2: Prefer Google
GEMINI_API_KEY="your-google-key"
OPENAI_API_KEY="your-openai-key" # Needed for fallback
PREFERRED_PROVIDER="google"
# BIG_MODEL="gemini-2.5-pro-preview-03-25" # Optional, it's the default for Google pref
# SMALL_MODEL="gemini-2.0-flash" # Optional, it's the default for Google pref
Example 3: Use Specific OpenAI Models
OPENAI_API_KEY="your-openai-key"
GEMINI_API_KEY="your-google-key"
PREFERRED_PROVIDER="openai"
BIG_MODEL="gpt-4o" # Example specific model
SMALL_MODEL="gpt-4o-mini" # Example specific model
How It Works 🧩
This proxy works by:
- Receiving requests in Anthropic's API format 📥
- Translating the requests to OpenAI format via LiteLLM 🔄
- Sending the translated request to OpenAI 📤
- Converting the response back to Anthropic format 🔄
- Returning the formatted response to the client ✅
The proxy handles both streaming and non-streaming responses, maintaining compatibility with all Claude clients. 🌊
Contributing 🤝
Contributions are welcome! Please feel free to submit a Pull Request. 🎁
Release files for claude-code-proxy 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| claude_code_proxy-0.1.5.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| claude_code_proxy-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.0 kB
Release files / claude_code_proxy-0.1.5.tar.gz
| Download URL | claude_code_proxy-0.1.5.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4234b19ed9e0dadd7ecd430adbc2728aa374771f32bb0f1530b5d4e6e63627e2
|
|
BLAKE2b-256 checksum How to use checksums |
ec3bfa61383655deab9f2146a68dbf0007b8cdbf5401abf26f354f219f38f1fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.8
|
Release files / claude_code_proxy-0.1.5-py3-none-any.whl
| Download URL | claude_code_proxy-0.1.5-py3-none-any.whl |
|---|---|
| Size | 18.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e410a4ce6332dfc1fcc8d63c6ab6304a032c0d3744678dd5628c67eefbad897
|
|
BLAKE2b-256 checksum How to use checksums |
1c97bcd53d9c45c6866c8b076beb2d133eb2fad8b4317aa0bd98011a78976e82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.8
|