Skip to content

Repository files navigation

Claude Code Multi-Model Proxy

PyPI version License: MIT Python 3.10+

Use Claude Code with any model from providers like GreenPT, Eurouter, OpenRouter, Together AI, Groq, and more. This lightweight proxy translates Anthropic Messages API to OpenAI Chat Completions API format, unlocking access to hundreds of models.

🎁 Featured Providers

Provider Highlights Get Started
GreenPT Fast inference, great coding models (Qwen, DeepSeek, Llama) Get $5 Free Credits β†’
Eurouter EU-based infrastructure, DeepSeek models Visit Eurouter β†’
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      Anthropic API      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      OpenAI API      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚ ────────────────────▢   β”‚                 β”‚ ──────────────────▢  β”‚    Eurouter     β”‚
β”‚   Claude Code   β”‚                         β”‚     Proxy       β”‚                      β”‚    GreenPT      β”‚
β”‚                 β”‚ ◀────────────────────   β”‚                 β”‚ ◀──────────────────  β”‚   OpenRouter    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Features

  • βœ… Full message translation β€” Anthropic ↔ OpenAI formats
  • βœ… Streaming support β€” Real-time response streaming via SSE
  • βœ… Tool/Function calling β€” Anthropic tools to OpenAI functions
  • βœ… System prompts β€” Proper system message handling
  • βœ… Multi-turn conversations β€” Full context preservation
  • βœ… Model mapping β€” Map Claude tiers (Opus/Sonnet/Haiku) to any models
  • βœ… Web configuration UI β€” Configure via browser at http://localhost:8080
  • βœ… Docker support β€” Easy containerized deployment

Quick Start

Option 1: pip (Recommended)

pip install claude-code-multi-model-proxy

Then run with GreenPT (get free credits):

claude-code-proxy \
  --target-url https://api.greenpt.ai/v1 \
  --api-key YOUR_API_KEY \
  --default-model qwen3-coder-30b-a3b-instruct

Or with Eurouter:

claude-code-proxy \
  --target-url https://api.eurouter.ai/api/v1 \
  --api-key YOUR_API_KEY \
  --default-model deepseek/deepseek-chat-v3

Option 2: From Source

git clone https://github.com/robertkeus/claude-code-all-models.git
cd claude-code-all-models
pip install -r requirements.txt
python -m anthropic_openai_proxy.proxy --target-url https://api.eurouter.ai/api/v1 --api-key YOUR_API_KEY

Option 3: Docker

docker run -p 8080:8080 \
  -e TARGET_URL=https://api.eurouter.ai/api/v1 \
  -e API_KEY=your-api-key \
  -e DEFAULT_MODEL=deepseek/deepseek-chat-v3 \
  robertkeus/claude-code-all-models

Option 4: Docker Compose

# Set your API key
export GREENPT_API_KEY=your-api-key

# Run
docker-compose up -d

Usage with Claude Code

Step 1: Start the proxy

claude-code-proxy \
  --target-url https://api.eurouter.ai/api/v1 \
  --api-key YOUR_API_KEY \
  --default-model deepseek/deepseek-chat-v3

Step 2: Configure Claude Code

# Log out of any existing Anthropic account
claude logout

# Set environment variables
export ANTHROPIC_BASE_URL=http://localhost:8080
export ANTHROPIC_AUTH_TOKEN=proxy
export ANTHROPIC_API_KEY=""

# Run Claude Code
claude --model gpt-4

One-liner

claude logout && \
ANTHROPIC_BASE_URL=http://localhost:8080 \
ANTHROPIC_AUTH_TOKEN=proxy \
ANTHROPIC_API_KEY="" \
claude --model gpt-4

Configuration

Command-Line Options

Flag Environment Variable Default Description
--target-url TARGET_URL https://api.openai.com/v1 OpenAI-compatible API base URL
--api-key API_KEY "" API key for target endpoint
--default-model DEFAULT_MODEL gpt-4 Default model name
--opus-model OPUS_MODEL (default) Model for Claude Opus requests
--sonnet-model SONNET_MODEL (default) Model for Claude Sonnet requests
--haiku-model HAIKU_MODEL (default) Model for Claude Haiku requests
--port PORT 8080 Proxy server port
--host HOST 0.0.0.0 Host to bind to

Model Mapping

Claude Code uses different models for different tasks. You can map each tier to specific models on your provider:

claude-code-proxy \
  --target-url https://api.eurouter.ai/api/v1 \
  --api-key YOUR_KEY \
  --default-model deepseek/deepseek-chat-v3 \
  --haiku-model deepseek/deepseek-chat-v3 \
  --sonnet-model deepseek/deepseek-chat-v3 \
  --opus-model deepseek/deepseek-r1
Claude Tier Use Case Suggested Mapping
Haiku Quick tasks, summaries, titles Fast/cheap model
Sonnet Main coding tasks Good coding model
Opus Complex reasoning Best available model

Web Configuration UI

