Skip to content

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

Dynamic model setting (#37095)

Saxon Fletcher834dcb5a29c8
diff --git a/apps/studio/lib/ai/model.ts b/apps/studio/lib/ai/model.ts
index ede4906ba93..e093e4702e9 100644
--- a/apps/studio/lib/ai/model.ts
+++ b/apps/studio/lib/ai/model.ts
@@ -14,8 +14,10 @@ export const regionMap = {
eu: 'eu',
}
-const SONNET_MODEL = 'anthropic.claude-3-7-sonnet-20250219-v1:0'
-const HAIKU_MODEL = 'anthropic.claude-3-haiku-20240307-v1:0'
+// Default behaviour here is to be throttled (e.g if this env var is not available, IS_THROTTLED should be true, unless specified 'false')
+const IS_THROTTLED = process.env.IS_THROTTLED !== 'false'
+const PRO_MODEL = process.env.AI_PRO_MODEL ?? 'anthropic.claude-3-7-sonnet-20250219-v1:0'
+const NORMAL_MODEL = process.env.AI_NORMAL_MODEL ?? 'anthropic.claude-3-5-haiku-20241022-v1:0'
const OPENAI_MODEL = 'gpt-4.1-2025-04-14'
export type ModelSuccess = {
@@ -47,7 +49,7 @@ export async function getModel(routingKey?: string, isLimited?: boolean): Promis
// Select the Bedrock region based on the routing key
const bedrockRegion: BedrockRegion = routingKey ? await selectBedrockRegion(routingKey) : 'us1'
const bedrock = bedrockForRegion(bedrockRegion)
- const model = HAIKU_MODEL
+ const model = IS_THROTTLED || isLimited ? NORMAL_MODEL : PRO_MODEL
const modelName = `${regionMap[bedrockRegion]}.${model}`
return {
diff --git a/turbo.json b/turbo.json
index b1484553135..fe75e665de7 100644
--- a/turbo.json
+++ b/turbo.json
@@ -96,7 +96,10 @@
"FORCE_ASSET_CDN",
"ASSET_CDN_S3_ENDPOINT",
"SITE_NAME",
- "VERCEL_URL"
+ "VERCEL_URL",
+ "IS_THROTTLED",
+ "AI_PRO_MODEL",
+ "AI_NORMAL_MODEL"
],
"passThroughEnv": ["CURRENT_CLI_VERSION"],
"outputs": [".next/**", "!.next/cache/**"]