Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude Hong Kong Region in Vercel Edge Functions for OpenAI Proxy Support #27

Open
huwan opened this issue Nov 11, 2024 · 4 comments
Open

Comments

@huwan
Copy link

huwan commented Nov 11, 2024

When deploying on Vercel and accessing the proxy API from Hong Kong, users encounter the "OpenAI proxy country, region, or territory not supported" error. This issue arises because Vercel's Edge Functions default to executing in the region closest to the incoming request, which is hkg1 for Hong Kong.

To resolve this, the Vercel edge network region hkg1 should be explicitly excluded by configuring the function to use only supported regions. This can be done by modifying the pages/api/proxy.ts file in the repository to include a list of supported regions.

export const config = {
runtime: 'edge'
};

regions: ['arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1'],

References:

  1. Configuring Regions in Vercel Functions
  2. Vercel Edge Network Regions
@WongLoki
Copy link
Contributor

Hi Hu Wan,

Thanks so much for reaching out!

Just wanted to explain the situation - while your code looks perfect, and you're absolutely right that deployment would go to HK servers for users in the Asia region, we've run into a small snag. The screening feature you're trying to use is actually part of Vercel's Enterprise tier, which is meant for larger organizations (they typically spend around $50k-200k USD per month 😅). Since you're not on an Enterprise account, the deployment would unfortunately fail.
While I can't merge the code this time, I really appreciate you taking the time to contribute! Feel free to bounce any other ideas off me anytime.

You can find it here:

  1. https://vercel.com/docs/edge-network/regions
  2. https://vercel.com/docs/functions/configuring-functions/region#available-configurations

Looking forward to our next chat!

Best
Loki

@huwan
Copy link
Author

huwan commented Nov 11, 2024

Thank you for the detailed explanation. I added a single iad1 region to specify the edge region with my Vercel hobby plan, and it seems to work when accessing the proxy API URL in HK. Hopefully, we can find a better and more affordable solution later. Thanks again.

@WongLoki
Copy link
Contributor

Hi Hu Wan,

Great news! 🎉

I did some testing on your idea and found something interesting - turns out we can actually specify a single region without an Enterprise account! The limitation only kicks in when we try to deploy to multiple regions.
I've gone ahead and updated the code using vercel.json configuration, keeping things clean without touching the main files. This approach should work perfectly for what we need.

Thanks again for bringing this to our attention - it helped us find a better way forward.

Best,
Loki

@huwan
Copy link
Author

huwan commented Nov 11, 2024

According to Vercel's documentation on configuring regions for functions, the vercel.json file is used for Serverless Functions. For Edge Functions, we might need to specify a regions key within a config object in pages/api/proxy.ts to set the execution region for proxy functions, though this could cause issues when deploying on different platforms. I'm not sure. Looking forward to your test results and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants