OpenAI-compatible API server that routes through Claude Code
Project description
claude-relay
Drop-in OpenAI API server that routes through Claude Code.
Why
You have tools that speak the OpenAI API. You have Claude Code with its tools, MCP servers, and agentic capabilities. claude-relay bridges the two — point any OpenAI-compatible client at it and every request flows through claude -p under the hood.
- Use Claude Code from any OpenAI client — Cursor, Continue, aider, custom scripts
- Keep Claude Code's superpowers — tool use, MCP servers, file access, shell execution
- Zero config — if
claudeworks on your machine, so does this - Real token usage — reports actual token counts from Claude (not zeros)
- Token-level streaming — uses
--include-partial-messagesfor true real-time deltas
Install
# With uv (recommended)
uvx claude-relay serve
# Or install globally
uv pip install claude-relay
claude-relay serve
# Or from source
git clone https://github.com/npow/claude-relay.git
cd claude-relay
uv sync
uv run claude-relay serve
Quick start
claude-relay serve
# Server starts on http://localhost:8082
Point any OpenAI-compatible client at it:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8082/v1", api_key="unused")
# Streaming
for chunk in client.chat.completions.create(
model="sonnet",
messages=[{"role": "user", "content": "Hello!"}],
stream=True,
):
print(chunk.choices[0].delta.content or "", end="")
# Non-streaming
resp = client.chat.completions.create(
model="sonnet",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
Or with curl:
curl http://localhost:8082/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"sonnet","messages":[{"role":"user","content":"Hello"}],"stream":true}'
Configuration
claude-relay serve [--host HOST] [--port PORT]
| Flag | Default | Description |
|---|---|---|
--host |
0.0.0.0 |
Bind address |
--port |
8082 |
Bind port |
API
| Endpoint | Method | Description |
|---|---|---|
/v1/chat/completions |
POST | Chat completions (OpenAI-compatible) |
/v1/models |
GET | List available models |
/health |
GET | Server and CLI status |
All endpoints also work without the /v1 prefix. CORS is enabled for all origins.
Supported features
| Feature | Status |
|---|---|
| Streaming (SSE) | Yes |
| System messages | Yes (via --system-prompt) |
| Multi-turn conversations | Yes |
| Multimodal (text parts) | Yes |
| Model selection | Yes |
| Token usage reporting | Yes |
| CORS | Yes |
Models
Pass any model name — it goes directly to claude --model:
| Model | Description |
|---|---|
opus |
Most capable |
sonnet |
Balanced (default) |
haiku |
Fastest |
Limitations
temperature,max_tokens,top_p, and other sampling parameters are ignored (Claude Code CLI does not expose them)- No tool/function calling passthrough (Claude Code uses its own tools internally, but they aren't exposed via the OpenAI tool-calling protocol)
- Each request spawns a new
claudeprocess (~2-3s overhead on top of API latency) - No image/audio content forwarding — only text parts of multimodal messages are extracted
How it works
OpenAI client → claude-relay → claude -p → Anthropic API
(SSE) (FastAPI) (stream-json)
Each request spawns a claude -p process with --output-format stream-json --include-partial-messages. The proxy translates between the OpenAI wire format and Claude Code's streaming JSON protocol. Requests are stateless — no conversation history bleeds between calls.
Development
uv sync
uv run pytest tests/ -v
License
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_relay-0.1.0.tar.gz.
File metadata
- Download URL: claude_relay-0.1.0.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae86038bf6b025bf8c4ca1a05022a40967de5ef60b554ff293d153a107b64aea
|
|
| MD5 |
7ef9fec7636e3bda4cb847b4206fb7bf
|
|
| BLAKE2b-256 |
0983e830228c287b084365b92090f3d5a4f9aeb7f9a852a3f18a93bf9be95197
|
Provenance
The following attestation bundles were made for claude_relay-0.1.0.tar.gz:
Publisher:
publish.yml on npow/claude-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_relay-0.1.0.tar.gz -
Subject digest:
ae86038bf6b025bf8c4ca1a05022a40967de5ef60b554ff293d153a107b64aea - Sigstore transparency entry: 976263069
- Sigstore integration time:
-
Permalink:
npow/claude-relay@b9b5c0525649a83ad9826d827e1d1f4c1dbbbffa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/npow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b9b5c0525649a83ad9826d827e1d1f4c1dbbbffa -
Trigger Event:
release
-
Statement type:
File details
Details for the file claude_relay-0.1.0-py3-none-any.whl.
File metadata
- Download URL: claude_relay-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 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 |
22c4d043c42389c56cf93a5194e078b9019fbf32f26026cfaf7655031477227a
|
|
| MD5 |
14725d5c53dccb2ec272e37dcf094581
|
|
| BLAKE2b-256 |
917e83a533f85c5ce60b642c1552eb2f2c9f93e06aa6cfd67158504af3ae36c0
|
Provenance
The following attestation bundles were made for claude_relay-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on npow/claude-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_relay-0.1.0-py3-none-any.whl -
Subject digest:
22c4d043c42389c56cf93a5194e078b9019fbf32f26026cfaf7655031477227a - Sigstore transparency entry: 976263072
- Sigstore integration time:
-
Permalink:
npow/claude-relay@b9b5c0525649a83ad9826d827e1d1f4c1dbbbffa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/npow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b9b5c0525649a83ad9826d827e1d1f4c1dbbbffa -
Trigger Event:
release
-
Statement type: