返回列表 发布新帖
查看: 86|回复: 0

在国内用不了大模型API?试试API Proxy

发表于 3 天前 | 查看全部 |阅读模式

立刻注册账号,享受更清爽的界面!

您需要 登录 才可以下载或查看,没有账号?注册

×
api-proxy.me 安全可靠的 API 代理服务
代理地址 源地址
https://api-proxy.me/anthropic https://api.anthropic.com
https://api-proxy.me/cerebras https://api.cerebras.ai
https://api-proxy.me/cohere https://api.cohere.ai
https://api-proxy.me/discord https://discord.com/api
https://api-proxy.me/fireworks https://api.fireworks.ai
https://api-proxy.me/gemini https://generativelanguage.googleapis.com
https://api-proxy.me/groq https://api.groq.com/openai
https://api-proxy.me/huggingface https://api-inference.huggingface.co
https://api-proxy.me/meta https://www.meta.ai/api
https://api-proxy.me/novita https://api.novita.ai
https://api-proxy.me/nvidia https://integrate.api.nvidia.com
https://api-proxy.me/oaipro https://api.oaipro.com
https://api-proxy.me/openai https://api.openai.com
https://api-proxy.me/openrouter https://openrouter.ai/api
https://api-proxy.me/portkey https://api.portkey.ai
https://api-proxy.me/reka https://api.reka.ai
https://api-proxy.me/telegram https://api.telegram.org
https://api-proxy.me/together https://api.together.xyz
https://api-proxy.me/xai https://api.x.ai


基于deno多模型API安全代理
  1. import { serve } from "https://deno.land/std/http/server.ts";

  2. const apiMapping = {
  3.   '/discord': 'https://discord.com/api',
  4.   '/telegram': 'https://api.telegram.org',
  5.   '/openai': 'https://api.openai.com',
  6.   '/claude': 'https://api.anthropic.com',
  7.   '/gemini': 'https://generativelanguage.googleapis.com',
  8.   '/meta': 'https://www.meta.ai/api',
  9.   '/groq': 'https://api.groq.com/openai',
  10.   '/xai': 'https://api.x.ai',
  11.   '/cohere': 'https://api.cohere.ai',
  12.   '/huggingface': 'https://api-inference.huggingface.co',
  13.   '/together': 'https://api.together.xyz',
  14.   '/novita': 'https://api.novita.ai',
  15.   '/portkey': 'https://api.portkey.ai',
  16.   '/fireworks': 'https://api.fireworks.ai',
  17.   '/openrouter': 'https://openrouter.ai/api'
  18. };

  19. serve(async (request) => {
  20.   const url = new URL(request.url);
  21.   const pathname = url.pathname;

  22.   if (pathname === '/' || pathname === '/index.html') {
  23.     return new Response('Service is running!', {
  24.       status: 200,
  25.       headers: { 'Content-Type': 'text/html' }
  26.     });
  27.   }
  28.   
  29.   if (pathname === '/robots.txt') {
  30.     return new Response('User-agent: *\nDisallow: /', {
  31.       status: 200,
  32.       headers: { 'Content-Type': 'text/plain' }
  33.     });
  34.   }

  35.   const [prefix, rest] = extractPrefixAndRest(pathname, Object.keys(apiMapping));
  36.   if (!prefix) {
  37.     return new Response('Not Found', { status: 404 });
  38.   }

  39.   const targetUrl = `${apiMapping[prefix]}${rest}`;

  40.   try {
  41.     const headers = new Headers();
  42.     const allowedHeaders = ['accept', 'content-type', 'authorization'];
  43.     for (const [key, value] of request.headers.entries()) {
  44.       if (allowedHeaders.includes(key.toLowerCase())) {
  45.         headers.set(key, value);
  46.       }
  47.     }

  48.     const response = await fetch(targetUrl, {
  49.       method: request.method,
  50.       headers: headers,
  51.       body: request.body
  52.     });

  53.     const responseHeaders = new Headers(response.headers);
  54.     responseHeaders.set('X-Content-Type-Options', 'nosniff');
  55.     responseHeaders.set('X-Frame-Options', 'DENY');
  56.     responseHeaders.set('Referrer-Policy', 'no-referrer');

  57.     return new Response(response.body, {
  58.       status: response.status,
  59.       headers: responseHeaders
  60.     });

  61.   } catch (error) {
  62.     console.error('Failed to fetch:', error);
  63.     return new Response('Internal Server Error', { status: 500 });
  64.   }
  65. });

  66. function extractPrefixAndRest(pathname, prefixes) {
  67.   for (const prefix of prefixes) {
  68.     if (pathname.startsWith(prefix)) {
  69.       return [prefix, pathname.slice(prefix.length)];
  70.     }
  71.   }
  72.   return [null, null];
  73. }
复制代码

Deno Deploy 中点击蓝色的“New Playground”
ba3067e207a5b3e5dc89134713f1a2de.jpg
输入上面的代码就可以反代常用的墙外api网址,很好用
爱生活,爱奶昔~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

  • 关注公众号
  • 添加微信客服
© 2025 Naixi Networks 沪ICP备13020230号-1|沪公网安备 31010702007642号
关灯 在本版发帖
扫一扫添加微信客服
返回顶部
快速回复 返回顶部 返回列表