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.
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
Node.js / Bun
npx claude-code-relay serve
# or
bunx claude-code-relay serve
# or install globally
npm install -g claude-code-relay
Python
pip install claude-code-relay
Usage
Start the server
# Node
npx claude-code-relay serve --port 52014
# Python
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!",
});
API Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions |
POST | Chat completions (streaming supported) |
/v1/models |
GET | List available models |
/health |
GET | Health check |
OpenAI API Compatibility
Supported Features
| Feature | Status | Notes |
|---|---|---|
model |
Supported | sonnet, opus, haiku (+ aliases below) |
messages |
Supported | system, user, assistant roles |
stream |
Supported | SSE streaming |
| System prompts | Supported | Via system role in messages |
Model Aliases
These model names are normalized to Claude CLI format:
| Input | Maps to |
|---|---|
sonnet |
sonnet |
opus |
opus |
haiku |
haiku |
claude-3-sonnet |
sonnet |
claude-3-opus |
opus |
claude-3-haiku |
haiku |
claude-sonnet-4 |
sonnet |
claude-opus-4 |
opus |
Not Supported
These parameters are accepted but ignored (not passed to Claude CLI):
| Parameter | Status |
|---|---|
temperature |
Ignored |
max_tokens |
Ignored |
top_p |
Ignored |
stop |
Ignored |
n |
Not supported |
presence_penalty |
Not supported |
frequency_penalty |
Not supported |
logit_bias |
Not supported |
response_format |
Not supported |
tools / functions |
Not supported |
tool_choice |
Not supported |
seed |
Not supported |
logprobs |
Not supported |
user |
Not supported |
Response Limitations
usagetokens are always0(not tracked by Claude CLI)finish_reasonis always"stop"(no length/tool_calls detection)
Configuration
Environment Variables
| Variable | Default | Description |
|---|---|---|
CLAUDE_CODE_RELAY_PORT |
52014 |
Server port (Python only) |
CLAUDE_CODE_RELAY_HOST |
127.0.0.1 |
Host to bind (Python only) |
CLAUDE_CLI_PATH |
claude |
Path to Claude CLI binary |
CLAUDE_CODE_RELAY_TIMEOUT |
300 |
Request timeout in seconds |
CLAUDE_CODE_RELAY_VERBOSE |
false |
Enable verbose logging (1 or true) |
CLI Options
claude-code-relay serve [options]
Options:
--port, -p <port> Server port (default: 52014)
--host <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
Requirements
- Claude CLI installed and authenticated
- Python 3.10+ or Node.js 18+
License
MIT - see LICENSE
Disclaimer: Unofficial community project. Users are responsible for compliance with Anthropic's Terms of Service.
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.7.tar.gz.
File metadata
- Download URL: claude_code_relay-0.0.7.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4f4c52911e43d8c7ad1bfa0b9d622c64d0ef1ed35bce48c7bc069c41782f3f8
|
|
| MD5 |
d3acecdb21d9be800c4f9458e3b9ead9
|
|
| BLAKE2b-256 |
4878929eb8585d86c9a5ae2f87d50ec72b290807b433f4529945a2a10c45d254
|
Provenance
The following attestation bundles were made for claude_code_relay-0.0.7.tar.gz:
Publisher:
python-publish.yml on DreamTeamMobile/claude-code-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_code_relay-0.0.7.tar.gz -
Subject digest:
d4f4c52911e43d8c7ad1bfa0b9d622c64d0ef1ed35bce48c7bc069c41782f3f8 - Sigstore transparency entry: 805118871
- Sigstore integration time:
-
Permalink:
DreamTeamMobile/claude-code-relay@ca90354c69ecc92d967cc42511b9567bb8941f9c -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/DreamTeamMobile
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ca90354c69ecc92d967cc42511b9567bb8941f9c -
Trigger Event:
push
-
Statement type:
File details
Details for the file claude_code_relay-0.0.7-py3-none-any.whl.
File metadata
- Download URL: claude_code_relay-0.0.7-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5ab6d86798185ab40f3eea6b34c7e94686458d3f8fe472f2f63540c918a1001
|
|
| MD5 |
21442e48cfbf81e5468fb67012c7cd0b
|
|
| BLAKE2b-256 |
0fa92eba0149c76cda37353cc7695cae502ece2b1ece36fa43370285c957b268
|
Provenance
The following attestation bundles were made for claude_code_relay-0.0.7-py3-none-any.whl:
Publisher:
python-publish.yml on DreamTeamMobile/claude-code-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_code_relay-0.0.7-py3-none-any.whl -
Subject digest:
c5ab6d86798185ab40f3eea6b34c7e94686458d3f8fe472f2f63540c918a1001 - Sigstore transparency entry: 805118874
- Sigstore integration time:
-
Permalink:
DreamTeamMobile/claude-code-relay@ca90354c69ecc92d967cc42511b9567bb8941f9c -
Branch / Tag:
refs/tags/v0.0.7 - Owner: https://github.com/DreamTeamMobile
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@ca90354c69ecc92d967cc42511b9567bb8941f9c -
Trigger Event:
push
-
Statement type: