中文 | English
Serverless API Proxy: Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects
Due to login restrictions on the original account(lopins), I'm now using this account(lopinx) for maintenance purposes.
- openai、gemini、claude、xAI、groq、llama and so on...
Environment Variables List
Variable Name | Type | Required/Optional | Description | Example Value/Format | Security Recommendations |
---|---|---|---|---|---|
ADMIN_USERNAME | String | Required | Admin dashboard login username | admin (strongly recommend changing) |
Use a strong username and avoid default values |
ADMIN_PASSWORD | Secret | Required | Admin dashboard login password | admin (strongly recommend changing to a strong password) |
Encrypt storage and use complex character combinations |
SESSION_SECRET | Secret | Required | Session cookie signing secret | $qA,.3!_I1^0AQ5rZm3!z-S3^(IgF$A8 (default value, must be changed in production) |
Generate a long random string and encrypt it |
API_ENDPOINTS | JSON/Array | Optional | Static API endpoint configuration (used if KV is not configured) | [["/openai", "https://api.openai.com/v1"], ["/gemini", "https://generativelanguage.googleapis.com"]] |
Mutually exclusive with KV configuration. Static configurations cannot be modified via the admin dashboard |
KV Namespace Binding Variables
Variable Name | Type | Required/Optional | Description | Associated Step |
---|---|---|---|---|
API_ENDPOINTS | KV Reference | Optional | Bind to Cloudflare KV Namespace to store dynamic API endpoint configurations | Bind to the Namespace Name of KV Namespace (must match env.API_ENDPOINTS in code) |
Provider | Identifier | API Endpoint | Documentation Link | Compatibility |
---|---|---|---|---|
Amazon Bedro 97EF ck | aws-bedrock | https://bedrock-runtime.us-east-1.amazonaws.com | docs | Non OpenAI Compatible |
Anthropic | anthropic | https://api.anthropic.com/v1 | docs | OpenAI Compatible |
Azure OpenAI | azure-openai | https://{RESOURCE_NAME}.openai.azure.com | docs | OpenAI Compatible |
Cartesia | cartesia | https://api.cartesia.ai | docs | Non OpenAI Compatible |
Cerebras | cerebras-ai | https://api.cerebras.ai/v1 | docs | OpenAI Compatible |
Cohere | cohere | https://api.cohere.ai | docs | OpenAI Compatible (https://api.cohere.ai/compatibility/v1) |
DeepSeek | deepseek | https://api.deepseek.com | docs | OpenAI Compatible |
Google AI Studio | google-ai-studio | https://generativelanguage.googleapis.com | docs | /v1beta/models/{model}:generateContent |
Google Vertex AI | google-vertex-ai | https://us-east1-aiplatform.googleapis.com | docs | /v1beta1/{model}:generateContent |
Grok | grok | https://api.x.ai/v1 | docs | OpenAI Compatible |
Groq | groq | https://api.groq.com/openai/v1 | docs | OpenAI Compatible |
HuggingFace | huggingface | https://router.huggingface.co/hf-inference/models/Qwen/Qwen3-235B-A22B/v1 | docs | OpenAI Compatible |
Mistral AI | mistral | https://api.mistral.ai/v1 | docs | OpenAI Compatible |
OpenAI | openai | https://api.openai.com/v1 | docs | OpenAI Compatible |
OpenRouter | openrouter | https://openrouter.ai/api/v1 | docs | OpenAI Compatible |
Perplexity | perplexity-ai | https://api.perplexity.ai | docs | OpenAI Compatible |
Replicate | replicate | https://api.replicate.com/v1 | docs | OpenAI Compatible |
Workers AI | workers-ai | https://api.cloudflare.com/client/v4/accounts/[account_id]/ai | docs | OpenAI Compatible |
Github AI | github-ai | https://models.github.ai/inference | docs | OpenAI Compatible |
import random
import re
from openai import OpenAI
ApiKey = "sk-Qa7GFtgCspCVfVGqKhm43QFmEB1FxsFvkXNysVycCuwDv2rz"
BaseUrl = "https://self.domain/openai/v1"
models = [
"gpt-3.5-turbo",
"gpt-4o-mini"
]
def gentext():
client = OpenAI(api_key=ApiKey, base_url=BaseUrl)
model = random.choice(models)
try:
completion = client.chat.completions.create(
model=model,
messages=[
{
"role": "system",
"content": "You are a smart and creative novelist."
},
{
"role": "user",
"content": "As the king of fairy tales, please write a short fairy tale, the theme of the story is to always maintain a kind heart, to stimulate children's interest and imagination in learning, and to help children better understand and accept the truth and values contained in the story. Only the story content is output, and the title and others are not required."
}
],
top_p=0.7,
temperature=0.7
)
text = completion.choices[0].message.content
print(f"{model}:{re.sub(r'\n+', '', text)}")
except Exception as e:
print(f"{model}:{str(e)}\n")