中文 | English
这是一个 Cloudflare Worker 中转适配器,用于把 https://unlimited.surf 转换成 OpenAI 兼容的 /v1/* 接口,以及 Anthropic/Claude Code 兼容的 /v1/messages 和 /anthropic/* 接口。
据网友反馈,社区有人将unlimited.surf接入Claude code,结果被控制了电脑写入了乱七八糟的东西,可能网站有投毒行为,建议不要接入有控制权的agent,可以使用cherry-studio等。(相关反馈)[eooce#1]
- OpenAI 兼容:
/v1/chat/completions、/v1/responses、/v1/models、/v1/files。 - Anthropic 兼容:
/v1/messages、/v1/models、/anthropic/v1/messages、/anthropic/v1/models。 - unlimited.surf 原始接口代理:
/api/*会直接转发到上游。 - Web Search:映射到上游
POST /api/search。 - Merge AI:映射到上游
POST /api/merge。 - Files:上传/提取映射到上游
POST /api/attachments/extract。 - Agent Setup、Codex、MCP:提供说明和配置入口,分别是
/v1/setup、/v1/codex、/v1/mcp。 - 多 Key 负载均衡:支持配置多个上游 key 轮调,429/401 自动换 key 重试;支持多个客户端 key 白名单。
注意:MCP server 仍然需要在本地 agent、IDE 或 Claude Code/Codex 环境里运行。这个 Worker 只提供模型 API 端点,不会在 Cloudflare 边缘侧读取或修改你的本地文件。
Worker 支持两层 Key 池:
| Secret | 用途 | 行为 |
|---|---|---|
UNLIMITED_SURF_API_KEYS |
上游 unlimited.surf key 池 | Round-Robin 轮调;429/401 自动换 key 重试 |
WORKER_API_KEYS |
客户端访问 key 白名单 | 任一有效 key 即可访问 Worker |
也兼容旧版单 key:UNLIMITED_SURF_API_KEY、WORKER_API_KEY。
配置示例(10 把 key,换行分隔):
UNLIMITED_SURF_API_KEYS=key1
key2
key3
...
WORKER_API_KEYS=client-key-1
client-key-2
...
本地开发可在 .dev.vars 中填写(该文件已在 .gitignore 中)。
/health 会返回 upstream_key_pool_size、worker_key_pool_size 和 key_rotation,不会暴露 key 明文。调试轮调时可运行 wrangler tail 查看 upstream_key_index 日志。
可以把本项目推送到 GitHub 私有仓库,然后让 Cloudflare 在每次提交后自动部署。
创建 GitHub 仓库并推送本项目。不要把 unlimited.surf API key 提交进仓库。
- 打开 Cloudflare Dashboard。
- 进入
Workers & Pages。 - 点击
Create。 - 选择
Import a repository或Connect to Git。 - 按提示授权 Cloudflare 访问 GitHub。
- 选择这个项目所在的 GitHub 仓库。
- Root directory 填
/,除非你把项目放在仓库子目录里。
Cloudflare 部署表单里可以使用:
Framework preset: None
Build command: npm install
Deploy command: npx wrangler deploy
Root directory: /
Wrangler config: wrangler.toml
如果 Cloudflare 只提供一个命令输入框,可以填:
npm install && npx wrangler deploy在 Worker 设置里添加上游 key(单 key 或多 key 二选一):
UNLIMITED_SURF_API_KEY=<你的 unlimited.surf key>
# 或
UNLIMITED_SURF_API_KEYS=<key1 换行 key2 换行 ...>
推荐再添加客户端访问 key,用来保护 Worker(单 key 或多 key 白名单):
WORKER_API_KEY=<你自定义的调用密钥>
# 或
WORKER_API_KEYS=<client-key-1 换行 client-key-2 换行 ...>
通常位置是:
Workers & Pages -> 你的 Worker -> Settings -> Variables -> Secrets
请只把 key 放到 Secret 里,不要写进 wrangler.toml、README.md 或任何 GitHub 文件。
如果设置了 WORKER_API_KEY 或 WORKER_API_KEYS,客户端调用 Worker 时必须传白名单中的任一 key。如果没有设置 worker key,Worker 会保持兼容模式,客户端传任意 key 都可以,真正请求上游时使用 UNLIMITED_SURF_API_KEY(S) 轮调。
部署完成后打开:
https://<your-worker>.workers.dev/health
看到 JSON 里有 "ok": true 即表示 Worker 正常运行。多 key 模式下还会显示 upstream_key_pool_size 和 key_rotation。
如果已经设置 WORKER_API_KEY,验证请求也需要带上它:
curl https://<your-worker>.workers.dev/health \
-H "Authorization: Bearer <你的 WORKER_API_KEY>"测试 OpenAI 模型列表:
curl https://<your-worker>.workers.dev/v1/models \
-H "Authorization: Bearer <你的 WORKER_API_KEY>"测试 Anthropic/Agent 配置说明:
curl https://<your-worker>.workers.dev/v1/setup \
-H "Authorization: Bearer <你的 WORKER_API_KEY>"也可以在本地直接部署:
npm install -g wrangler
wrangler login
wrangler secret put UNLIMITED_SURF_API_KEY
wrangler secret put UNLIMITED_SURF_API_KEYS
wrangler secret put WORKER_API_KEY
wrangler secret put WORKER_API_KEYS
wrangler deploy单 key 与多 key 可并存配置:若设置了 UNLIMITED_SURF_API_KEYS / WORKER_API_KEYS,优先使用 key 池;否则 fallback 到单 key。
UNLIMITED_SURF_API_KEY(S) 填 unlimited.surf 的真实 key。WORKER_API_KEY(S) 填你自定义给客户端使用的 key。
WORKER_API_KEY(S) 是可选的:如果不设置,客户端可以传任意 key;如果设置了,客户端必须传白名单中的 key。也可以不配置上游 secret,改为每次请求直接传 unlimited.surf key,但不推荐这样做。
推荐配置上游 key 池 + 客户端 key 白名单:
UNLIMITED_SURF_API_KEYS=<key1 换行 key2 ...>
WORKER_API_KEYS=<client-key-1 换行 client-key-2 ...>
也兼容旧版单 key 配置:
UNLIMITED_SURF_API_KEY=<你的 unlimited.surf key>
WORKER_API_KEY=<你自定义的客户端 key>
客户端调用时使用 WORKER_API_KEY,不要直接暴露 unlimited.surf key:
curl https://<your-worker>.workers.dev/v1/chat/completions \
-H "Authorization: Bearer <你的 WORKER_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"model":"gateway-gpt-5","messages":[{"role":"user","content":"Hello"}]}'规则如下:
设置了 WORKER_API_KEY 或 WORKER_API_KEYS:
客户端必须传白名单中的任一 key
Worker 使用 UNLIMITED_SURF_API_KEYS 轮调请求 unlimited.surf
上游 429/401 时自动换下一个 key 重试
没有设置 worker key:
客户端传任意 key 都可以
Worker 优先使用 UNLIMITED_SURF_API_KEY(S) 轮调请求 unlimited.surf
如果也没有上游 secret,则把客户端传入的 key 当作 unlimited.surf key
Base URL:
https://<your-worker>.workers.dev/v1
支持接口:
GET /v1/modelsPOST /v1/chat/completionsPOST /v1/responsesPOST /v1/searchPOST /v1/mergeGET /v1/key、GET /v1/usagePOST /v1/filesPOST /v1/files/extract、POST /v1/attachments/extractGET /v1/setup、GET /v1/codex、GET /v1/mcp
示例:
curl https://<your-worker>.workers.dev/v1/chat/completions \
-H "Authorization: Bearer <你的 WORKER_API_KEY 或 unlimited.surf key>" \
-H "Content-Type: application/json" \
-d '{"model":"gateway-gpt-5","messages":[{"role":"user","content":"Hello"}],"stream":true}'Base URL:
https://<your-worker>.workers.dev
支持接口:
POST /v1/messagesGET /v1/modelsPOST /anthropic/v1/messagesGET /anthropic/v1/modelsGET /v1/setup、GET /v1/codex、GET /v1/mcp
Claude Code PowerShell 示例:
$env:ANTHROPIC_BASE_URL = "https://<your-worker>.workers.dev"
$env:ANTHROPIC_AUTH_TOKEN = "<你的 WORKER_API_KEY 或 unlimited.surf key>"
$env:ANTHROPIC_API_KEY = "<你的 WORKER_API_KEY 或 unlimited.surf key>"
$env:ANTHROPIC_MODEL = "claude-opus-4-7-20260101"
claude- Chat 映射到上游
POST /api/chat。 - Web Search 在调用
/v1/search、传入web_search_options、传入query,或包含 web search tool 时映射到POST /api/search。 - Merge AI 在调用
/v1/merge、传入merge: true,或传入 2 个以上models时映射到POST /api/merge。 - Models 映射到上游
GET /api/models,如果上游不可用会返回内置 fallback 模型列表。 - Files 映射到上游
POST /api/attachments/extract。如果需要持久化文件,需要额外接入 Cloudflare KV 或 R2。 - Codex、Agent Setup、MCP 是配置说明入口;MCP 工具执行仍然发生在本地 agent/IDE 里。
- Embeddings、audio、images 会返回
501,因为当前提供的 unlimited.surf 文档中没有这些原生接口。
任何 /api/* 请求都会被转发到 unlimited.surf,并自动带上配置好的 key,因此你仍然可以通过 Worker 使用原始接口。
This is a Cloudflare Worker adapter for https://unlimited.surf. It exposes OpenAI-compatible /v1/* routes and Anthropic/Claude Code-compatible /v1/messages plus /anthropic/* aliases.
- OpenAI-compatible routes:
/v1/chat/completions,/v1/responses,/v1/models,/v1/files. - Anthropic-compatible routes:
/v1/messages,/v1/models,/anthropic/v1/messages,/anthropic/v1/models. - Raw upstream proxy:
/api/*forwards directly to unlimited.surf. - Web Search maps to upstream
POST /api/search. - Merge AI maps to upstream
POST /api/merge. - Files extraction maps to upstream
POST /api/attachments/extract. - Agent Setup, Codex, and MCP info endpoints are available at
/v1/setup,/v1/codex, and/v1/mcp. - Multi-key load balancing: upstream key pool with round-robin and automatic 429/401 failover; client key whitelist support.
MCP servers still run inside your local agent, IDE, Claude Code, or Codex environment. This Worker only provides the model API endpoint and does not read or modify local files from Cloudflare.
The Worker supports two key pools:
| Secret | Purpose | Behavior |
|---|---|---|
UNLIMITED_SURF_API_KEYS |
Upstream unlimited.surf key pool | Round-robin; auto-retry on 429/401 |
WORKER_API_KEYS |
Client access key whitelist | Any valid key grants access |
Legacy single-key secrets (UNLIMITED_SURF_API_KEY, WORKER_API_KEY) remain supported.
Example (10 keys, newline-separated):
UNLIMITED_SURF_API_KEYS=key1
key2
...
WORKER_API_KEYS=client-key-1
client-key-2
...
For local dev, put values in .dev.vars (gitignored).
/health returns upstream_key_pool_size, worker_key_pool_size, and key_rotation without exposing key values. Use wrangler tail to inspect upstream_key_index logs during debugging.
Push this project to a GitHub repository, then let Cloudflare deploy it automatically on each commit.
Create a GitHub repository and push this project. Do not commit your unlimited.surf API key.
- Open the Cloudflare Dashboard.
- Go to
Workers & Pages. - Click
Create. - Choose
Import a repositoryorConnect to Git. - Authorize Cloudflare to access GitHub if prompted.
- Select the repository containing this project.
- Set Root directory to
/unless the project is in a subdirectory.
Use these values:
Framework preset: None
Build command: npm install
Deploy command: npx wrangler deploy
Root directory: /
Wrangler config: wrangler.toml
If Cloudflare shows only one command field, use:
npm install && npx wrangler deployAdd upstream key(s) in the Worker settings (single or pool):
UNLIMITED_SURF_API_KEY=<your unlimited.surf key>
# or
UNLIMITED_SURF_API_KEYS=<key1 newline key2 ...>
Recommended: add client-facing key(s) to protect the Worker:
WORKER_API_KEY=<your custom client key>
# or
WORKER_API_KEYS=<client-key-1 newline client-key-2 ...>
The usual location is:
Workers & Pages -> your Worker -> Settings -> Variables -> Secrets
Keep keys in Secrets only. Do not put them in wrangler.toml, README.md, or GitHub files.
If WORKER_API_KEY or WORKER_API_KEYS is set, clients must send a whitelisted key when calling the Worker. If no worker keys are set, the Worker keeps compatibility mode and accepts any client key while round-robinning UNLIMITED_SURF_API_KEY(S) for upstream requests.
Open:
https://<your-worker>.workers.dev/health
You should see JSON with "ok": true. With multiple keys configured, it also shows upstream_key_pool_size and key_rotation.
If WORKER_API_KEY is set, include it in verification requests too:
curl https://<your-worker>.workers.dev/health \
-H "Authorization: Bearer <your WORKER_API_KEY>"Test OpenAI-compatible models:
curl https://<your-worker>.workers.dev/v1/models \
-H "Authorization: Bearer <your WORKER_API_KEY>"Test Anthropic/agent setup docs:
curl https://<your-worker>.workers.dev/v1/setup \
-H "Authorization: Bearer <your WORKER_API_KEY>"You can also deploy from your local machine:
npm install -g wrangler
wrangler login
wrangler secret put UNLIMITED_SURF_API_KEY
wrangler secret put UNLIMITED_SURF_API_KEYS
wrangler secret put WORKER_API_KEY
wrangler secret put WORKER_API_KEYS
wrangler deployIf UNLIMITED_SURF_API_KEYS / WORKER_API_KEYS are set, the pools take priority; otherwise the Worker falls back to single-key secrets.
Use your real unlimited.surf key(s) for UNLIMITED_SURF_API_KEY(S). Use your own client-facing key(s) for WORKER_API_KEY(S).
WORKER_API_KEY(S) is optional. If not set, clients may send any key. If set, clients must send a whitelisted key. You can also skip upstream secrets and pass the unlimited.surf key on every request, but that is not recommended.
Recommended setup (key pools):
UNLIMITED_SURF_API_KEYS=<key1 newline key2 ...>
WORKER_API_KEYS=<client-key-1 newline client-key-2 ...>
Legacy single-key setup also works:
UNLIMITED_SURF_API_KEY=<your unlimited.surf key>
WORKER_API_KEY=<your custom client key>
Clients should use WORKER_API_KEY, not the upstream unlimited.surf key:
curl https://<your-worker>.workers.dev/v1/chat/completions \
-H "Authorization: Bearer <your WORKER_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"model":"gateway-gpt-5","messages":[{"role":"user","content":"Hello"}]}'Rules:
WORKER_API_KEY or WORKER_API_KEYS is set:
clients must send a whitelisted key
Worker round-robins UNLIMITED_SURF_API_KEYS for unlimited.surf
retries with the next key on upstream 429/401
No worker key is set:
clients may send any key
Worker prefers UNLIMITED_SURF_API_KEY(S) for unlimited.surf
if upstream secrets are also missing, the client key is treated as the unlimited.surf key
Base URL:
https://<your-worker>.workers.dev/v1
Supported routes:
GET /v1/modelsPOST /v1/chat/completionsPOST /v1/responsesPOST /v1/searchPOST /v1/mergeGET /v1/key,GET /v1/usagePOST /v1/filesPOST /v1/files/extract,POST /v1/attachments/extractGET /v1/setup,GET /v1/codex,GET /v1/mcp
Example:
curl https://<your-worker>.workers.dev/v1/chat/completions \
-H "Authorization: Bearer <your WORKER_API_KEY or unlimited.surf key>" \
-H "Content-Type: application/json" \
-d '{"model":"gateway-gpt-5","messages":[{"role":"user","content":"Hello"}],"stream":true}'Base URL:
https://<your-worker>.workers.dev
Supported routes:
POST /v1/messagesGET /v1/modelsPOST /anthropic/v1/messagesGET /anthropic/v1/modelsGET /v1/setup,GET /v1/codex,GET /v1/mcp
Claude Code PowerShell example:
$env:ANTHROPIC_BASE_URL = "https://<your-worker>.workers.dev"
$env:ANTHROPIC_AUTH_TOKEN = "<your WORKER_API_KEY or unlimited.surf key>"
$env:ANTHROPIC_API_KEY = "<your WORKER_API_KEY or unlimited.surf key>"
$env:ANTHROPIC_MODEL = "claude-opus-4-7-20260101"
claude- Chat maps to upstream
POST /api/chat. - Web Search maps to upstream
POST /api/searchwhen you call/v1/search, passweb_search_options, passquery, or include a web search tool. - Merge AI maps to upstream
POST /api/mergewhen you call/v1/merge, passmerge: true, or passmodelswith 2+ model IDs. - Models maps to upstream
GET /api/modelswith a fallback catalog if the upstream call fails. - Files maps upload/extract requests to upstream
POST /api/attachments/extract; persistent file storage requires adding KV or R2. - Codex, Agent Setup, and MCP are setup/info endpoints. MCP tool execution remains local to the client agent or IDE.
- Embeddings, audio, and images return
501because the provided unlimited.surf docs do not expose those native APIs.
Any /api/* request is forwarded to unlimited.surf with the configured key, so the original API remains available through the Worker.