MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

深度技术分析:yxlao/deepseek-cursor-proxy

项目背景与痛点

“yxlao/deepseek-cursor-proxy” 项目旨在解决 DeepSeek V4 中推理内容缺失的问题,这是在机器学习推理阶段经常遇到的一种故障。具体来说,DeepSeek V4 的推理层在某些情况下可能会丢失推理结果,导致数据不完整。该问题不仅影响数据准确性,还可能引发潜在的系统错误。因此,项目的使命非常明确:提供一种可靠的代理机制,确保推理内容的完整性,从而提升整个系统的鲁棒性。

核心技术揭秘

技术架构

deepseek-cursor-proxy 是一项代理技术,通过引入一个中间层,有效解决了推理内容丢失的问题。它使用了流式消息处理框架,确保数据的完整传输和处理。核心功能模块包括数据接收、校验、转发和错误处理等。以下是其架构图概览:

graph TD A[用户请求] --> B{"参数校验"} B -->|"通过"| C[执行业务] C --> D[获取推理结果] D --> E{"内容校验"} E -->|"未丢失"| F[返回结果] E -->|"丢失"| G[重置通道] G --> H[重新请求] H --> D B -->|"失败"| I[返回错误]

实现原理

  1. 数据接收与校验:

    • 在接收用户请求后,系统首先进行参数校验。如校验通过,请求被转发至业务服务器;如有误,则直接返回错误。
  2. 消息传输出错处理:

    • 数据在传输过程中,如果遇到推理内容丢失,系统会进行内容校验。如确认丢失,就会重启数据通道。
  3. 错误处理:

    • 通过重置通道和重新请求的机制,确保丢失的推理内容能够被重新获取,从而确保数据的完整性。

功能亮点与差异

与市面上类似的产品相比,deepseek-cursor-proxy在几个关键点上具有独特的优势:

  1. 高鲁棒性:

    • 通过重新请求机制,确保推理内容不丢失,提高系统整体的鲁棒性和可靠性。
  2. 快速响应:

    • 发生数据丢失时,系统会快速响应并启动数据重传机制,减少因数据丢失造成的延误。
  3. 简洁设计:

    • 使用中间代理层的设计思想,使整个架构既简单又灵活,易于维护和扩展。

应用场景与落地建议

应用场景

deepseek-cursor-proxy 的应用场景非常广泛,尤其是出现在大数据实时处理以及机器学习的推理层面。在生产环境中,为了更好地利用这份可靠的数据防护机制,应:

  1. 监控:实时监控数据流状态,及时发现潜在的连接失败情况。
  2. 策略:根据实际业务需求,调整重传策略,以达到最优性能和稳定性。

落地建议

对于考虑在生产环境中使用该项目的开发团队,他们应注意以下几点:

  • 测试覆盖: 在开发过程中充分测试潜在的数据丢失情况,确认系统的稳定性。
  • 性能调优: 根据系统环境的具体情况,适当调整代理配置参数,以达到最优性能。

综合评价

优点

  • 高度可靠:提供数据重传机制,确保数据的完整性。
  • 易于集成:巧妙而简洁的设计,使其易于集成到现有系统中。
  • 性能优秀:针对性能做了一系列优化策略,提高了系统效率。

缺点

  • 资源消耗:重传机制可能带来一定的网络与计算资源开销。
  • 配置复杂:为达到最佳性能,需要根据具体业务场景调整配置,对使用者有一定技术水平要求。

总之,deepseek-cursor-proxy 作为深思熟虑后的产物,已经充分考虑到了数据完整性和系统鲁棒性的重要需求。然而,任何技术都无法避免资源消耗的问题。对于追求高可靠性的大数据处理和机器学习领域,deepseek-cursor-proxy 是一个值得信赖的选择。

关于

GitHub 原始描述(英文)

Fixes missing reasoning_content for DeepSeek V4

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Python

README

deepseek-cursor-proxy logo
DeepSeek Cursor Proxy

A compatibility proxy that connects Cursor to DeepSeek thinking models (deepseek-v4-pro and deepseek-v4-flash) by properly handling the reasoning_content field for DeepSeek tool-call reasoning API requests.

This proxy can also help other applications and coding agents beyond Cursor that run into the same missing reasoning_content issue with DeepSeek’s thinking-mode API. Just point their API base URL at the proxy.

What It Does

  • ✅ Injects reasoning_content into outgoing tool-call requests since Cursor does not include the field, restoring previously cached reasoning from regular and streamed DeepSeek responses. See DeepSeek docs for more details.
  • ✅ Displays DeepSeek’s thinking tokens in Cursor by forwarding them into Cursor-visible collapsible Markdown <details><summary>Thinking</summary>...</details> blocks.
  • ✅ Starts an ngrok tunnel so Cursor can reach the local proxy through a public HTTPS URL.
  • ✅ Provides other compatibility fixes to make DeepSeek models run well in Cursor.

Why This Exists

This repository fixes the following Cursor + DeepSeek tool-call error with thinking mode enabled:

Error 400 - reasoning_content must be passed back
⚠️ Connection Error
Provider returned error:
{
  "error": {
    "message": "The reasoning_content in the thinking mode must be passed back to the API.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_request_error"
  }
}

Usage

Step 1: Set Up ngrok

Cursor blocks non-public API URLs such as localhost, so the proxy needs a public HTTPS URL. ngrok can expose the local proxy to Cursor without opening router ports. Alternatively, you may use Cloudflare Tunnel. Create an ngrok account and visit ngrok’s dashboard. You will find the authtoken and public URL there.

If you’re using this proxy with another application that allows localhost API endpoints, you can skip this step entirely by setting ngrok: false in ~/.deepseek-cursor-proxy/config.yaml, or by starting the proxy with --no-ngrok.

ngrok dashboard

Then, install and authenticate ngrok once:

brew install ngrok
ngrok config add-authtoken <your-ngrok-token>

Step 2: Install and Start the Proxy Server

Run with UV

# Install uv if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install and start
# uv installs the program in .venv/ under the repo local folder
git clone https://github.com/yxlao/deepseek-cursor-proxy.git
cd deepseek-cursor-proxy
uv run deepseek-cursor-proxy

Run with Conda

# Install conda if you don't have it
# Follow: https://www.anaconda.com/docs/getting-started/miniconda/install/overview

# Install
conda create -n dcp python=3.10 -y
conda activate dcp
git clone https://github.com/yxlao/deepseek-cursor-proxy.git
cd deepseek-cursor-proxy
pip install -e .

# Start
deepseek-cursor-proxy

When ngrok is enabled, deepseek-cursor-proxy will print the ngrok public URL on start. If it differs from the one in Cursor, update it in Cursor’s Base URL field.

If you use a reserved ngrok endpoint or your own domain (instead of a URL assigned by ngrok), pass it through to the ngrok agent as --url=…. Set ngrok_url in ~/.deepseek-cursor-proxy/config.yaml or use --ngrok-url on the command line (see ngrok http --help). Example:

ngrok: true
ngrok_url: https://your-subdomain.ngrok.dev
deepseek-cursor-proxy --ngrok-url https://your-subdomain.ngrok.dev

On the first run, deepseek-cursor-proxy will create:

  • ~/.deepseek-cursor-proxy/config.yaml: the configuration file
  • ~/.deepseek-cursor-proxy/reasoning_content.sqlite3: the reasoning content cache

Persistent settings live in ~/.deepseek-cursor-proxy/config.yaml. You can also override the config with command-line flags, for example:

# Hide thinking tokens displaying in Cursor UI
deepseek-cursor-proxy --no-display-reasoning

# Show full incoming and outgoing requests
deepseek-cursor-proxy --verbose

# Run without ngrok (run on localhost directly)
deepseek-cursor-proxy --no-ngrok

# Use a fixed ngrok public URL (reserved endpoint / custom domain)
deepseek-cursor-proxy --ngrok-url https://your-subdomain.ngrok.dev

# Use a different local port
deepseek-cursor-proxy --port 9000

Step 3: Add Cursor Custom Model

In Cursor, add the DeepSeek custom model and point it at this proxy:

  • Model: deepseek-v4-pro
  • API Key: your DeepSeek API key
  • Base URL: your ngrok HTTPS URL with the /v1 API version path

The proxy respects the DeepSeek model name Cursor sends, such as deepseek-v4-pro or deepseek-v4-flash. The model field in config.yaml is used as a fallback only when a request does not include a model.

For example, if ngrok dashboard shows https://example.ngrok-free.dev, use:

https://example.ngrok-free.dev/v1
Cursor settings for DeepSeek through the proxy

Note: you can toggle the custom API on and off with:

  • macOS: Cmd+Shift+0
  • Windows/Linux: Ctrl+Shift+0

Step 4: Chat with DeepSeek in Cursor

Select deepseek-v4-pro in Cursor and use chat or agent mode as usual.

Chatting with DeepSeek in Cursor

How It Works

  • Core fix: DeepSeek thinking-mode tool calls require the complete multi-round reasoning_content chain to be sent back in later requests. Cursor omits that field, causing a 400 error. The proxy (Cursor -> ngrok -> proxy -> DeepSeek API) stores DeepSeek’s original reasoning_content and patches missing blocks back into outgoing tool-call history.
  • Multi-conversation isolation: To avoid collisions across concurrent conversations, the proxy scopes cache keys by a SHA-256 hash of the canonical conversation prefix (roles, content, and tool calls, excluding reasoning_content) plus the upstream model, configuration, and an API-key hash. Different threads get different scopes, so reused tool-call IDs do not collide. Byte-identical cloned histories produce identical scopes.
  • Context caching compatibility: The proxy preserves compatibility by never injecting synthetic thread IDs, timestamps, or cache-control messages. It restores reasoning_content as the exact original string, so repeated prefixes remain intact for DeepSeek context cache. Cache hit rates are logged in the terminal output.
  • Additional compatibility fixes: Beyond reasoning repair, the proxy converts legacy functions/function_call fields to tools/tool_choice, preserves required and named tool-choice semantics, normalizes reasoning_effort aliases, strips mirrored thinking display blocks from assistant content, flattens multi-part content arrays to plain text, and mirrors reasoning_content into Cursor-visible Markdown details blocks.

Development

Run unit tests:

uv run python -m unittest discover -s tests

Run pre-commit hooks (code formatting and linting):

uv sync --dev
uv run pre-commit run --all-files

Debugging

Run with verbose output:

deepseek-cursor-proxy --verbose

Run without ngrok for local curl testing:

deepseek-cursor-proxy --no-ngrok --port 9000 --verbose

Capture full structured request traces for debugging:

deepseek-cursor-proxy --verbose --trace-dir ./trace-dumps

Use another config file:

deepseek-cursor-proxy --config ./dev.config.yaml

Clear the local reasoning cache:

deepseek-cursor-proxy --clear-reasoning-cache

评论

暂无评论