dsv4-cc-proxy 1.8.0__tar.gz

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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsv4-cc-proxy contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include README.zh-CN.md
3
+ include LICENSE
4
+ recursive-include scripts *
@@ -0,0 +1,273 @@
1
+ Metadata-Version: 2.4
2
+ Name: dsv4-cc-proxy
3
+ Version: 1.8.0
4
+ Summary: DeepSeek Anthropic API 兼容性代理 — 让 Claude Code 在 DeepSeek V4 模型上稳定运行
5
+ Author: HosheaLi
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 dsv4-cc-proxy contributors
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/HosheaLi/P14_dsv4ToCC
29
+ Project-URL: Source, https://github.com/HosheaLi/P14_dsv4ToCC
30
+ Project-URL: Documentation, https://hosheali.github.io/P14_dsv4ToCC
31
+ Keywords: deepseek,claude,proxy,anthropic,api
32
+ Classifier: Development Status :: 4 - Beta
33
+ Classifier: Environment :: Web Environment
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: Topic :: Internet :: Proxy Servers
41
+ Requires-Python: >=3.11
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Requires-Dist: httpx>=0.27.0
45
+ Requires-Dist: starlette>=0.37.0
46
+ Requires-Dist: uvicorn>=0.29.0
47
+ Provides-Extra: test
48
+ Requires-Dist: pytest>=8.0; extra == "test"
49
+ Requires-Dist: ruff>=0.4.0; extra == "test"
50
+ Dynamic: license-file
51
+
52
+ <div align="center">
53
+
54
+ [**中文版 README**](README.zh-CN.md)
55
+
56
+ # dsv4-cc-proxy
57
+
58
+ **Make DeepSeek V4 work flawlessly with Claude Code**
59
+
60
+ Anthropic API compatibility proxy that fixes 3 DeepSeek V4 incompatibilities.
61
+
62
+ ```
63
+ Claude Code ←→ localhost:16889 (dsv4-cc-proxy) ←→ api.deepseek.com/anthropic
64
+ ```
65
+
66
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
67
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org)
68
+ [![CI](https://github.com/HosheaLi/dsv4-cc-proxy/actions/workflows/ci.yml/badge.svg)](https://github.com/HosheaLi/dsv4-cc-proxy/actions)
69
+ [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)]()
70
+ [![Docker Pulls](https://img.shields.io/docker/pulls/hosheali/dsv4-cc-proxy)](https://hub.docker.com/r/hosheali/dsv4-cc-proxy)
71
+
72
+ </div>
73
+
74
+ ---
75
+
76
+ ## Why dsv4-cc-proxy
77
+
78
+ DeepSeek V4 implements the Anthropic API format, but has 3 critical incompatibilities that break Claude Code. This proxy fixes them transparently.
79
+
80
+ | # | Problem | Symptom | Fix |
81
+ |---|---------|---------|-----|
82
+ | 1 | `tool_use` assistant messages missing a `thinking` block | `reasoning_content` 400 error | Inject empty thinking block before each tool_use |
83
+ | 2 | DeepSeek unconditionally emits `thinking`/`signature_delta` SSE events even when thinking is disabled | `Tool result missing due to internal error` in Claude Code | Strip thinking events from the SSE response stream |
84
+ | 3 | `thinking.type=adaptive` (Claude Code default) + `reasoning_effort` not supported by DeepSeek | Stream truncation / 400 errors | Normalize to `disabled` + strip reasoning_effort |
85
+
86
+ Non-DeepSeek requests and non-`/messages` endpoints pass through with zero overhead.
87
+
88
+ ## Quick Start
89
+
90
+ ### Option 1: pip install (recommended)
91
+
92
+ ```bash
93
+ pip install dsv4-cc-proxy
94
+
95
+ # Start the proxy (default port 16889)
96
+ dsv4-cc-proxy
97
+
98
+ # Stop the proxy
99
+ dsv4-cc-proxy --stop
100
+ ```
101
+
102
+ ### Option 2: pipx (isolated environment)
103
+
104
+ ```bash
105
+ pipx install dsv4-cc-proxy
106
+ dsv4-cc-proxy
107
+ ```
108
+
109
+ ### Option 3: Docker
110
+
111
+ ```bash
112
+ docker run -d -p 16889:16889 --name dsv4-cc-proxy hosheali/dsv4-cc-proxy:latest
113
+ ```
114
+
115
+ Or via docker compose:
116
+
117
+ ```bash
118
+ docker compose up -d
119
+ ```
120
+
121
+ ### Configuration
122
+
123
+ Point Claude Code to the proxy by adding to your `settings.local.json`:
124
+
125
+ ```json
126
+ "ANTHROPIC_BASE_URL": "http://localhost:16889"
127
+ ```
128
+
129
+ ## Configuration
130
+
131
+ | Env Var | Default | Description |
132
+ |---------|---------|-------------|
133
+ | `PROXY_UPSTREAM` | `https://api.deepseek.com/anthropic` | DeepSeek API base URL |
134
+ | `PROXY_HOST` | `127.0.0.1` | Bind address |
135
+ | `PROXY_PORT` | `16889` | Bind port |
136
+ | `PROXY_LOG_LEVEL` | `warning` | Log level (`info` for debugging) |
137
+ | `PROXY_DUMP_DIR` | *(empty=off)* | Debug traffic dump directory. ⚠ Contains conversation data |
138
+
139
+ ## Comparison
140
+
141
+ | Scenario | Without Proxy | With Proxy |
142
+ |----------|--------------|------------|
143
+ | tool_use msg without thinking | 400 error | Auto-injected empty thinking |
144
+ | Claude Code sends `thinking.type=adaptive` | Stream truncation / 400 | Normalized to `disabled` |
145
+ | DeepSeek SSE thinking events | Tool result missing error | Silently stripped from stream |
146
+ | Non-messages endpoints | — | Zero-overhead passthrough |
147
+ | Non-DeepSeek models | — | Zero-overhead passthrough |
148
+
149
+ ## Platform Guides
150
+
151
+ ### macOS (launchd auto-start)
152
+
153
+ ```bash
154
+ # Copy and edit paths in the plist file first!
155
+ cp scripts/com.deepseek.thinking-proxy.plist ~/Library/LaunchAgents/
156
+ launchctl load ~/Library/LaunchAgents/com.deepseek.thinking-proxy.plist
157
+ ```
158
+
159
+ **Note:** Edit the plist file to update paths like `/Users/yourname/.claude/proxy/` to match your setup.
160
+
161
+ ### Windows (Scheduled Task)
162
+
163
+ ```batch
164
+ :: One-time setup (auto-start at logon, restart on crash)
165
+ scripts\install_windows_service.ps1 -Install
166
+
167
+ :: Start manually in terminal
168
+ scripts\start.bat
169
+
170
+ :: Or with PowerShell
171
+ scripts\start.ps1
172
+ ```
173
+
174
+ ### Linux (systemd)
175
+
176
+ Create `/etc/systemd/system/dsv4-cc-proxy.service`:
177
+
178
+ ```ini
179
+ [Unit]
180
+ Description=dsv4-cc-proxy — DeepSeek Anthropic API proxy
181
+ After=network.target
182
+
183
+ [Service]
184
+ Type=simple
185
+ User=your-user
186
+ WorkingDirectory=/path/to/dsv4-cc-proxy
187
+ ExecStart=/path/to/.venv/bin/python3 proxy/deepseek-thinking-proxy.py
188
+ Restart=on-failure
189
+ RestartSec=5
190
+
191
+ [Install]
192
+ WantedBy=multi-user.target
193
+ ```
194
+
195
+ ```bash
196
+ sudo systemctl daemon-reload
197
+ sudo systemctl enable --now dsv4-cc-proxy
198
+ ```
199
+
200
+ ## Docker (manual build)
201
+
202
+ ```bash
203
+ docker build -t dsv4-cc-proxy .
204
+ docker run -d -p 16889:16889 --name dsv4-cc-proxy dsv4-cc-proxy
205
+ ```
206
+
207
+ ## How It Works
208
+
209
+ ```
210
+ ┌─────────────┐ ┌──────────────────┐ ┌────────────────────┐
211
+ │ Claude Code │ ──→ │ dsv4-cc-proxy │ ──→ │ api.deepseek.com │
212
+ │ │ │ localhost:16889 │ │ /anthropic │
213
+ └─────────────┘ └──────────────────┘ └────────────────────┘
214
+
215
+ ┌───────┴────────┐
216
+ │ Fixes applied │
217
+ │ 1. Thinking │
218
+ │ injection │
219
+ │ 2. Thinking │
220
+ │ normalize │
221
+ │ 3. SSE events │
222
+ │ strip │
223
+ └────────────────┘
224
+ ```
225
+
226
+ The proxy intercepts `POST /v1/messages` and applies three fixes for `deepseek-v4*` models. All other requests pass through transparently.
227
+
228
+ ## Testing
229
+
230
+ ```bash
231
+ pip install dsv4-cc-proxy[test]
232
+ pytest tests/ -v
233
+ ```
234
+
235
+ ### Health Check
236
+
237
+ ```bash
238
+ curl http://localhost:16889/health
239
+ # → {"status":"ok","version":"1.8.0","upstream":"https://api.deepseek.com/anthropic"}
240
+ ```
241
+
242
+ ## Project Structure
243
+
244
+ ```
245
+ .
246
+ ├── dsv4_cc_proxy/
247
+ │ ├── __init__.py # Package entry, exports VERSION + create_app
248
+ │ ├── __main__.py # CLI entry — dsv4-cc-proxy command
249
+ │ ├── _version.py # VERSION = "1.8.0" (single source of truth)
250
+ │ └── proxy.py # Core proxy logic (factory pattern)
251
+ ├── tests/
252
+ │ └── test_proxy.py # 22 unit tests
253
+ ├── scripts/
254
+ │ ├── start.bat # Windows batch startup
255
+ │ ├── start.ps1 # PowerShell startup
256
+ │ ├── install_windows_service.ps1 # Windows Task Scheduler setup
257
+ │ └── com.deepseek.thinking-proxy.plist # macOS launchd (optional)
258
+ ├── Dockerfile # Docker multi-stage build
259
+ ├── docker-compose.yml # Docker Compose
260
+ ├── pyproject.toml # Build config, entry point
261
+ ├── MANIFEST.in # Package extras
262
+ ├── .github/workflows/ci.yml # GitHub Actions CI
263
+ ├── LICENSE # MIT License
264
+ └── CONTRIBUTING.md # Contributor guidelines
265
+ ```
266
+
267
+ ## Contributing
268
+
269
+ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
270
+
271
+ ## License
272
+
273
+ [MIT](LICENSE)
@@ -0,0 +1,222 @@
1
+ <div align="center">
2
+
3
+ [**中文版 README**](README.zh-CN.md)
4
+
5
+ # dsv4-cc-proxy
6
+
7
+ **Make DeepSeek V4 work flawlessly with Claude Code**
8
+
9
+ Anthropic API compatibility proxy that fixes 3 DeepSeek V4 incompatibilities.
10
+
11
+ ```
12
+ Claude Code ←→ localhost:16889 (dsv4-cc-proxy) ←→ api.deepseek.com/anthropic
13
+ ```
14
+
15
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
16
+ [![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org)
17
+ [![CI](https://github.com/HosheaLi/dsv4-cc-proxy/actions/workflows/ci.yml/badge.svg)](https://github.com/HosheaLi/dsv4-cc-proxy/actions)
18
+ [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-lightgrey)]()
19
+ [![Docker Pulls](https://img.shields.io/docker/pulls/hosheali/dsv4-cc-proxy)](https://hub.docker.com/r/hosheali/dsv4-cc-proxy)
20
+
21
+ </div>
22
+
23
+ ---
24
+
25
+ ## Why dsv4-cc-proxy
26
+
27
+ DeepSeek V4 implements the Anthropic API format, but has 3 critical incompatibilities that break Claude Code. This proxy fixes them transparently.
28
+
29
+ | # | Problem | Symptom | Fix |
30
+ |---|---------|---------|-----|
31
+ | 1 | `tool_use` assistant messages missing a `thinking` block | `reasoning_content` 400 error | Inject empty thinking block before each tool_use |
32
+ | 2 | DeepSeek unconditionally emits `thinking`/`signature_delta` SSE events even when thinking is disabled | `Tool result missing due to internal error` in Claude Code | Strip thinking events from the SSE response stream |
33
+ | 3 | `thinking.type=adaptive` (Claude Code default) + `reasoning_effort` not supported by DeepSeek | Stream truncation / 400 errors | Normalize to `disabled` + strip reasoning_effort |
34
+
35
+ Non-DeepSeek requests and non-`/messages` endpoints pass through with zero overhead.
36
+
37
+ ## Quick Start
38
+
39
+ ### Option 1: pip install (recommended)
40
+
41
+ ```bash
42
+ pip install dsv4-cc-proxy
43
+
44
+ # Start the proxy (default port 16889)
45
+ dsv4-cc-proxy
46
+
47
+ # Stop the proxy
48
+ dsv4-cc-proxy --stop
49
+ ```
50
+
51
+ ### Option 2: pipx (isolated environment)
52
+
53
+ ```bash
54
+ pipx install dsv4-cc-proxy
55
+ dsv4-cc-proxy
56
+ ```
57
+
58
+ ### Option 3: Docker
59
+
60
+ ```bash
61
+ docker run -d -p 16889:16889 --name dsv4-cc-proxy hosheali/dsv4-cc-proxy:latest
62
+ ```
63
+
64
+ Or via docker compose:
65
+
66
+ ```bash
67
+ docker compose up -d
68
+ ```
69
+
70
+ ### Configuration
71
+
72
+ Point Claude Code to the proxy by adding to your `settings.local.json`:
73
+
74
+ ```json
75
+ "ANTHROPIC_BASE_URL": "http://localhost:16889"
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ | Env Var | Default | Description |
81
+ |---------|---------|-------------|
82
+ | `PROXY_UPSTREAM` | `https://api.deepseek.com/anthropic` | DeepSeek API base URL |
83
+ | `PROXY_HOST` | `127.0.0.1` | Bind address |
84
+ | `PROXY_PORT` | `16889` | Bind port |
85
+ | `PROXY_LOG_LEVEL` | `warning` | Log level (`info` for debugging) |
86
+ | `PROXY_DUMP_DIR` | *(empty=off)* | Debug traffic dump directory. ⚠ Contains conversation data |
87
+
88
+ ## Comparison
89
+
90
+ | Scenario | Without Proxy | With Proxy |
91
+ |----------|--------------|------------|
92
+ | tool_use msg without thinking | 400 error | Auto-injected empty thinking |
93
+ | Claude Code sends `thinking.type=adaptive` | Stream truncation / 400 | Normalized to `disabled` |
94
+ | DeepSeek SSE thinking events | Tool result missing error | Silently stripped from stream |
95
+ | Non-messages endpoints | — | Zero-overhead passthrough |
96
+ | Non-DeepSeek models | — | Zero-overhead passthrough |
97
+
98
+ ## Platform Guides
99
+
100
+ ### macOS (launchd auto-start)
101
+
102
+ ```bash
103
+ # Copy and edit paths in the plist file first!
104
+ cp scripts/com.deepseek.thinking-proxy.plist ~/Library/LaunchAgents/
105
+ launchctl load ~/Library/LaunchAgents/com.deepseek.thinking-proxy.plist
106
+ ```
107
+
108
+ **Note:** Edit the plist file to update paths like `/Users/yourname/.claude/proxy/` to match your setup.
109
+
110
+ ### Windows (Scheduled Task)
111
+
112
+ ```batch
113
+ :: One-time setup (auto-start at logon, restart on crash)
114
+ scripts\install_windows_service.ps1 -Install
115
+
116
+ :: Start manually in terminal
117
+ scripts\start.bat
118
+
119
+ :: Or with PowerShell
120
+ scripts\start.ps1
121
+ ```
122
+
123
+ ### Linux (systemd)
124
+
125
+ Create `/etc/systemd/system/dsv4-cc-proxy.service`:
126
+
127
+ ```ini
128
+ [Unit]
129
+ Description=dsv4-cc-proxy — DeepSeek Anthropic API proxy
130
+ After=network.target
131
+
132
+ [Service]
133
+ Type=simple
134
+ User=your-user
135
+ WorkingDirectory=/path/to/dsv4-cc-proxy
136
+ ExecStart=/path/to/.venv/bin/python3 proxy/deepseek-thinking-proxy.py
137
+ Restart=on-failure
138
+ RestartSec=5
139
+
140
+ [Install]
141
+ WantedBy=multi-user.target
142
+ ```
143
+
144
+ ```bash
145
+ sudo systemctl daemon-reload
146
+ sudo systemctl enable --now dsv4-cc-proxy
147
+ ```
148
+
149
+ ## Docker (manual build)
150
+
151
+ ```bash
152
+ docker build -t dsv4-cc-proxy .
153
+ docker run -d -p 16889:16889 --name dsv4-cc-proxy dsv4-cc-proxy
154
+ ```
155
+
156
+ ## How It Works
157
+
158
+ ```
159
+ ┌─────────────┐ ┌──────────────────┐ ┌────────────────────┐
160
+ │ Claude Code │ ──→ │ dsv4-cc-proxy │ ──→ │ api.deepseek.com │
161
+ │ │ │ localhost:16889 │ │ /anthropic │
162
+ └─────────────┘ └──────────────────┘ └────────────────────┘
163
+
164
+ ┌───────┴────────┐
165
+ │ Fixes applied │
166
+ │ 1. Thinking │
167
+ │ injection │
168
+ │ 2. Thinking │
169
+ │ normalize │
170
+ │ 3. SSE events │
171
+ │ strip │
172
+ └────────────────┘
173
+ ```
174
+
175
+ The proxy intercepts `POST /v1/messages` and applies three fixes for `deepseek-v4*` models. All other requests pass through transparently.
176
+
177
+ ## Testing
178
+
179
+ ```bash
180
+ pip install dsv4-cc-proxy[test]
181
+ pytest tests/ -v
182
+ ```
183
+
184
+ ### Health Check
185
+
186
+ ```bash
187
+ curl http://localhost:16889/health
188
+ # → {"status":"ok","version":"1.8.0","upstream":"https://api.deepseek.com/anthropic"}
189
+ ```
190
+
191
+ ## Project Structure
192
+
193
+ ```
194
+ .
195
+ ├── dsv4_cc_proxy/
196
+ │ ├── __init__.py # Package entry, exports VERSION + create_app
197
+ │ ├── __main__.py # CLI entry — dsv4-cc-proxy command
198
+ │ ├── _version.py # VERSION = "1.8.0" (single source of truth)
199
+ │ └── proxy.py # Core proxy logic (factory pattern)
200
+ ├── tests/
201
+ │ └── test_proxy.py # 22 unit tests
202
+ ├── scripts/
203
+ │ ├── start.bat # Windows batch startup
204
+ │ ├── start.ps1 # PowerShell startup
205
+ │ ├── install_windows_service.ps1 # Windows Task Scheduler setup
206
+ │ └── com.deepseek.thinking-proxy.plist # macOS launchd (optional)
207
+ ├── Dockerfile # Docker multi-stage build
208
+ ├── docker-compose.yml # Docker Compose
209
+ ├── pyproject.toml # Build config, entry point
210
+ ├── MANIFEST.in # Package extras
211
+ ├── .github/workflows/ci.yml # GitHub Actions CI
212
+ ├── LICENSE # MIT License
213
+ └── CONTRIBUTING.md # Contributor guidelines
214
+ ```
215
+
216
+ ## Contributing
217
+
218
+ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
219
+
220
+ ## License
221
+
222
+ [MIT](LICENSE)