153 lines
2.0 KiB
Markdown
153 lines
2.0 KiB
Markdown
# Cursor API Proxy (整理版)
|
||
|
||
一個代理伺服器,讓你用標準 OpenAI / Anthropic API 存取 Cursor CLI 模型。
|
||
|
||
可接入:
|
||
- Claude Code
|
||
- OpenCode
|
||
- 任何支援 OpenAI / Anthropic API 的工具
|
||
|
||
---
|
||
|
||
## 功能
|
||
|
||
- API 相容(OpenAI / Anthropic)
|
||
- 多帳號管理
|
||
- 模型自動對映(轉成 claude-*)
|
||
- 支援區網存取(0.0.0.0)
|
||
- 連線池優化
|
||
|
||
---
|
||
|
||
## 快速開始(本機)
|
||
### 看幫助
|
||
```bash
|
||
make help
|
||
```
|
||
### 安裝依賴
|
||
|
||
```bash
|
||
curl https://cursor.com/install -fsS | bash
|
||
curl -fsSL https://claude.ai/install.sh | bash
|
||
```
|
||
|
||
### 下載與建置
|
||
|
||
```bash
|
||
git clone https://code.30cm.net/daniel.w/opencode-cursor-agent.git
|
||
cd cursor-api-proxy-go
|
||
go build -o cursor-api-proxy .
|
||
```
|
||
|
||
### 登入
|
||
|
||
```bash
|
||
./cursor-api-proxy login myaccount
|
||
```
|
||
|
||
### 啟動
|
||
|
||
```bash
|
||
make env PORT=8766 API_KEY=mysecret
|
||
make pm2
|
||
```
|
||
|
||
---
|
||
|
||
## Claude Code 設定
|
||
|
||
```bash
|
||
make claude-settings PORT=8766
|
||
make claude-onboarding
|
||
claude
|
||
```
|
||
|
||
---
|
||
|
||
## OpenCode 設定
|
||
|
||
編輯:
|
||
|
||
~/.config/opencode/opencode.json
|
||
|
||
```json
|
||
{
|
||
"provider": {
|
||
"cursor": {
|
||
"options": {
|
||
"baseURL": "http://127.0.0.1:8766/v1"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
---
|
||
|
||
## Docker(簡化版)
|
||
|
||
```bash
|
||
make docker-setup
|
||
vim .env
|
||
make docker-setup
|
||
```
|
||
|
||
檢查:
|
||
|
||
```bash
|
||
curl http://localhost:8766/health
|
||
```
|
||
|
||
---
|
||
|
||
## 常用指令
|
||
|
||
```bash
|
||
make docker-up
|
||
make docker-down
|
||
make docker-logs
|
||
make docker-restart
|
||
```
|
||
|
||
---
|
||
|
||
## API
|
||
|
||
| 路徑 | 方法 |
|
||
|------|------|
|
||
| /v1/chat/completions | POST |
|
||
| /v1/messages | POST |
|
||
| /v1/models | GET |
|
||
| /health | GET |
|
||
|
||
---
|
||
|
||
## 環境變數(核心)
|
||
|
||
| 變數 | 預設 |
|
||
|------|------|
|
||
| CURSOR_BRIDGE_HOST | 127.0.0.1 |
|
||
| CURSOR_BRIDGE_PORT | 8766 |
|
||
| CURSOR_BRIDGE_TIMEOUT_MS | 3600000 |
|
||
|
||
---
|
||
|
||
## 帳號操作
|
||
|
||
```bash
|
||
./cursor-api-proxy login myaccount
|
||
./cursor-api-proxy accounts
|
||
./cursor-api-proxy logout myaccount
|
||
./cursor-api-proxy reset-hwid
|
||
```
|
||
|
||
---
|
||
|
||
## 備註
|
||
|
||
- Docker 預設開放區網(0.0.0.0)
|
||
- 模型自動同步
|
||
- 支援多模型切換
|
||
|
||
---
|