Proxy Claude API requests to OpenAI-compatible backends
Project description
openai2claude
Proxy server that converts Claude API requests to OpenAI-compatible backends. This allows you to use the Anthropic Claude SDK with any OpenAI-compatible API provider.
Installation
pip install openai2claude
Quick Start
- Start the proxy server:
export OPENAI2CLAUDE_BACKEND=https://api.openai.com/v1
export OPENAI2CLAUDE_API_KEY=sk-your-api-key
openai2claude
Or with command-line arguments:
openai2claude --backend https://api.openai.com/v1 --api-key sk-your-api-key
- Configure your Claude SDK code to use the proxy:
import anthropic
client = anthropic.Anthropic(
base_url="http://localhost:8000"
)
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, world!"}]
)
Or via environment variable:
export ANTHROPIC_API_BASE="http://localhost:8000"
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
OPENAI2CLAUDE_BACKEND |
http://localhost:8080/v1 |
OpenAI-compatible backend URL |
OPENAI2CLAUDE_API_KEY |
sk-xxx... |
API key for the backend |
OPENAI2CLAUDE_HOST |
0.0.0.0 |
Proxy server host |
OPENAI2CLAUDE_PORT |
8000 |
Proxy server port |
OPENAI2CLAUDE_LOG_LEVEL |
INFO |
Logging level |
OPENAI2CLAUDE_TIMEOUT |
300 |
Request timeout in seconds |
OPENAI2CLAUDE_VERIFY_SSL |
true |
Verify SSL certificates |
Command-Line Options
openai2claude [OPTIONS]
Options:
-b, --backend TEXT OpenAI-compatible backend URL
-k, --api-key TEXT API key for the backend
-h, --host TEXT Host to bind the proxy server
-p, --port INTEGER Port to bind the proxy server
-l, --log-level TEXT Logging level (debug, info, warning, error)
-t, --timeout FLOAT Request timeout in seconds
--no-verify-ssl Disable SSL certificate verification
--version Show version
Architecture
┌─────────────┐ ┌─────────────────┐ ┌────────────────────┐
│ Your Code │───>│ openai2claude │───>│ OpenAI Backend │
│ Claude SDK │ │ (localhost │ │ (api.openai.com, │
│ │<───│ :8000) │<───│ ollama, etc.) │
└─────────────┘ └─────────────────┘ └────────────────────┘
The proxy:
- Accepts requests in Claude API format (
/v1/messages) - Converts them to OpenAI API format (
/v1/chat/completions) - Forwards to the configured backend
- Converts responses back to Claude format
Features
- Format Conversion: Automatically converts between Claude and OpenAI API formats
- Tool Calling Fix: Fixes malformed tool calls (e.g.,
cmd/input->command) for Bash tools - Streaming Support: Full SSE streaming support for real-time responses
- System Prompt Injection: Adds tool usage instructions to prevent common errors
- Environment Variables: Full configuration via environment variables
- CLI Interface: Easy-to-use command-line interface with
--help
Use Cases
- Use Claude SDK with local models: Point to Ollama, LM Studio, or other OpenAI-compatible local servers
- Multi-provider support: Switch between OpenAI, Azure, or other OpenAI-compatible providers
- Development and testing: Test Claude code against mock or local backends
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
openai2claude-0.1.0.tar.gz
(11.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai2claude-0.1.0.tar.gz.
File metadata
- Download URL: openai2claude-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73a92ab237e1eba1394119487b7ebaf5c8ed6a6ed6c33f4d45933f0a09202355
|
|
| MD5 |
aed2f091bb3587b09e18bcebfee83c7b
|
|
| BLAKE2b-256 |
4dac031287b304cd3a8fe1beba67462c5b6bfca3f53a801d136c3bc9ad030c6c
|
File details
Details for the file openai2claude-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai2claude-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
965f5484a21b1b127556fbfeafe22bf115867688f071d1179610833d936b6bb6
|
|
| MD5 |
0e0a9e1981f4d61b1bcd9236a3c3730f
|
|
| BLAKE2b-256 |
711ad6053a4b25e784a08d7c1a8fe844986a606daeb7a4938fbd0d2036851152
|