claude-code-relay 0.0.4 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -0
- package/package.json +4 -1
package/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# claude-code-relay
|
|
2
|
+
|
|
3
|
+
Local proxy that exposes Claude CLI as an OpenAI-compatible API server.
|
|
4
|
+
|
|
5
|
+
Use your existing Claude CLI installation with any OpenAI-compatible client.
|
|
6
|
+
|
|
7
|
+
## Why?
|
|
8
|
+
|
|
9
|
+
- You already have Claude CLI working with your subscription
|
|
10
|
+
- You want to use tools that expect OpenAI API format
|
|
11
|
+
- No separate API key needed - uses your local Claude CLI
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### Node.js / Bun
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx claude-code-relay serve
|
|
19
|
+
# or
|
|
20
|
+
bunx claude-code-relay serve
|
|
21
|
+
# or install globally
|
|
22
|
+
npm install -g claude-code-relay
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Python
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install claude-code-relay
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Start the server
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Node
|
|
37
|
+
npx claude-code-relay serve --port 52014
|
|
38
|
+
|
|
39
|
+
# Python
|
|
40
|
+
claude-code-relay serve --port 52014
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Use with OpenAI SDK
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from openai import OpenAI
|
|
47
|
+
|
|
48
|
+
client = OpenAI(
|
|
49
|
+
base_url="http://localhost:52014/v1",
|
|
50
|
+
api_key="not-needed"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
response = client.chat.completions.create(
|
|
54
|
+
model="sonnet", # or "opus", "haiku"
|
|
55
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
56
|
+
)
|
|
57
|
+
print(response.choices[0].message.content)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import OpenAI from "openai";
|
|
62
|
+
|
|
63
|
+
const client = new OpenAI({
|
|
64
|
+
baseURL: "http://localhost:52014/v1",
|
|
65
|
+
apiKey: "not-needed",
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const response = await client.chat.completions.create({
|
|
69
|
+
model: "sonnet",
|
|
70
|
+
messages: [{ role: "user", content: "Hello!" }],
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Use with LiteLLM
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from litellm import completion
|
|
78
|
+
|
|
79
|
+
response = completion(
|
|
80
|
+
model="openai/sonnet",
|
|
81
|
+
api_base="http://localhost:52014/v1",
|
|
82
|
+
api_key="not-needed",
|
|
83
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
84
|
+
)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Use with Vercel AI SDK
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
91
|
+
import { generateText } from "ai";
|
|
92
|
+
|
|
93
|
+
const claude = createOpenAICompatible({
|
|
94
|
+
name: "claude-code-relay",
|
|
95
|
+
baseURL: "http://localhost:52014/v1",
|
|
96
|
+
apiKey: "not-needed",
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const { text } = await generateText({
|
|
100
|
+
model: claude.chatModel("sonnet"),
|
|
101
|
+
prompt: "Hello!",
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## API Endpoints
|
|
106
|
+
|
|
107
|
+
| Endpoint | Method | Description |
|
|
108
|
+
|----------|--------|-------------|
|
|
109
|
+
| `/v1/chat/completions` | POST | Chat completions (streaming supported) |
|
|
110
|
+
| `/v1/models` | GET | List available models |
|
|
111
|
+
| `/health` | GET | Health check |
|
|
112
|
+
|
|
113
|
+
## OpenAI API Compatibility
|
|
114
|
+
|
|
115
|
+
### Supported Features
|
|
116
|
+
|
|
117
|
+
| Feature | Status | Notes |
|
|
118
|
+
|---------|--------|-------|
|
|
119
|
+
| `model` | Supported | `sonnet`, `opus`, `haiku` (+ aliases below) |
|
|
120
|
+
| `messages` | Supported | `system`, `user`, `assistant` roles |
|
|
121
|
+
| `stream` | Supported | SSE streaming |
|
|
122
|
+
| System prompts | Supported | Via `system` role in messages |
|
|
123
|
+
|
|
124
|
+
### Model Aliases
|
|
125
|
+
|
|
126
|
+
These model names are normalized to Claude CLI format:
|
|
127
|
+
|
|
128
|
+
| Input | Maps to |
|
|
129
|
+
|-------|---------|
|
|
130
|
+
| `sonnet` | `sonnet` |
|
|
131
|
+
| `opus` | `opus` |
|
|
132
|
+
| `haiku` | `haiku` |
|
|
133
|
+
| `claude-3-sonnet` | `sonnet` |
|
|
134
|
+
| `claude-3-opus` | `opus` |
|
|
135
|
+
| `claude-3-haiku` | `haiku` |
|
|
136
|
+
| `claude-sonnet-4` | `sonnet` |
|
|
137
|
+
| `claude-opus-4` | `opus` |
|
|
138
|
+
|
|
139
|
+
### Not Supported
|
|
140
|
+
|
|
141
|
+
These parameters are accepted but **ignored** (not passed to Claude CLI):
|
|
142
|
+
|
|
143
|
+
| Parameter | Status |
|
|
144
|
+
|-----------|--------|
|
|
145
|
+
| `temperature` | Ignored |
|
|
146
|
+
| `max_tokens` | Ignored |
|
|
147
|
+
| `top_p` | Ignored |
|
|
148
|
+
| `stop` | Ignored |
|
|
149
|
+
| `n` | Not supported |
|
|
150
|
+
| `presence_penalty` | Not supported |
|
|
151
|
+
| `frequency_penalty` | Not supported |
|
|
152
|
+
| `logit_bias` | Not supported |
|
|
153
|
+
| `response_format` | Not supported |
|
|
154
|
+
| `tools` / `functions` | Not supported |
|
|
155
|
+
| `tool_choice` | Not supported |
|
|
156
|
+
| `seed` | Not supported |
|
|
157
|
+
| `logprobs` | Not supported |
|
|
158
|
+
| `user` | Not supported |
|
|
159
|
+
|
|
160
|
+
### Response Limitations
|
|
161
|
+
|
|
162
|
+
- `usage` tokens are always `0` (not tracked by Claude CLI)
|
|
163
|
+
- `finish_reason` is always `"stop"` (no length/tool_calls detection)
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
### Environment Variables
|
|
168
|
+
|
|
169
|
+
| Variable | Default | Description |
|
|
170
|
+
|----------|---------|-------------|
|
|
171
|
+
| `CLAUDE_CODE_RELAY_PORT` | `52014` | Server port (Python only) |
|
|
172
|
+
| `CLAUDE_CODE_RELAY_HOST` | `127.0.0.1` | Host to bind (Python only) |
|
|
173
|
+
| `CLAUDE_CLI_PATH` | `claude` | Path to Claude CLI binary |
|
|
174
|
+
| `CLAUDE_CODE_RELAY_TIMEOUT` | `300` | Request timeout in seconds |
|
|
175
|
+
| `CLAUDE_CODE_RELAY_VERBOSE` | `false` | Enable verbose logging (`1` or `true`) |
|
|
176
|
+
|
|
177
|
+
### CLI Options
|
|
178
|
+
|
|
179
|
+
```
|
|
180
|
+
claude-code-relay serve [options]
|
|
181
|
+
|
|
182
|
+
Options:
|
|
183
|
+
--port, -p <port> Server port (default: 52014)
|
|
184
|
+
--host <host> Host to bind (default: 127.0.0.1)
|
|
185
|
+
--claude-path <path> Path to Claude CLI
|
|
186
|
+
--timeout <seconds> Request timeout (default: 300)
|
|
187
|
+
--verbose, -v Enable verbose logging
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Requirements
|
|
191
|
+
|
|
192
|
+
- Claude CLI installed and authenticated
|
|
193
|
+
- Python 3.10+ or Node.js 18+
|
|
194
|
+
|
|
195
|
+
## License
|
|
196
|
+
|
|
197
|
+
MIT - see [LICENSE](LICENSE)
|
|
198
|
+
|
|
199
|
+
**Disclaimer**: Unofficial community project. Users are responsible for compliance with Anthropic's Terms of Service.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-relay",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Local proxy that exposes Claude CLI as an OpenAI-compatible API server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -60,5 +60,8 @@
|
|
|
60
60
|
"esbuild": "^0.27.2",
|
|
61
61
|
"typescript": "^5.9.3",
|
|
62
62
|
"vitest": "^4.0.16"
|
|
63
|
+
},
|
|
64
|
+
"optionalDependencies": {
|
|
65
|
+
"@rollup/rollup-linux-x64-gnu": "^4.55.1"
|
|
63
66
|
}
|
|
64
67
|
}
|