Local proxy that exposes Claude CLI as an OpenAI-compatible API server
Project description
claude-code-relay
Local proxy that exposes Claude CLI as an OpenAI-compatible API server.
Use your existing Claude CLI installation with any OpenAI-compatible client (LiteLLM, Vercel AI SDK, LangChain, etc).
Why?
- You already have Claude CLI working with your subscription
- You want to use tools that expect OpenAI API format
- No separate API key needed - uses your local Claude CLI
Installation
Python
pip install claude-code-relay
# or
uv pip install claude-code-relay
# or
poetry add claude-code-relay
Node.js / Bun
npx claude-code-relay serve
# or
bunx claude-code-relay serve
# or install globally
npm install -g claude-code-relay
Usage
Start the server
# Python
claude-code-relay serve --port 52014
# Node
npx claude-code-relay serve --port 52014
Use with OpenAI SDK
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:52014/v1",
api_key="not-needed"
)
response = client.chat.completions.create(
model="sonnet", # or "opus", "haiku"
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://localhost:52014/v1",
apiKey: "not-needed",
});
const response = await client.chat.completions.create({
model: "sonnet",
messages: [{ role: "user", content: "Hello!" }],
});
Use with LiteLLM
from litellm import completion
response = completion(
model="openai/sonnet",
api_base="http://localhost:52014/v1",
api_key="not-needed",
messages=[{"role": "user", "content": "Hello!"}]
)
Use with Vercel AI SDK
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const claude = createOpenAICompatible({
name: "claude-code-relay",
baseURL: "http://localhost:52014/v1",
apiKey: "not-needed",
});
const { text } = await generateText({
model: claude.chatModel("sonnet"),
prompt: "Hello!",
});
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
CLAUDE_RELAY_PORT |
52014 |
Server port |
CLAUDE_CLI_PATH |
claude |
Path to Claude CLI binary |
CLAUDE_RELAY_TIMEOUT |
300 |
Request timeout in seconds |
CLI Options
claude-code-relay serve [options]
Options:
--port, -p <port> Server port (default: 52014)
--host, -h <host> Host to bind (default: 127.0.0.1)
--claude-path <path> Path to Claude CLI
--timeout <seconds> Request timeout (default: 300)
--verbose, -v Enable verbose logging
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions |
POST | Chat completions (streaming supported) |
/v1/models |
GET | List available models |
/health |
GET | Health check |
Supported Features
- Chat completions
- Streaming (SSE)
- Model selection (sonnet, opus, haiku)
- System prompts
- Function calling / tools (planned)
- Vision / images (planned)
Requirements
- Claude CLI installed and authenticated
- Python 3.10+ or Node.js 18+ / Bun
License
MIT License - see LICENSE
DISCLAIMER: This is an unofficial community project. Users are responsible for their own compliance with Anthropic's Terms of Service.
Contributing
See CONTRIBUTING.md for guidelines.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 claude_code_relay-0.0.1.tar.gz.
File metadata
- Download URL: claude_code_relay-0.0.1.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3e5bc08062a4cfa4356880e75b4cc42be9629ae72108e98332b07dfb34efcf
|
|
| MD5 |
318b0ec79086e60151d75b02ef87f91e
|
|
| BLAKE2b-256 |
e67bec2105cdde28a7e18a77ce52fc8bbd51baf58cd60b724e6209a024c56dc3
|
File details
Details for the file claude_code_relay-0.0.1-py3-none-any.whl.
File metadata
- Download URL: claude_code_relay-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8762285c5159478d189d7ac00a4a89a750a348f11c8e681b821e0cb20e515ee
|
|
| MD5 |
e517d82a395b25848a18361a33b69b31
|
|
| BLAKE2b-256 |
067e5a7bef68c0a16529210d0c5526a555de159e3ef9c221b04c89e7bc49a7d4
|