AI Personal Learning
and practical guidance

Use deno for any large model secure proxy API to avoid leaking real IP and domain information

To solve the problem of certain areas can not directly request api.openai.com and so on big model API, or because the agent leaks information leading to blocking the account, before the use of CF proxy, may leak your IP, now there is a safer program.

1. First enter the deno official website to register an account


2. Create a project

Go to https://dash.deno.com/account/projects and click on "New Playground".

Use deno to proxy API for any large model to avoid leakage of real IP blocking through transmission-1

 

3. Paste the code and save it

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];
}

 

Use deno to proxy API for any large model to avoid leakage of real IP blocking through transmission-1

 

4. Usage

The default domain name is https://hungry-lamb-22.deno.dev/

interviewshttps://hungry-lamb-22.deno.dev/xai is equivalent to visiting https://api.x.ai/

Following the format in the code, you can add a new big model request address

 

5. Customized domain name

Go to Settings and bind your own domain name

Use deno for any large model secure proxy API to avoid leaking real IP and domain information-1

 

Shared Proxy Address

Chief AI Sharing CircleThis content has been hidden by the author, please enter the verification code to view the content
Captcha:
Please pay attention to this site WeChat public number, reply "CAPTCHA, a type of challenge-response test (computing)", get the verification code. Search in WeChat for "Chief AI Sharing Circle"or"Looks-AI"or WeChat scanning the right side of the QR code can be concerned about this site WeChat public number.

AI Easy Learning

The layman's guide to getting started with AI

Help you learn how to utilize AI tools at a low cost and from a zero base.AI, like office software, is an essential skill for everyone. Mastering AI will give you an edge in your job search and half the effort in your future work and studies.

View Details>
May not be reproduced without permission:Chief AI Sharing Circle " Use deno for any large model secure proxy API to avoid leaking real IP and domain information

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish