自己搭了个newapi来集合一下api玩,当时选服务器选错了,gemini被地区限制了,然后又有佬友分享了个claude api,但是只支持流输出,不能放到newapi里面,所以让claude糊了这个程序,直接放cloudflare worker就可以用了,详细功能看下面介绍
使用说明
程序使用一个全局配置对象 config 来管理各种设置:
const config = {
hostSecurity: {
enabled: true,
status: false,
whiteList: ['rfym.net', 'rfym.org'],
blackList: ['baidu.com', 'taobao.com']
},
originSecurity: {
enabled: true,
status: false,
whiteList: ['rfym.net', 'rfym.org'],
blackList: ['baidu.com', 'taobao.com']
}
}
hostSecurity: 控制允许访问的目标主机。originSecurity: 控制允许的请求来源。enabled: 是否启用安全检查。status:true表示使用白名单模式,false表示使用黑名单模式。whiteList: 允许的主机或来源列表。blackList: 禁止的主机或来源列表。
使用方法
ServerProxy
直接代理请求到指定的目标 URL。
格式:
/ServerProxy/[目标URL]
示例:
https://your-worker.com/ServerProxy/https://api.example.com/data
这将代理请求到 https://api.example.com/data。
UrlRedirect
通过 URL 参数重定向请求。
格式:
/UrlRedirect/[编码后的目标URL]
示例:
https://your-worker.com/UrlRedirect/[https%3A%2F%2Fwww.example.com%2Fpage]/http://domain.com/v1/chat
这将重定向请求到 https://www.example.com/page。
HostProxy
替换请求的主机名进行代理。
格式:
/HostProxy/[新主机名][原始路径]
示例:
https://your-worker.com/HostProxy/[api.newdomain.com]http://domain.com/v1/users
这将把请求代理到 https://api.newdomain.com/v1/users。
StreamRedirect
处理流式请求,使只支持流输出的openai api也能添加到newapi/oneapi。
格式:
/StreamRedirect/目标URL
示例:
POST https://your-worker.com/StreamRedirect/https://api.openai.com/v1/chat/completions
如果接口只支持流输出,则直接返回一个默认的响应体
PathRedirect
根据指定规则修改请求路径。
格式:
/PathRedirect/[from]/[to]/目标URL
示例:
https://your-worker.com/PathRedirect/[api]/[v2]http://example.com/api/data
这将把请求路径中的 “api” 替换为 “v2”,最终请求 http://example.com/v2/data。