https://github.com/lopinx/serverless-api-proxy
Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects
https://github.com/lopinx/serverless-api-proxy
ai api api-gateway apiproxy claude cohere discord fireworks gemini groq huggingface llama novita openai openrouter portkey telegram together
Last synced: 8 months ago
JSON representation
Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects
- Host: GitHub
- URL: https://github.com/lopinx/serverless-api-proxy
- Owner: lopinx
- License: mit
- Created: 2024-12-15T06:34:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-29T13:09:47.000Z (about 1 year ago)
- Last Synced: 2025-03-29T20:51:08.713Z (9 months ago)
- Topics: ai, api, api-gateway, apiproxy, claude, cohere, discord, fireworks, gemini, groq, huggingface, llama, novita, openai, openrouter, portkey, telegram, together
- Language: JavaScript
- Homepage: https://vercel-api-proxy.lopins.cn
- Size: 7.81 KB
- Stars: 11
- Watchers: 1
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Serverless API Proxy
Serverless API Proxy: Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects
## Notice
**Due to login restrictions on the original account([lopins](https://github.com/lopins)), I'm now using this account([lopinx](https://github.com/lopinx)) for maintenance purposes.**
## Support
- openai
- gemini
- groq
- claude
- cohere
- huggingface.co
- Fireworks AI
- ...
## How to deploy
### Vercel
[](https://vercel.com/new/clone?repository-url=https://github.com/lopinx/serverless-api-proxy)
### Cloudflare
[](https://deploy.workers.cloudflare.com/?url=https://github.com/lopinx/serverless-api-proxy)
### Netlify
[](https://app.netlify.com/start/deploy?repository=https://github.com/lopinx/serverless-api-proxy)
## How to use
### Configure proxy address
```
# openai
https://self.domain/openai/
# gemini
https://self.domain/gemini/
# groq
https://self.domain/groq/
# claude
https://self.domain/claude/
# cohere
https://self.domain/cohere/
# huggingface
https://self.domain/huggingface/
# fireworks
https://self.domain/fireworks/
```
| Name | Original API | Proxy API | Use Example |
| :---: | :--- | :--- | :--- |
| OpenAI API | | `/openai/v1` | `/openai/v1/chat/completions` |
| Gemini API | | `/gemini/v1` | `/gemini/v1/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
| Gemini API | | `/gemini/v1beta` | `/gemini/v1beta/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
| Groq API | | `/groq/openai/v1` | `/groq/openai/v1/chat/completions` |
| Claude API | | `/claude/v1` | `/claude/v1/completions` |
| Cohere API | | `/cohere/v1` | `/cohere/v1/chat/completions` |
| Huggingface API | | `/huggingface` | `/huggingface/models/meta-llama/Llama-3.1-70B-Instruct/v1/chat/completions` |
| Fireworks API | | `/fireworks/v1` | `/fireworks/v1/chat/completions` |
### API Usage
``` python
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")
```
## Vercel Region List
https://vercel.com/docs/edge-network/regions#region-list