赞
踩
✈ChatGPT的API接口为 https://api.openai.com 但是很多小伙伴不是国家区域不对,就试没有一个好的代理,经常chatgpt出现无法聊天的情况,那么自己搭建一个代理服务器那不是很香?还是免费的,直接整起来!图文教程,无缝链接!
https://www.cloudflare.com/zh-cn/
- 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);
- const headers_Origin = request.headers.get("Access-Control-Allow-Origin") || "*"
- 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', headers_Origin);
- return modifiedResponse;
- }

https://你自定义的项目名.workers.dev/v1/chat/completions
- {
- "error": {
- "message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.",
- "type": "invalid_request_error",
- "param": null,
- "code": null
- }
- }
上面的基本就算部署成功了,但是你还需要部署你自己的域名来访问,成为你自己专属的第一无二的api接口,所以你还需要绑定域名。
添加自定义域
输入你在Cloudflare托管的域名,自定义一个未使用的二级域名地址,并点添加自定义域
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。