Skip to content

API 文档

Sublink Worker 暴露了一组 RESTful 端点,帮助你在 CI、脚本或运维平台中批量生成订阅、保存配置以及共享短链。

基础信息

  • Base URLhttps://<your-worker-domain>.workers.dev
  • 所有请求均使用 HTTPS,推荐附带 Accept-Language 以获得对应语言的提示。

端点

1. 生成配置

/singbox

  • 方法GET
  • 参数
    • config (必需):URL 编码后的代理列表,可包含多行(使用 %0A 分隔)。
    • selectedRules:预定义规则集数组,JSON 字符串。
    • customRules:自定义规则数组,JSON 字符串。
    • pintrue/false,是否将自定义规则置顶。
    • configId:配合基础配置存储使用,详见基础配置
    • 其他:uagroup_by_countryenable_clash_uiexternal_controller 等。
text
/singbox?config=vmess%3A%2F%2Fexample&selectedRules=balanced

/clash

  • 方法GET
  • 参数与 /singbox 完全一致,响应内容为 text/yaml

/surge

  • 方法GET
  • 参数与 /singbox 基本一致,但不支持 customRules 置顶;返回 Surge 规则文本,并附带 subscription-userinfo 响应头。

/xray

  • 方法GET
  • 参数
    • config (必需):URL 编码后的代理配置(每行一个)。
    • ua:自定义 User-Agent,用于订阅抓取。

2. 短链接

/shorten

  • 方法GET
  • 参数url (必需),将生成 https://<domain>/s/<code>
json
{
  "shortUrl": "https://worker-domain.workers.dev/s/abcdefg"
}

/s/{shortCode}

  • 方法GET
  • 描述:根据 shortCode 重定向到原始 URL,当记录不存在时返回 404。

3. 保存基础配置

/config

  • 方法POST
  • Body
json
{
  "type": "clash" | "singbox" | "surge",
  "content": "配置内容"
}
  • 响应:成功返回 configId(字符串)。失败返回 400 + 错误描述。

使用方式:在生成配置时追加 configId 参数即可,例如:

https://worker-domain.workers.dev/clash?config=vmess://xxx&configId=clash_abc123

预定义规则集

可在 selectedRules 中使用以下名称:

Rule NameSite RulesIP Rules
Ad Blockcategory-ads-all
AI Servicescategory-ai-!cn
Bilibilibilibili
YouTubeyoutube
Googlegooglegoogle
Privateprivate
Location:CNgeolocation-cncn
Telegramtelegram
Microsoftmicrosoft
Appleapple
Bahamutbahamut
Social Mediafacebook, instagram, twitter, tiktok, linkedin
Streamingnetflix, hulu, disney, hbo, amazon
Gamingsteam, epicgames, ea, ubisoft, blizzard
Githubgithub, gitlab
Educationcoursera, edx, udemy, khanacademy, category-scholar-!cn
Financialpaypal, visa, mastercard, stripe, wise
Cloud Servicesaws, azure, digitalocean, heroku, dropbox

Sing-Box 规则集来自 lyc8503/sing-box-rules

自定义规则

customRules 接收 JSON 数组,每个对象支持以下字段:

字段说明
site域名规则,逗号分隔
ipIP 规则,逗号分隔
domain_suffix域名后缀
domain_keyword域名关键词
ip_cidrIP CIDR
protocol协议匹配
name对应的出站名称

示例:

json
[
  {
    "site": "google,anthropic",
    "ip": "private,cn",
    "domain_suffix": ".com,.org",
    "domain_keyword": "Mijia Cloud,push.apple",
    "ip_cidr": "192.168.0.0/16,10.0.0.0/8",
    "protocol": "http,tls,dns",
    "name": "🤪 MyCustomRule"
  }
]

pin=true 可把自定义规则置顶,优先级高于预设规则。

错误处理

  • 400 Bad Request:缺少 configurl 等必需参数,或 customRules 格式无效。
  • 404 Not Found:短链不存在、指定 configId 不存在。
  • 500 Internal Server Error:运行时异常;可查看 Worker 日志或增加 KV 可用性。

使用建议

  1. config 参数内若包含多条订阅,请使用 %0A(URL 编码后的换行)分隔。
  2. 配合 Accept-Language 可获得不同语言的提示文本。
  3. 通过 ua 自定义订阅抓取的 User-Agent,避免被目标服务器屏蔽。
  4. 配置持久化/短链写操作建议加上访问令牌或速率限制,避免滥用。

最后更新于:

遵循 MIT 许可证