Access the configuration interface at http://localhost:8080 after starting the proxy:

  1. Select your provider (GreenPT, OpenRouter, or custom)
  2. Enter your API key
  3. Choose models for each Claude tier
  4. Save and copy the launch commands

Supported Providers

Provider Target URL Example Model
GreenPT ⭐ https://api.greenpt.ai/v1 qwen3-coder-30b-a3b-instruct
Eurouter ⭐ https://api.eurouter.ai/api/v1 deepseek/deepseek-chat-v3
OpenRouter https://openrouter.ai/api/v1 openai/gpt-4-turbo
Together AI https://api.together.xyz/v1 meta-llama/Llama-3-70b-chat-hf
Groq https://api.groq.com/openai/v1 llama-3.1-70b-versatile
Fireworks https://api.fireworks.ai/inference/v1 accounts/fireworks/models/llama-v3-70b
LM Studio http://localhost:1234/v1 local-model
Ollama http://localhost:11434/v1 llama3
OpenAI https://api.openai.com/v1 gpt-4-turbo

πŸ’‘ New to this? Get $5 free credits from GreenPT to try it out!


API Translation Reference

Endpoints

Anthropic (incoming) OpenAI (outgoing)
POST /v1/messages POST /v1/chat/completions
POST /v1/messages/count_tokens (estimated locally)

Request Format Translation

Anthropic format (Claude Code sends this):

{
  "model": "claude-3-sonnet-20240229",
  "max_tokens": 1024,
  "system": "You are a helpful assistant.",
  "messages": [
    {"role": "user", "content": "Hello"}
  ]
}

OpenAI format (Proxy sends this):

{
  "model": "gpt-4",
  "max_tokens": 1024,
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello"}
  ]
}

Response Format Translation

OpenAI format (Provider returns this):

{
  "choices": [{"message": {"content": "Hi there!"}, "finish_reason": "stop"}],
  "usage": {"prompt_tokens": 10, "completion_tokens": 3}
}

Anthropic format (Proxy returns this):

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [{"type": "text", "text": "Hi there!"}],
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 10, "output_tokens": 3}
}

Troubleshooting

"Auth conflict" error in Claude Code

You need to log out of Anthropic first:

claude logout

Connection refused

Make sure the proxy is running before starting Claude Code:

# Terminal 1: Start proxy
claude-code-proxy --target-url ... --api-key ...

# Terminal 2: Start Claude Code
ANTHROPIC_BASE_URL=http://localhost:8080 claude --model deepseek/deepseek-chat-v3

Model not found

Specify the exact model name that your provider supports:

claude --model qwen3-coder-30b-a3b-instruct

Streaming issues

If you experience streaming problems, the proxy automatically falls back to simulated streaming from non-streaming responses.


Development

Setup

git clone https://github.com/robertkeus/claude-code-all-models.git
cd claude-code-all-models

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install with dev dependencies
pip install -e ".[dev]"

Running Tests

pytest

Code Quality

# Format
black src/ proxy.py

# Lint
ruff check src/ proxy.py

# Type check
mypy src/

Publishing

To PyPI

# Install build tools
pip install build twine

# Build
python -m build

# Upload to PyPI
twine upload dist/*

To Docker Hub

# Build
docker build -t robertkeus/claude-code-all-models .

# Push
docker push robertkeus/claude-code-all-models

Architecture

anthropic-openai-proxy/
β”œβ”€β”€ src/
β”‚   └── anthropic_openai_proxy/
β”‚       β”œβ”€β”€ __init__.py       # Package entry point
β”‚       β”œβ”€β”€ proxy.py          # Main FastAPI application
β”‚       β”œβ”€β”€ config.py         # Configuration & model mapping
β”‚       β”œβ”€β”€ routes.py         # API route handlers
β”‚       β”œβ”€β”€ converters.py     # Format translation logic
β”‚       β”œβ”€β”€ streaming.py      # SSE stream handling
β”‚       └── templates/
β”‚           └── config.html   # Web configuration UI
β”œβ”€β”€ public/
β”‚   └── assets/               # Static assets
β”œβ”€β”€ Dockerfile                # Docker build configuration
β”œβ”€β”€ docker-compose.yml        # Docker Compose setup
β”œβ”€β”€ pyproject.toml            # Python package configuration
└── requirements.txt          # Dependencies

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

Disclaimer

This project is not affiliated with, endorsed by, or associated with GreenPT, OpenRouter, Eurouter, Anthropic, or any other API provider mentioned in this documentation.

Use at your own risk. The authors and contributors are not responsible for any damages, data loss, API costs, or other issues that may arise from using this software. Always review your API provider's terms of service before use.


License

MIT License - See LICENSE for details.


Acknowledgments

  • Anthropic for Claude and Claude Code
  • FastAPI for the excellent web framework
  • All the OpenAI-compatible API providers

About

Connect Claude Code to any OpenAI-compatible API. This proxy translates requests from Claude Code to work with alternative providers.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages