解决某些地区无法直接请求api.openai.com等等大模型API,或者因为代理泄露信息导致封帐号,之前使用CF代理,可能会泄露你的IP,现在有一个较为安全的方案。
1.首先进入deno官网注册账号
2.创建项目
访问 https://dash.deno.com/account/projects,点击“New Playground”

3.粘贴代码并保存
import { serve } from "https://deno.land/std/http/server.ts";
const apiMapping = {
'/discord': 'https://discord.com/api',
'/telegram': 'https://api.telegram.org',
'/openai': 'https://api.openai.com',
'/claude': 'https://api.anthropic.com',
'/gemini': 'https://generativelanguage.googleapis.com',
'/meta': 'https://www.meta.ai/api',
'/groq': 'https://api.groq.com/openai',
'/xai': 'https://api.x.ai',
'/cohere': 'https://api.cohere.ai',
'/huggingface': 'https://api-inference.huggingface.co',
'/together': 'https://api.together.xyz',
'/novita': 'https://api.novita.ai',
'/portkey': 'https://api.portkey.ai',
'/fireworks': 'https://api.fireworks.ai',
'/openrouter': 'https://openrouter.ai/api'
};
serve(async (request) => {
const url = new URL(request.url);
const pathname = url.pathname;
if (pathname === '/' || pathname === '/index.html') {
return new Response('Service is running!', {
status: 200,
headers: { 'Content-Type': 'text/html' }
});
}
if (pathname === '/robots.txt') {
return new Response('User-agent: *\nDisallow: /', {
status: 200,
headers: { 'Content-Type': 'text/plain' }
});
}
const [prefix, rest] = extractPrefixAndRest(pathname, Object.keys(apiMapping));
if (!prefix) {
return new Response('Not Found', { status: 404 });
}
const targetUrl = `${apiMapping[prefix]}${rest}`;
try {
const headers = new Headers();
const allowedHeaders = ['accept', 'content-type', 'authorization'];
for (const [key, value] of request.headers.entries()) {
if (allowedHeaders.includes(key.toLowerCase())) {
headers.set(key, value);
}
}
const response = await fetch(targetUrl, {
method: request.method,
headers: headers,
body: request.body
});
const responseHeaders = new Headers(response.headers);
responseHeaders.set('X-Content-Type-Options', 'nosniff');
responseHeaders.set('X-Frame-Options', 'DENY');
responseHeaders.set('Referrer-Policy', 'no-referrer');
return new Response(response.body, {
status: response.status,
headers: responseHeaders
});
} catch (error) {
console.error('Failed to fetch:', error);
return new Response('Internal Server Error', { status: 500 });
}
});
function extractPrefixAndRest(pathname, prefixes) {
for (const prefix of prefixes) {
if (pathname.startsWith(prefix)) {
return [prefix, pathname.slice(prefix.length)];
}
}
return [null, null];
}

4.使用方法
默认域名是 https://hungry-lamb-22.deno.dev/
访问https://hungry-lamb-22.deno.dev/xai 等于访问 https://api.x.ai/
按照代码里的格式,你可以添加新的大模型请求地址
5.自定义域名
进入设置,绑定你自己的域名

共享代理地址


































