Skip to content

Commit 71f0c23

Browse files
committed
.
0 parents  commit 71f0c23

File tree

11 files changed

+522
-0
lines changed

11 files changed

+522
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vercel
2+
node_modules/
3+
package-lock.json

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Hk-Gosuto
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<div align="right">
2+
<a href="README_CN.md">中文</a> | <strong>English</strong>
3+
</div>
4+
<div align="center">
5+
<h1>Serverless API Proxy</h1>
6+
<p>Serverless API Proxy: Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects</p>
7+
</div>
8+
9+
## Support
10+
11+
- openai
12+
- gemini
13+
- groq
14+
- claude
15+
- cohere
16+
- huggingface.co
17+
- Fireworks AI
18+
- ...
19+
20+
## How to deploy
21+
22+
### Vercel
23+
24+
[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/lopins/serverless-api-proxy)
25+
26+
### Cloudflare
27+
28+
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lopins/serverless-api-proxy)
29+
30+
### Netlify
31+
32+
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/lopins/serverless-api-proxy)
33+
34+
## How to use
35+
36+
### Configure proxy address
37+
38+
```
39+
# openai
40+
https://self.domain/openai/
41+
42+
# gemini
43+
https://self.domain/gemini/
44+
45+
# groq
46+
https://self.domain/groq/
47+
48+
# claude
49+
https://self.domain/claude/
50+
51+
# cohere
52+
https://self.domain/cohere/
53+
54+
# huggingface
55+
https://self.domain/huggingface/
56+
57+
# fireworks
58+
https://self.domain/fireworks/
59+
```
60+
61+
| Name | Original API | Proxy API | Use Example |
62+
| :---: | :--- | :--- | :--- |
63+
| OpenAI API | <https://api.openai.com/v1> | `/openai/v1` | `/openai/v1/chat/completions` |
64+
| Gemini API | <https://generativelanguage.googleapis.com/v1> | `/gemini/v1` | `/gemini/v1/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
65+
| Gemini API | <https://generativelanguage.googleapis.com/v1beta> | `/gemini/v1beta` | `/gemini/v1beta/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
66+
| Groq API | <https://api.groq.com/groq/openai/v1> | `/groq/openai/v1` | `/groq/openai/v1/chat/completions` |
67+
| Claude API | <https://api.anthropic.com/v1> | `/claude/v1` | `/claude/v1/completions` |
68+
| Cohere API | <https://api.cohere.ai/v1> | `/cohere/v1` | `/cohere/v1/chat/completions` |
69+
| Huggingface API | <https://api-inference.huggingface.co> | `/huggingface` | `/huggingface/models/meta-llama/Llama-3.1-70B-Instruct/v1/chat/completions` |
70+
| Fireworks API | <https://api.fireworks.ai/v1> | `/fireworks/v1` | `/fireworks/v1/chat/completions` |
71+
72+
73+
### API Usage
74+
75+
``` python
76+
import random
77+
import re
78+
79+
from openai import OpenAI
80+
81+
ApiKey = "sk-Qa7GFtgCspCVfVGqKhm43QFmEB1FxsFvkXNysVycCuwDv2rz"
82+
BaseUrl = "https://self.domain/openai/v1"
83+
models = [
84+
"gpt-3.5-turbo",
85+
"gpt-4o-mini"
86+
]
87+
88+
def gentext():
89+
client = OpenAI(api_key=ApiKey, base_url=BaseUrl)
90+
model = random.choice(models)
91+
try:
92+
completion = client.chat.completions.create(
93+
model=model,
94+
messages=[
95+
{
96+
"role": "system",
97+
"content": "You are a smart and creative novelist."
98+
},
99+
{
100+
"role": "user",
101+
"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."
102+
}
103+
],
104+
top_p=0.7,
105+
temperature=0.7
106+
)
107+
text = completion.choices[0].message.content
108+
print(f"{model}{re.sub(r'\n+', '', text)}")
109+
except Exception as e:
110+
print(f"{model}{str(e)}\n")
111+
```
112+
113+
## Vercel Region List
114+
115+
https://vercel.com/docs/edge-network/regions#region-list

