Herm-Studio / StakeVladDracula

StakeVladDracula pierces all.
https://hermchats.com/
MIT License
445 stars 90 forks source link

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

Open huwan opened 1 week ago

huwan commented 1 week ago

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.

https://github.com/Herm-Studio/StakeVladDracula/blob/44295c9c5c64657e301633958c454b30d6dae044/pages/api/proxy.ts#L3-L5

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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.