3405 words
17 minutes
Accessing AI Platform APIs Through a Proxy

The Project#

LLM Proxy

Why a Proxy#

Most AI providers restrict access from mainland China, so their APIs are effectively out of reach from there — you need a proxy in between.

Take OpenAI’s access restrictions, for example:

  • Blocked from mainland China
  • Blocked from Hong Kong as well

The Approach#

Deploy a proxy on a US-based server, then route all your AI API traffic through it.

Deployment#

I added mongoose to keep a record of incoming requests, so it has to be installed first — skip this if you don’t care about request logging.

Terminal window
# Initialize the project
npm init -y
# Install mongoose
npm install mongoose

I run it under pm2:

Terminal window
# Start the service
pm2 start llm-proxy.js --name llm-proxy
# With environment variables
MONGODB_URI=mongodb://localhost:27017/llm-proxy PORT=8088 HOST=0.0.0.0 pm2 start llm-proxy.js --name llm-proxy
# List processes
pm2 list
# Stop the service
pm2 stop llm-proxy

The Code#

The proxy server#

llm-proxy.js
// Import Node.js built-in modules
const http = require('http');
const https = require('https'); // Pick http or https depending on the target URL's protocol
const fs = require('fs');
const path = require('path');
const { URL } = require('url');
const mongoose = require('mongoose');
// Read environment variables
const PORT = process.env.PORT || 8088;
const HOST = process.env.HOST || '0.0.0.0';
const MONGODB_URI = process.env.MONGODB_URI || '';
// If MONGODB_URI is set, store request logs in MongoDB
let AiProxyUsage = null;
if (MONGODB_URI) {
try {
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true });
const AiProxyUsageSchema = new mongoose.Schema({
type: {
type: String,
required: true,
},
createTime: {
type: String,
required: true,
},
});
AiProxyUsage = mongoose?.models?.AiProxyUsage || mongoose.model('AiProxyUsage', AiProxyUsageSchema);
} catch (error) {
console.error(`Error connecting to MongoDB: ${error}`);
}
}
// API route mapping
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', // Note: the actual Meta API may differ
'/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'
};
// Headers (lowercase) that are allowed to be forwarded to the target API
const allowedHeaders = ['accept', 'content-type', 'authorization'];
// Helper: extract the matching prefix and the remainder from a pathname
function extractPrefixAndRest(pathname, prefixes) {
for (const prefix of prefixes) {
if (pathname.startsWith(prefix)) {
return [prefix, pathname.slice(prefix.length)];
}
}
return [null, null];
}
// Create the HTTP server
const server = http.createServer(async (req, res) => {
// Parse the request URL
// req.url only carries the path and query string, so build the full URL from the host header
const requestUrl = new URL(req.url, `http://${req.headers.host}`);
const pathname = requestUrl.pathname;
// 1. Root path and /index.html -> serve the local HTML file
if (pathname === '/' || pathname === '/index.html') {
const filePath = path.join(__dirname, 'index.html'); // assumes index.html sits next to the script
fs.readFile(filePath, (err, data) => {
if (err) {
console.error(`Error reading index.html: ${err}`);
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end('Internal Server Error - Could not read index.html');
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
return; // done handling the request
}
// 2. Handle robots.txt
if (pathname === '/robots.txt') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('User-agent: *\nDisallow: /');
return; // done handling the request
}
// 3. Handle API proxying
const [prefix, rest] = extractPrefixAndRest(pathname, Object.keys(apiMapping));
if (!prefix) {
// No known prefix matched: return 404
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('Not Found');
return; // done handling the request
}
// Build the target API URL
const targetBaseUrl = apiMapping[prefix];
const targetUrl = `${targetBaseUrl}${rest}${requestUrl.search}`; // includes the query string
// Options for the forwarded request
const options = {
method: req.method,
headers: {},
// agent: targetBaseUrl.startsWith('https') ? new https.Agent({ keepAlive: true }) : new http.Agent({ keepAlive: true }) // optional: use an agent for connection reuse
};
// Copy over the allowed headers
for (const key in req.headers) {
if (allowedHeaders.includes(key.toLowerCase())) {
options.headers[key] = req.headers[key];
}
}
// Make sure the host header points at the target, not the proxy
options.headers['host'] = new URL(targetBaseUrl).host;
// Pick the http or https module for the request
const protocol = targetBaseUrl.startsWith('https') ? https : http;
// Create the proxied request
const proxyReq = protocol.request(targetUrl, options, (proxyRes) => {
// Response headers
// Copy the target's response headers to the client response
const responseHeaders = { ...proxyRes.headers }; // copy them
// Add a few extra security headers
responseHeaders['X-Content-Type-Options'] = 'nosniff';
responseHeaders['X-Frame-Options'] = 'DENY';
responseHeaders['Referrer-Policy'] = 'no-referrer';
// Optionally strip or tweak headers coming back from the target, e.g. 'transfer-encoding'
// delete responseHeaders['transfer-encoding'];
// Write the target's status code and processed headers to the client response
res.writeHead(proxyRes.statusCode, responseHeaders);
// Stream the target's response body to the client response
proxyRes.pipe(res, { end: true });
});
// Handle proxy request errors
proxyReq.on('error', (err) => {
console.error(`Proxy request error: ${err}`);
if (!res.headersSent) {
res.writeHead(502, { 'Content-Type': 'text/plain' }); // 502 Bad Gateway
}
res.end('Bad Gateway');
});
// Log the request to MongoDB
if (MONGODB_URI && AiProxyUsage) {
const usage = new AiProxyUsage({
type: prefix,
createTime: new Date().toISOString(),
});
usage.save();
}
// Stream the client's request body into the proxied request
// For bodyless requests like GET/HEAD this is a no-op
req.pipe(proxyReq, { end: true });
});
// Start the server
server.listen(PORT, HOST, () => {
console.log(`Node.js proxy server running on http://${HOST}:${PORT}`);
console.log(`Root path serves './index.html'`);
console.log('Proxying the following prefixes:');
Object.keys(apiMapping).forEach(prefix => {
console.log(` ${prefix} -> ${apiMapping[prefix]}`);
});
});
// Optional: handle shutdown signals gracefully so pm2 reload/stop behaves
process.on('SIGINT', () => {
console.log('SIGINT signal received: closing HTTP server');
server.close(() => {
console.log('HTTP server closed');
process.exit(0);
});
});

The landing page#

index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🚀</text></svg>">
<title>LLM Proxy - 简单、安全、高效</title>
<!-- seo -->
<meta name="description" content="LLM Proxy - 提供简单、安全、高效、免费的 API 代理服务,让您的 AI 应用更加稳定、快速。">
<meta name="keywords" content="LLM Proxy, API Proxy, AI, 代理, 简单, 安全, 高效">
<meta name="robots" content="index, follow">
<meta name="googlebot" content="index, follow">
<meta name="bingbot" content="index, follow">
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio,line-clamp"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/languages/javascript.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/atom-one-light.min.css">
<script>
// Tailwind config
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['-apple-system', 'BlinkMacSystemFont', 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', 'Arial', 'sans-serif'],
mono: ['SF Mono', 'SFMono-Regular', 'Menlo', 'Monaco', 'Consolas', '"Liberation Mono"', '"Courier New"', 'monospace'],
},
maxWidth: {
'screen-xl': '1280px',
},
colors: {
'apple-blue': {
50: '#E8F2FF',
100: '#C9E0FF',
200: '#A6CDFF',
300: '#83BAFF',
400: '#5FA7FF',
500: '#3C94FF',
600: '#0071E3', // Apple button blue
700: '#0051A5',
800: '#00356B',
900: '#001A36',
},
'apple-gray': {
50: '#F9F9F9', // light gray background
100: '#F5F5F7', // Apple site background gray
200: '#E8E8ED',
300: '#D2D2D7',
400: '#B1B1B6',
500: '#86868B', // Apple site text gray
600: '#6E6E73',
700: '#414144',
800: '#2D2D2F',
900: '#1D1D1F', // Apple site dark text
}
},
boxShadow: {
'apple': '0 2px 5px -1px rgba(0, 0, 0, 0.1), 0 2px 5px -1px rgba(0, 0, 0, 0.06)',
'apple-md': '0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.05)',
'apple-lg': '0 10px 20px -5px rgba(0, 0, 0, 0.1), 0 5px 10px -5px rgba(0, 0, 0, 0.04)',
},
borderRadius: {
'apple': '10px',
'apple-sm': '6px'
}
}
}
}
</script>
<style type="text/tailwindcss">
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
letter-spacing: -0.2px;
}
.copy-btn:disabled svg {
color: theme('colors.green.500');
}
/* Apple-style scrollbar */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f3f4f6; /* gray-100 instead of apple-gray.100 */
border-radius: 100px;
}
::-webkit-scrollbar-thumb {
background: #d1d5db; /* gray-300 instead of apple-gray.300 */
border-radius: 100px;
}
::-webkit-scrollbar-thumb:hover {
background: #9ca3af; /* gray-400 instead of apple-gray.400 */
}
/* Custom code-highlight styles */
pre {
position: relative;
background: #f9fafb; /* gray-50 instead of apple-gray.50 */
border-radius: 0.375rem; /* rounded-md instead of borderRadius.apple-sm */
margin: 0;
padding: 1rem;
overflow: auto;
}
pre code {
font-family: theme('fontFamily.mono');
font-size: 0.9rem;
line-height: 1.5;
display: block;
padding: 0;
}
/* Keyword highlight */
.hljs-keyword {
color: #0033cc;
font-weight: 500;
}
/* String highlight */
.hljs-string {
color: #067d17;
}
/* Comment highlight */
.hljs-comment {
color: #888888;
font-style: italic;
}
/* Function highlight */
.hljs-function {
color: #6f42c1;
}
/* Number highlight */
.hljs-number {
color: #986801;
}
/* Attribute highlight */
.hljs-attr, .hljs-property {
color: #e36209;
}
.code-container {
position: relative;
border-radius: 0.375rem; /* rounded-md instead of borderRadius.apple-sm */
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); /* shadow-sm instead of boxShadow.apple */
overflow: hidden;
width: 100%;
max-width: 100%;
margin: 0 auto;
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.5rem 1rem;
background: #f3f4f6; /* gray-100 instead of apple-gray.100 */
border-bottom: 1px solid #e5e7eb; /* gray-200 instead of apple-gray.200 */
}
.code-title {
font-size: 0.85rem;
font-weight: 500;
color: #4b5563; /* gray-600 instead of apple-gray.600 */
}
.code-copy-btn {
background: transparent;
border: none;
cursor: pointer;
padding: 0.25rem;
border-radius: 4px;
color: #6b7280; /* gray-500 instead of apple-gray.500 */
transition: all 0.2s;
}
.code-copy-btn:hover {
color: #2563eb; /* blue-600 instead of apple-blue.600 */
background: rgba(0, 0, 0, 0.05);
}
</style>
<script>
// Make sure highlight.js runs as soon as the page has loaded
window.onload = function () {
hljs.configure({
languages: ['javascript']
});
hljs.highlightAll();
};
</script>
</head>
<body class="bg-apple-gray-50 text-apple-gray-900 font-sans flex flex-col items-center min-h-screen py-8 px-4">
<div class="w-full max-w-screen-xl space-y-6 md:space-y-8">
<div class="bg-gradient-to-br from-blue-600 to-blue-400 rounded-apple shadow-apple-lg text-center p-8 md:p-12">
<h1 class="text-4xl md:text-6xl font-medium tracking-tight mb-2 md:mb-3 text-white">LLM Proxy</h1>
<h2 class="text-xl md:text-2xl font-light mb-6 md:mb-8 text-white/90">简单、安全、高效</h2>
<p class="text-base md:text-xl leading-relaxed font-light text-white/90 mx-auto">
使用美国西部服务器,免费提供简单、安全、高效的 API 代理服务,让您的 AI 应用更加稳定、快速。
</p>
</div>
<div class="bg-white rounded-apple shadow-apple-md p-6 md:p-8">
<h2 class="text-xl md:text-2xl font-medium text-apple-gray-900 mb-3 text-left">可用端点</h2>
<p class="text-sm md:text-base font-light text-apple-gray-600 mb-6">选择并配置您需要的 AI 服务接口</p>
<div class="overflow-x-auto rounded-apple-sm">
<table class="w-full text-left text-sm md:text-base table-fixed">
<thead>
<tr>
<th class="w-[18%] pb-3 pt-2 px-3 md:px-4 font-medium text-apple-gray-600 border-b border-apple-gray-200">
服务
</th>
<th class="w-[42%] pb-3 pt-2 px-3 md:px-4 font-medium text-apple-gray-600 border-b border-apple-gray-200">
代理地址
</th>
<th class="w-[40%] pb-3 pt-2 px-3 md:px-4 font-medium text-apple-gray-600 border-b border-apple-gray-200">
原始地址</th>
</tr>
</thead>
<tbody class="divide-y divide-apple-gray-200">
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">OpenAI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/openai</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/openai" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://platform.openai.com/docs/api-reference" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.openai.com</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Anthropic Claude</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/claude</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/claude" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://docs.anthropic.com/claude/reference/getting-started-with-the-api" target="_blank"
rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.anthropic.com</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Google Gemini</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/gemini</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/gemini" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://ai.google.dev/api/rest" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://generativelanguage.googleapis.com</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Groq</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/groq</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/groq" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://console.groq.com/docs/api-reference" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.groq.com</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Meta AI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/meta</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/meta" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://developers.facebook.com/docs/graph-api" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://developers.facebook.com/docs/graph-api</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Cohere</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/cohere</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/cohere" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://docs.cohere.com/reference/about" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.cohere.ai</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Together AI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/together</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/together" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://docs.together.ai/reference/inference" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.together.xyz</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">X.ai (Grok)</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/xai</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/xai" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://docs.x.ai/" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.x.ai</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Hugging Face</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/huggingface</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/huggingface" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://huggingface.co/docs/api-inference/index" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api-inference.huggingface.co</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">OpenRouter</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/openrouter</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/openrouter" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://openrouter.ai/docs" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://openrouter.ai/api</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Fireworks AI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/fireworks</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/fireworks" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://readme.fireworks.ai/reference/introduction" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.fireworks.ai</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Portkey AI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/portkey</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/portkey" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://portkey.ai/docs/api-reference/introduction" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.portkey.ai</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Novita AI</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/novita</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/novita" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://docs.novita.ai/api-reference" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://api.novita.ai</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Discord</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/discord</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/discord" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://discord.com/developers/docs/intro" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://discord.com/api</a>
</td>
</tr>
<tr>
<td class="py-3.5 px-3 md:px-4 font-medium text-apple-gray-800 align-middle">Telegram</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<div class="flex items-center gap-1">
<span
class="font-mono text-apple-gray-600 break-words min-w-0 text-sm">https://llm-proxy.mihouo.com/telegram</span>
<button
class="copy-btn flex-shrink-0 p-1.5 rounded-full text-apple-gray-500 hover:bg-apple-gray-100 hover:text-apple-blue-600 focus:outline-none focus:ring-1 focus:ring-apple-blue-500 transition-colors duration-150"
data-copy-text="https://llm-proxy.mihouo.com/telegram" aria-label="复制地址">
</button>
</div>
</td>
<td class="py-3.5 px-3 md:px-4 align-middle">
<a href="https://core.telegram.org/bots/api" target="_blank" rel="noopener noreferrer"
class="font-mono text-apple-blue-600 hover:underline break-words text-sm">https://core.telegram.org/bots/api</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Usage example -->
<div class="bg-white rounded-apple shadow-apple-md p-6 md:p-8 text-center">
<h2 class="text-xl md:text-2xl font-medium mb-4 text-apple-gray-800">使用示例</h2>
<p class="text-base md:text-lg font-light text-apple-gray-600 mb-6">通过几行简单的代码,即可轻松连接到 API 服务</p>
<div class="code-container mx-auto text-left">
<div class="code-header">
<span class="code-title">JavaScript</span>
<button class="code-copy-btn" aria-label="复制代码">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4"
viewBox="0 0 16 16">
<path
d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z">
</path>
<path
d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z">
</path>
</svg>
</button>
</div>
<pre><code class="language-javascript">// Import the OpenAI library
const { OpenAI } = require('openai');
// Create the API client
const openai = new OpenAI({
apiKey: 'sk-**************************************',
baseURL: 'https://llm-proxy.mihouo.com/openai/v1',
});
// Example request
async function generateResponse() {
const response = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: "你是一个专业的AI助手。" },
{ role: "user", content: "你好,请介绍一下自己。" }
],
temperature: 0.7,
});
console.log(response.choices[0].message.content);
}</code></pre>
</div>
</div>
<div class="bg-white rounded-apple shadow-apple-md p-6 text-center">
<div class="flex flex-col md:flex-row items-center justify-center space-y-2 md:space-y-0 md:space-x-8">
<p class="flex items-center text-apple-gray-500 text-sm">
<span class="inline-block w-2.5 h-2.5 bg-green-500 rounded-full mr-2"></span>
<span class="font-light">状态:</span>
<span class="text-apple-gray-700 font-medium ml-1">运行中</span>
</p>
<p class="text-sm text-apple-gray-500">
<span class="font-light">北京时间:</span>
<span id="live-time" class="font-medium text-apple-gray-700 ml-1">加载中...</span>
</p>
</div>
</div>
</div>
<script>
// Live clock
function updateLiveTime() {
const timeElement = document.getElementById('live-time');
if (timeElement) {
const now = new Date();
const beijingTime = now.toLocaleString('zh-CN', {
timeZone: 'Asia/Shanghai',
hour12: false,
year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit'
});
timeElement.textContent = beijingTime.replace(/[\/]/g, '-').replace(/\s+/g, ' ').trim();
}
}
updateLiveTime();
setInterval(updateLiveTime, 1000);
// --- Copy button script ---
document.addEventListener('DOMContentLoaded', () => {
const copyButtons = document.querySelectorAll('.copy-btn');
// Re-run highlighting once the DOM is ready
hljs.configure({
languages: ['javascript']
});
hljs.highlightAll();
// Code-block copy behavior
const codeBlock = document.querySelector('pre code');
const codeCopyBtn = document.querySelector('.code-copy-btn');
if (codeBlock && codeCopyBtn) {
codeCopyBtn.addEventListener('click', () => {
const code = codeBlock.textContent;
navigator.clipboard.writeText(code).then(() => {
// Success feedback
const originalSvg = codeCopyBtn.innerHTML;
// Swap in the success icon
codeCopyBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4 text-green-500" viewBox="0 0 16 16"><path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425z"/></svg>`;
// Restore the original icon after 1.5s
setTimeout(() => {
codeCopyBtn.innerHTML = originalSvg;
}, 1500);
}).catch(err => {
console.error('无法复制代码: ', err);
alert('复制失败,请手动复制。');
});
});
}
// SVG icons - Apple style
const originalIconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4" viewBox="0 0 16 16"><path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/><path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/></svg>`;
const successIconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="w-4 h-4" viewBox="0 0 16 16"><path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425z"/></svg>`;
copyButtons.forEach(button => {
button.innerHTML = originalIconSvg; // Set the initial icon
button.addEventListener('click', () => {
const textToCopy = button.dataset.copyText;
if (!textToCopy) {
console.error('无复制内容');
return;
}
if (!navigator.clipboard) {
console.error('剪贴板 API 不可用');
alert('抱歉,您的浏览器不支持或未启用剪贴板功能。');
return;
}
navigator.clipboard.writeText(textToCopy).then(() => {
// Success feedback - smooth Apple-style transition
button.innerHTML = successIconSvg;
button.disabled = true;
setTimeout(() => {
button.innerHTML = originalIconSvg; // Restore the icon
button.disabled = false;
}, 1500); // Restore after 1.5s
}).catch(err => {
console.error('无法复制文本: ', err);
alert('复制失败,请手动复制。');
});
});
});
});
</script>
</body>
</html>
Accessing AI Platform APIs Through a Proxy
https://www.mihouo.com/en/posts/tool-share/llm-api-proxy/
Author
Jia
Published at
2025-04-28
License
CC BY-NC-SA 4.0