Files
supabase/apps/studio/lib/ai/model.utils.ts
claude[bot]andClaude ea3a7743b1 feat(studio): default AI Assistant to GPT-6 Luna (AI-1245) (#50757)
<!-- ccr-slack-attribution -->
_Requested by **Saxon Fletcher** · [Slack
thread](https://supabase.slack.com/archives/C051L8U2EJF/p1790104861710199?thread_ts=1790104861.710199&cid=C051L8U2EJF)_

## Problem

**Before:** The Assistant's base model is `gpt-5.6-luna` at medium
reasoning effort.

**After:** The base model is `gpt-6-luna`, its direct successor, still
at medium effort. It costs half as much: $0.10/$0.50 per MTok against
$0.20/$1.20.

Resolves
[AI-1245](https://linear.app/supabase/issue/AI-1245/move-the-assistants-base-model-to-gpt-6-luna).

## Solution

This swaps `gpt-5.6-luna` for `gpt-6-luna` in
`apps/studio/lib/ai/model.utils.ts`: the model ID union, the
reasoning-support map, `ASSISTANT_MODELS`,
`DEFAULT_ASSISTANT_BASE_MODEL_ID`, and the OpenAI provider registry. The
old ID is removed, not kept next to the new one. A stored selection of
`gpt-5.6-luna` is no longer a known ID, so the client and `generate-v4`
both fall back to the new default. The eval cost table (AI-1242) and
eval experiments (AI-1243) are out of scope.

Source for the model ID and supported efforts (none/low/medium
default/high/xhigh/max): [OpenAI model docs: GPT-6
Luna](https://developers.openai.com/api/docs/models/gpt-6-luna).
`@ai-sdk/openai@4.0.41` types model IDs as a union plus `string & {}`,
so no SDK bump is needed.

## Review instructions

1. Check the diff in `model.utils.ts`. Say so if you'd rather keep
`gpt-5.6-luna` selectable as a fallback.
2. AI-1245 asks for the Assistant evals before shipping. Add the
`run-evals` label to run `braintrust-evals.yml` on this PR, or run `pnpm
--filter studio evals:run` locally. They have not been run yet because
they need OpenAI/Braintrust credentials.
3. Already run: studio `typecheck`, eslint + prettier on the changed
files, vitest for `lib/ai`, `pages/api/ai` and `state/ai-assistant` (264
passed), and `evals:preflight`.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] No docs topics changed

**AI disclosure:** Claude Code wrote this PR from start to finish. Saxon
Fletcher (@SaxonF) is the accountable human and must review it before
merge.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01W21zLTfzde6FFPyYGbGC6K


---
_Generated by [Claude
Code](https://claude.ai/code/session_01W21zLTfzde6FFPyYGbGC6K)_

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-23 10:03:27 +10:00

179 lines
5.7 KiB
TypeScript

export type ProviderName = 'bedrock' | 'openai'
export type BedrockModel = 'anthropic.claude-3-7-sonnet-20250219-v1:0' | 'openai.gpt-oss-120b-1:0'
export type OpenAIModelId = 'gpt-5.4-nano' | 'gpt-5.3-codex' | 'gpt-6-luna'
// Source: https://developers.openai.com/api/docs/guides/reasoning + per-model pages
export type ReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'
// Per-model reasoning effort compatibility.
// Sources: https://developers.openai.com/api/docs/models/gpt-5.4-nano
// https://developers.openai.com/api/docs/models/gpt-5.3-codex
// https://developers.openai.com/api/docs/models/gpt-6-luna
type ModelReasoningSupport = {
'gpt-5.4-nano': 'none' | 'low' | 'medium' | 'high' | 'xhigh'
'gpt-5.3-codex': 'low' | 'medium' | 'high' | 'xhigh'
'gpt-6-luna': 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max'
}
type ReasoningEffortFor<ModelId extends OpenAIModelId> = ModelId extends keyof ModelReasoningSupport
? ModelReasoningSupport[ModelId]
: never
/** Type-safe factory for configuring OpenAI models with compatible reasoning efforts. */
export function openaiModelEntry<
ModelId extends OpenAIModelId,
RequiresAdvance extends boolean = false,
>(config: {
id: ModelId
/** When true, the model requires the `assistant.advance_model` entitlement (paid plans). Defaults to false. */
requiresAdvanceModelEntitlement?: RequiresAdvance
/**
* When omitted, OpenAI applies its own default reasoning effort for the model,
* which may not be zero. Use an explicit level to control cost and latency.
*/
reasoningEffort?: ReasoningEffortFor<ModelId>
}): {
id: ModelId
requiresAdvanceModelEntitlement: RequiresAdvance
reasoningEffort?: ReasoningEffortFor<ModelId>
} {
return {
requiresAdvanceModelEntitlement: false as RequiresAdvance,
...config,
}
}
export type OpenAIModelEntry = ReturnType<typeof openaiModelEntry>
/** Default model entry for simple completion endpoints where latency is more important than reasoning. */
export const DEFAULT_COMPLETION_MODEL = openaiModelEntry({
id: 'gpt-5.4-nano',
reasoningEffort: 'none',
})
export const LOGS_REWRITE_MODEL = openaiModelEntry({
id: 'gpt-5.4-nano',
reasoningEffort: 'low',
})
// Single source of truth for all Assistant chat model variants and their reasoning levels.
// Models with requiresAdvanceModelEntitlement false are available to all users; true requires the assistant.advance_model entitlement.
export const ASSISTANT_MODELS = [
openaiModelEntry({
id: 'gpt-6-luna',
requiresAdvanceModelEntitlement: false,
reasoningEffort: 'medium',
}),
openaiModelEntry({
id: 'gpt-5.4-nano',
requiresAdvanceModelEntitlement: false,
reasoningEffort: 'low',
}),
openaiModelEntry({
id: 'gpt-5.3-codex',
requiresAdvanceModelEntitlement: true,
reasoningEffort: 'low',
}),
] as const
export type AssistantBaseModelId = Extract<
(typeof ASSISTANT_MODELS)[number],
{ requiresAdvanceModelEntitlement: false }
>['id']
export type AssistantModelId = (typeof ASSISTANT_MODELS)[number]['id']
const ASSISTANT_MODELS_MAP = Object.fromEntries(ASSISTANT_MODELS.map((m) => [m.id, m])) as Record<
AssistantModelId,
(typeof ASSISTANT_MODELS)[number]
>
export const DEFAULT_ASSISTANT_BASE_MODEL_ID = 'gpt-6-luna' satisfies AssistantBaseModelId
export const DEFAULT_ASSISTANT_ADVANCE_MODEL_ID = 'gpt-5.3-codex' satisfies AssistantModelId
export function defaultAssistantModelId(_hasAccessToAdvanceModel: boolean): AssistantModelId {
return DEFAULT_ASSISTANT_BASE_MODEL_ID
}
export function isKnownAssistantModelId(id: string): id is AssistantModelId {
return Object.hasOwn(ASSISTANT_MODELS_MAP, id)
}
export function isAssistantBaseModelId(id: string): id is AssistantBaseModelId {
return (
id in ASSISTANT_MODELS_MAP &&
!ASSISTANT_MODELS_MAP[id as AssistantModelId].requiresAdvanceModelEntitlement
)
}
export function isAdvanceOnlyModelId(id: string): boolean {
return (
id in ASSISTANT_MODELS_MAP &&
ASSISTANT_MODELS_MAP[id as AssistantModelId].requiresAdvanceModelEntitlement
)
}
export function getAssistantModelEntry(id: AssistantModelId): (typeof ASSISTANT_MODELS)[number] {
return ASSISTANT_MODELS_MAP[id]
}
export type Model = BedrockModel | OpenAIModelId
export type ProviderModelConfig = {
/** Optional providerOptions to attach to the system message for this model */
systemProviderOptions?: Record<string, any>
/** The default model for this provider (used when limited or no preferred specified) */
default: boolean
}
export type ProviderRegistry = {
bedrock: {
models: Record<BedrockModel, ProviderModelConfig>
providerOptions?: Record<string, any>
}
openai: {
models: Record<OpenAIModelId, ProviderModelConfig>
providerOptions?: Record<string, any>
}
}
export const PROVIDERS: ProviderRegistry = {
bedrock: {
models: {
'anthropic.claude-3-7-sonnet-20250219-v1:0': {
systemProviderOptions: {
bedrock: {
// Always cache the system prompt (must not contain dynamic content)
cachePoint: { type: 'default' },
},
},
default: false,
},
'openai.gpt-oss-120b-1:0': {
default: true,
},
},
},
openai: {
models: {
'gpt-6-luna': { default: false },
'gpt-5.3-codex': { default: false },
'gpt-5.4-nano': { default: true },
},
providerOptions: {
openai: {
store: false,
},
},
},
}
export function getDefaultModelForProvider(provider: ProviderName): Model | undefined {
const models = PROVIDERS[provider]?.models as Record<Model, ProviderModelConfig>
if (!models) return undefined
return Object.keys(models).find((id) => models[id as Model]?.default) as Model | undefined
}