共计 872 个字符,预计需要花费 3 分钟才能阅读完成。
利用 cf_worker 反代 apenai api 地址: https://github.com/x-dr/chatgptProxyAPI.git
-
- const TELEGRAPH_URL = ‘https://api.openai.com’;
-
- addEventListener(‘fetch’, event => {
- event.respondWith(handleRequest(event.request))
- })
-
- async function handleRequest(request) {
- const url = new URL(request.url);
- url.host = TELEGRAPH_URL.replace(/^https?:///, ”);
- const modifiedRequest = new Request(url.toString(), {
- headers: request.headers,
- method: request.method,
- body: request.body,
- redirect: ‘follow’
- });
- const response = await fetch(modifiedRequest);
- const modifiedResponse = new Response(response.body, response);
- // 添加允许跨域访问的响应头
- modifiedResponse.headers.set(‘Access-Control-Allow-Origin’, ‘*’);
- return modifiedResponse;
- }
复制代码
使用: https://openai.1rmb.tk
|
网友回复:
注册 : 为什么要反代?
minick: 不需要反代,看你用哪个模板,把 api chatgpt.php 移动到海外服务器,修改 index.html,把这个文件改成海外的就行了
机长 : cf 也可以
rogerskys: 这个反带的意义是撒?。。。。
byg: 可以直接反代 api.openai 吗佬
ansheng: 可以,我更新了
langer: 太牛逼了 用上了 感谢感谢!!