zezhiya 发表于 4 天前

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

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安全代理
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 = extractPrefixAndRest(pathname, Object.keys(apiMapping));
if (!prefix) {
    return new Response('Not Found', { status: 404 });
}

const targetUrl = `${apiMapping}${rest}`;

try {
    const headers = new Headers();
    const allowedHeaders = ['accept', 'content-type', 'authorization'];
    for (const 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 ;
    }
}
return ;
}
在 Deno Deploy 中点击蓝色的“New Playground”

输入上面的代码就可以反代常用的墙外api网址,很好用
页: [1]
查看完整版本: 在国内用不了大模型API?试试API Proxy