https://github.com/chen86860/vercel-openai-proxy
Use Vercel Edge Functions to proxy requests to OpenAI services, addressing accessibility issues in regions where OpenAI is unavailable
https://github.com/chen86860/vercel-openai-proxy
openai proxy-server vercel
Last synced: 4 months ago
JSON representation
Use Vercel Edge Functions to proxy requests to OpenAI services, addressing accessibility issues in regions where OpenAI is unavailable
- Host: GitHub
- URL: https://github.com/chen86860/vercel-openai-proxy
- Owner: chen86860
- License: mit
- Created: 2024-08-30T01:54:10.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-31T02:22:16.000Z (over 1 year ago)
- Last Synced: 2025-10-10T15:49:26.222Z (9 months ago)
- Topics: openai, proxy-server, vercel
- Language: TypeScript
- Homepage:
- Size: 96.7 KB
- Stars: 2
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
English | [简体中文](README_ZH.md)
# Vercel Region OpenAI Proxy
Use Vercel Edge Functions to proxy requests to OpenAI services, addressing accessibility issues in regions where OpenAI is unavailable (e.g., Hong Kong, Mainland China).
You can also refer to this example to request other proxy services by specifying the region, not limited to OpenAI.
## Deployment
Register a Vercel account, then click the button below to deploy this project to Vercel.
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fchen86860%2Fvercel-openai-proxy&project-name=vercel-openai-proxy)
## Usage
After deployment, you will receive a URL like `https://your-project-name-xxxx.vercel.app`. The proxy request URL should be `https://your-project-name-xxxx.vercel.app/openai/`, and you can use this URL to proxy requests to OpenAI services.
### Example
Using the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to make a request:
```js
// request openai api, just replace https://api.openai.com to https://your-project-name-xxxx.vercel.app/openai/
const response = await fetch("https://your-project-name-xxxx.vercel.app/openai/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer OPENAI_KEY_HERE",
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: "Hello, world!" }],
}),
});
```
Using the [openai](https://www.npmjs.com/package/openai) library to make a request:
```js
const openai = new OpenAI({
apiKey: "OPENAI_KEY_HERE",
// Just set the baseURL
baseURL: "https://your-project-name-xxxx.vercel.app/openai/v1/",
});
```
## Configuration
By default, unsupported regions have been excluded. If you need to add or modify regions, you can do so in `src/app/openai/[...path]/route.ts`.
## License
[MIT](./LICENSE)