DayuanJiang/next-ai-draw-io · error · Error
Model ID is required when using custom AI provider. Please…
Error message
Model ID is required when using custom AI provider. Please specify a model in Settings.
What it means
When the client supplies its own provider override (Settings custom AI config) but no modelId and no AI_MODEL env fallback exists, getAIModel throws asking for a model in Settings.
Solutions
- Enter a model ID in Settings (e.g. claude-sonnet-4-5) for the custom provider
- Alternatively set AI_MODEL in .env.local as a server-side fallback
- Ensure the model name matches what the chosen provider exposes
Example fix
// before
overrides = { provider: 'anthropic' } // no modelId
// after
overrides = { provider: 'anthropic', modelId: 'claude-sonnet-4-5' } Defensive patterns
Strategy: validation
Validate before calling
const hasModel = !!overrides?.modelId || !!process.env.AI_MODEL
if (!hasModel) disableSubmit('Model ID required') Type guard
const hasModelId = (o?: { modelId?: string }): boolean =>
!!o?.modelId || !!process.env.AI_MODEL Try / catch
try { getAIModel(overrides) } catch (e) { if ((e as Error).message.includes('Model ID is required')) focusModelFieldInSettings() } Prevention
- Require the model field in the custom-provider settings form
- Keep an AI_MODEL fallback in server env
- Validate overrides completeness client-side before calling the API
When it happens
Trigger: User configures a custom provider/baseUrl in the UI but leaves the model field empty while AI_MODEL is unset in the environment.
Common situations: Setting up BYO-provider in Settings and forgetting the model name, or AI_MODEL removed from .env.local after switching to UI config.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- addPageToDoc: opts.xml must be a bare
- At least one of [ ] environment variables is required for…
- GOOGLE_TOP_P must be a number between 0 and 1, got
- Invalid preset name
- ModelScope API error
AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27).
Data as JSON: /api/errors/4ab7b73b2109dcc4.
Report an issue: GitHub.
Appendix: source
Thrown at lib/ai-providers.ts:746
`Please provide your own API key in Settings.`,
)
}
// Check if client is providing their own provider override
const isClientOverride = !!(
overrides?.provider &&
(overrides?.apiKey ||
(overrides?.provider === "vertexai" && overrides?.vertexApiKey))
)
// Use client override if provided, otherwise fall back to env vars.
// AI_MODEL may be comma-separated (multi-model fallback); pick the first.
const envModel = process.env.AI_MODEL?.split(",")[0]?.trim() || undefined
const modelId = overrides?.modelId || envModel
if (!modelId) {
if (isClientOverride) {
throw new Error(
`Model ID is required when using custom AI provider. Please specify a model in Settings.`,
)
}
throw new Error(
`AI_MODEL environment variable is required. Example: AI_MODEL=claude-sonnet-4-5`,
)
}
// Determine provider: client override > explicit config > auto-detect > error
let provider: ProviderName
if (overrides?.provider) {
// Validate client-provided provider
if (
!ALLOWED_CLIENT_PROVIDERS.includes(
overrides.provider as ProviderName,
)
) {
throw new Error(View on GitHub (pinned to 155ef4f7ac)