Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: restrict ai edge function regions (#29085)

Charis534a2484851e
diff --git a/apps/docs/pages/api/ai/docs.ts b/apps/docs/pages/api/ai/docs.ts
index 40d35d01105..b2e45876a61 100644
--- a/apps/docs/pages/api/ai/docs.ts
+++ b/apps/docs/pages/api/ai/docs.ts
@@ -3,7 +3,34 @@ import { ApplicationError, UserError, clippy } from 'ai-commands/edge'
import { NextRequest } from 'next/server'
import OpenAI from 'openai'
-export const runtime = 'edge'
+export const config = {
+ runtime: 'edge',
+ /* To avoid OpenAI errors, restrict to the Vercel Edge Function regions that
+ overlap with the OpenAI API regions.
+
+ Reference for Vercel regions: https://vercel.com/docs/edge-network/regions#region-list
+ Reference for OpenAI regions: https://help.openai.com/en/articles/5347006-openai-api-supported-countries-and-territories
+ */
+ regions: [
+ 'arn1',
+ 'bom1',
+ 'cdg1',
+ 'cle1',
+ 'cpt1',
+ 'dub1',
+ 'fra1',
+ 'gru1',
+ 'hnd1',
+ 'iad1',
+ 'icn1',
+ 'kix1',
+ 'lhr1',
+ 'pdx1',
+ 'sfo1',
+ 'sin1',
+ 'syd1',
+ ],
+}
const openAiKey = process.env.OPENAI_API_KEY
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL as string
diff --git a/apps/studio/pages/api/ai/docs.ts b/apps/studio/pages/api/ai/docs.ts
index 40d35d01105..b2e45876a61 100644
--- a/apps/studio/pages/api/ai/docs.ts
+++ b/apps/studio/pages/api/ai/docs.ts
@@ -3,7 +3,34 @@ import { ApplicationError, UserError, clippy } from 'ai-commands/edge'
import { NextRequest } from 'next/server'
import OpenAI from 'openai'
-export const runtime = 'edge'
+export const config = {
+ runtime: 'edge',
+ /* To avoid OpenAI errors, restrict to the Vercel Edge Function regions that
+ overlap with the OpenAI API regions.
+
+ Reference for Vercel regions: https://vercel.com/docs/edge-network/regions#region-list
+ Reference for OpenAI regions: https://help.openai.com/en/articles/5347006-openai-api-supported-countries-and-territories
+ */
+ regions: [
+ 'arn1',
+ 'bom1',
+ 'cdg1',
+ 'cle1',
+ 'cpt1',
+ 'dub1',
+ 'fra1',
+ 'gru1',
+ 'hnd1',
+ 'iad1',
+ 'icn1',
+ 'kix1',
+ 'lhr1',
+ 'pdx1',
+ 'sfo1',
+ 'sin1',
+ 'syd1',
+ ],
+}
const openAiKey = process.env.OPENAI_API_KEY
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL as string
diff --git a/apps/www/pages/api/ai/docs.ts b/apps/www/pages/api/ai/docs.ts
index 40d35d01105..b2e45876a61 100644
--- a/apps/www/pages/api/ai/docs.ts
+++ b/apps/www/pages/api/ai/docs.ts
@@ -3,7 +3,34 @@ import { ApplicationError, UserError, clippy } from 'ai-commands/edge'
import { NextRequest } from 'next/server'
import OpenAI from 'openai'
-export const runtime = 'edge'
+export const config = {
+ runtime: 'edge',
+ /* To avoid OpenAI errors, restrict to the Vercel Edge Function regions that
+ overlap with the OpenAI API regions.
+
+ Reference for Vercel regions: https://vercel.com/docs/edge-network/regions#region-list
+ Reference for OpenAI regions: https://help.openai.com/en/articles/5347006-openai-api-supported-countries-and-territories
+ */
+ regions: [
+ 'arn1',
+ 'bom1',
+ 'cdg1',
+ 'cle1',
+ 'cpt1',
+ 'dub1',
+ 'fra1',
+ 'gru1',
+ 'hnd1',
+ 'iad1',
+ 'icn1',
+ 'kix1',
+ 'lhr1',
+ 'pdx1',
+ 'sfo1',
+ 'sin1',
+ 'syd1',
+ ],
+}
const openAiKey = process.env.OPENAI_API_KEY
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL as string