README_CN.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<div align="right">
2+
<strong>中文</strong> | <a href="README.md">English</a>
3+
</div>
4+
<div align="center">
5+
<h1>Serverless API Proxy</h1>
6+
<p>Serverless API Proxy: 基于Vercel Routes、Cloudflare Worker、Netlify Redirects的多API代理网关</p>
7+
</div>
8+
9+
## 支持服务
10+
11+
- openai
12+
- gemini
13+
- groq
14+
- claude
15+
- cohere
16+
- huggingface.co
17+
- Fireworks AI
18+
- 其他服务
19+
20+
## 怎么部署
21+
22+
### Vercel 部署
23+
24+
[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/lopins/serverless-api-proxy)
25+
26+
### Cloudflare 部署
27+
28+
[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/lopins/serverless-api-proxy)
29+
30+
### Netlify 部署
31+
32+
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/lopins/serverless-api-proxy)
33+
34+
## 如何使用
35+
36+
### API地址
37+
38+
```
39+
# openai
40+
https://self.domain/openai/
41+
42+
# gemini
43+
https://self.domain/gemini/
44+
45+
# groq
46+
https://self.domain/groq/
47+
48+
# claude
49+
https://self.domain/claude/
50+
51+
# cohere
52+
https://self.domain/cohere/
53+
54+
# huggingface
55+
https://self.domain/huggingface/
56+
57+
# fireworks
58+
https://self.domain/fireworks/
59+
```
60+
61+
| API | 官方API | 代理API | API使用 |
62+
| :---: | :--- | :--- | :--- |
63+
| OpenAI API | <https://api.openai.com/v1> | `/openai/v1` | `/openai/v1/chat/completions` |
64+
| Gemini API | <https://generativelanguage.googleapis.com/v1> | `/gemini/v1` | `/gemini/v1/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
65+
| Gemini API | <https://generativelanguage.googleapis.com/v1beta> | `/gemini/v1beta` | `/gemini/v1beta/models/gemini-pro:generateContent?key=AIzaSyBbBDDvGwJqKjsmE6CpNheqmzp30bz9saI` |
66+
| Groq API | <https://api.groq.com/groq/openai/v1> | `/groq/openai/v1` | `/groq/openai/v1/chat/completions` |
67+
| Claude API | <https://api.anthropic.com/v1> | `/claude/v1` | `/claude/v1/completions` |
68+
| Cohere API | <https://api.cohere.ai/v1> | `/cohere/v1` | `/cohere/v1/chat/completions` |
69+
| Huggingface API | <https://api-inference.huggingface.co> | `/huggingface` | `/huggingface/models/meta-llama/Llama-3.1-70B-Instruct/v1/chat/completions` |
70+
| Fireworks API | <https://api.fireworks.ai/v1> | `/fireworks/v1` | `/fireworks/v1/chat/completions` |
71+
72+
### API使用
73+
74+
``` python
75+
import random
76+
import re
77+
78+
from openai import OpenAI
79+
80+
ApiKey = "sk-Qa7GFtgCspCVfVGqKhm43QFmEB1FxsFvkXNysVycCuwDv2rz"
81+
BaseUrl = "https://self.domain/openai/v1"
82+
models = [
83+
"gpt-3.5-turbo",
84+
"gpt-4o-mini"
85+
]
86+
87+
def gentext():
88+
client = OpenAI(api_key=ApiKey, base_url=BaseUrl)
89+
model = random.choice(models)
90+
try:
91+
completion = client.chat.completions.create(
92+
model=model,
93+
messages=[
94+
{
95+
"role": "system",
96+
"content": "你是一个聪明且富有创造力的小说作家。"
97+
},
98+
{
99+
"role": "user",
100+
"content": "请你作为童话故事大王,写一篇短篇童话故事,故事的主题是要永远保持一颗善良的心,要能够激发儿童的学习兴趣和想象力,同时也能够帮助儿童更好地理解和接受故事中所蕴含的道理和价值观。只输出故事内容不需要标题和其他。"
101+
}
102+
],
103+
top_p=0.7,
104+
temperature=0.7
105+
)
106+
text = completion.choices[0].message.content
107+
print(f"{model}{re.sub(r'\n+', '', text)}")
108+
except Exception as e:
109+
print(f"{model}{str(e)}\n")
110+
```
111+
112+
## Vercel区域
113+
114+
https://vercel.com/docs/edge-network/regions#region-list

netlify.toml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[build]
2+
publish = "public"
3+
command = "npm run build"
4+
5+
[[redirects]]
6+
from = "/discord/*"
7+
to = "https://discord.com/api/:splat"
8+
status = 200
9+
10+
[[redirects]]
11+
from = "/telegram/*"
12+
to = "https://api.telegram.org/:splat"
13+
status = 200
14+
15+
[[redirects]]
16+
from = "/openai/*"
17+
to = "https://api.openai.com/:splat"
18+
status = 200
19+
20+
[[redirects]]
21+
from = "/claude/*"
22+
to = "https://api.anthropic.com/:splat"
23+
status = 200
24+
25+
[[redirects]]
26+
from = "/gemini/*"
27+
to = "https://generativelanguage.googleapis.com/:splat"
28+
status = 200
29+
30+
[[redirects]]
31+
from = "/meta/*"
32+
to = "https://www.meta.ai/api/:splat"
33+
status = 200
34+
35+
[[redirects]]
36+
from = "/groq/*"
37+
to = "https://api.groq.com/:splat"
38+
status = 200
39+
40+
[[redirects]]
41+
from = "/x/*"
42+
to = "https://api.x.ai/:splat"
43+
status = 200
44+
45+
[[redirects]]
46+
from = "/cohere/*"
47+
to = "https://api.cohere.ai/:splat"
48+
status = 200
49+
50+
[[redirects]]
51+
from = "/huggingface/*"
52+
to = "https://api-inference.huggingface.co/:splat"
53+
status = 200
54+
55+
[[redirects]]
56+
from = "/together/*"
57+
to = "https://api.together.xyz/:splat"
58+
status = 200
59+
60+
[[redirects]]
61+
from = "/novita/*"
62+
to = "https://api.novita.ai/:splat"
63+
status = 200
64+
65+
[[redirects]]
66+
from = "/portkey/*"
67+
to = "https://api.portkey.ai/:splat"
68+
status = 200
69+
70+
[[redirects]]
71+
from = "/fireworks/*"
72+
to = "https://api.fireworks.ai/:splat"
73+
status = 200
74+
75+
[[redirects]]
76+
from = "/openrouter/*"
77+
to = "https://openrouter.ai/api/:splat"
78+
status = 200

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "serverless-api-proxy",
3+
"version": "1.0.0",
4+
"description": "Multi-API Proxy Gateway Based on Vercel Routes, Cloudflare Workers, and Netlify Redirects",
5+
"scripts": {
6+
"build": "echo 'No build step required.'"
7+
},
8+
"author": "https://github.com/lopins",
9+
"license": "MIT"
10+
}

public/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset="utf-8" />
4+
<title>Vercel API Proxy - Multi-API proxy gateway based on vercel routes</title>
5+
<meta name="robots" content="none"/>
6+
<link rel="shortcut icon" href="https://lobechat.com/favicon-32x32.ico?v=1" />
7+
</head>
8+
<body>
9+
service is running!
10+
</body>
11+
12+
</html>

public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /

0 commit comments

Comments
 (0)