Skip to content

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

fix(studio): do not ignore requested model if available in base (#51388)

Charisffe1ebc94020
diff --git a/apps/studio/lib/ai/generate-assistant-response.ts b/apps/studio/lib/ai/generate-assistant-response.ts
index 94086372e41..460633fd992 100644
--- a/apps/studio/lib/ai/generate-assistant-response.ts
+++ b/apps/studio/lib/ai/generate-assistant-response.ts
@@ -48,6 +48,7 @@ export async function generateAssistantResponse({
systemProviderOptions,
providerOptions,
requestedModel,
+ effectiveModel,
abortSignal,
timeout,
onSpanCreated,
@@ -71,6 +72,8 @@ export async function generateAssistantResponse({
includesLogsSnippets?: boolean
isExplorerEnabled?: boolean
requestedModel?: string
+ /** The model actually used after entitlement/throttle fallback. */
+ effectiveModel?: string
systemProviderOptions?: Record<string, any>
providerOptions?: Record<string, any>
abortSignal?: AbortSignal
@@ -196,6 +199,7 @@ export async function generateAssistantResponse({
planId,
isHighComplianceProject,
requestedModel,
+ effectiveModel,
gitBranch: process.env.VERCEL_GIT_COMMIT_REF,
environment: process.env.NEXT_PUBLIC_ENVIRONMENT,
},
diff --git a/apps/studio/pages/api/ai/sql/generate-v4.ts b/apps/studio/pages/api/ai/sql/generate-v4.ts
index 67209870b15..204e6ec0141 100644
--- a/apps/studio/pages/api/ai/sql/generate-v4.ts
+++ b/apps/studio/pages/api/ai/sql/generate-v4.ts
@@ -161,7 +161,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse, claims?: Jw
const envThrottled = process.env.IS_THROTTLED !== 'false'
let effectiveModel: AssistantModelId = requestedModel ?? DEFAULT_ASSISTANT_BASE_MODEL_ID
- if (!hasAccessToAdvanceModel || (envThrottled && !isAssistantBaseModelId(effectiveModel))) {
+ if (!isAssistantBaseModelId(effectiveModel) && (!hasAccessToAdvanceModel || envThrottled)) {
effectiveModel = DEFAULT_ASSISTANT_BASE_MODEL_ID
}
@@ -242,6 +242,7 @@ async function handlePost(req: NextApiRequest, res: NextApiResponse, claims?: Jw
includesLogsSnippets,
isExplorerEnabled: explorerEnabled,
requestedModel,
+ effectiveModel,
systemProviderOptions,
abortSignal: abortController.signal,
timeout: { totalMs: Math.max(0, ASSISTANT_TIMEOUT_MS - (Date.now() - requestStartedAt)) },