{"record":{"id":"4ab7b73b2109dcc4","repo":"DayuanJiang/next-ai-draw-io","slug":"model-id-is-required-when-using-custom-ai-provider","errorCode":null,"errorMessage":"Model ID is required when using custom AI provider. Please specify a model in Settings.","messagePattern":"Model ID is required when using custom AI provider\\. Please specify a model in Settings\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/ai-providers.ts","lineNumber":746,"sourceCode":"                `Please provide your own API key in Settings.`,\n        )\n    }\n\n    // Check if client is providing their own provider override\n    const isClientOverride = !!(\n        overrides?.provider &&\n        (overrides?.apiKey ||\n            (overrides?.provider === \"vertexai\" && overrides?.vertexApiKey))\n    )\n\n    // Use client override if provided, otherwise fall back to env vars.\n    // AI_MODEL may be comma-separated (multi-model fallback); pick the first.\n    const envModel = process.env.AI_MODEL?.split(\",\")[0]?.trim() || undefined\n    const modelId = overrides?.modelId || envModel\n\n    if (!modelId) {\n        if (isClientOverride) {\n            throw new Error(\n                `Model ID is required when using custom AI provider. Please specify a model in Settings.`,\n            )\n        }\n        throw new Error(\n            `AI_MODEL environment variable is required. Example: AI_MODEL=claude-sonnet-4-5`,\n        )\n    }\n\n    // Determine provider: client override > explicit config > auto-detect > error\n    let provider: ProviderName\n    if (overrides?.provider) {\n        // Validate client-provided provider\n        if (\n            !ALLOWED_CLIENT_PROVIDERS.includes(\n                overrides.provider as ProviderName,\n            )\n        ) {\n            throw new Error(","sourceCodeStart":728,"sourceCodeEnd":764,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/ai-providers.ts#L728-L764","documentation":"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.","triggerScenarios":"User configures a custom provider/baseUrl in the UI but leaves the model field empty while AI_MODEL is unset in the environment.","commonSituations":"Setting up BYO-provider in Settings and forgetting the model name, or AI_MODEL removed from .env.local after switching to UI config.","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"],"exampleFix":"// before\noverrides = { provider: 'anthropic' } // no modelId\n\n// after\noverrides = { provider: 'anthropic', modelId: 'claude-sonnet-4-5' }","handlingStrategy":"validation","validationCode":"const hasModel = !!overrides?.modelId || !!process.env.AI_MODEL\nif (!hasModel) disableSubmit('Model ID required')","typeGuard":"const hasModelId = (o?: { modelId?: string }): boolean =>\n  !!o?.modelId || !!process.env.AI_MODEL","tryCatchPattern":"try { getAIModel(overrides) } catch (e) { if ((e as Error).message.includes('Model ID is required')) focusModelFieldInSettings() }","preventionTips":["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"],"tags":["provider","model-id","validation","settings"],"backgroundTag":"missing-configuration-value","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}