{"record":{"id":"bd061e74249f3c8a","repo":"janhq/jan","slug":"provider-configuration-is-required","errorCode":null,"errorMessage":"Provider configuration is required","messagePattern":"Provider configuration is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"web-app/src/lib/ai-model.ts","lineNumber":79,"sourceCode":"      },\n    }\n  },\n}\n\n/**\n * Creates a LanguageModel instance for the AI SDK based on the provider configuration.\n * This allows using Jan's model providers with the AI SDK's useChat hook.\n *\n * Note: This function is synchronous and does not load the model or construct URLs.\n * URL construction should happen elsewhere after the model is ready.\n */\nexport function createLanguageModel(\n  modelId: string,\n  provider?: ModelProvider | null,\n  providerObject?: ProviderObject | null\n): LanguageModel {\n  if (!provider) {\n    throw new Error('Provider configuration is required')\n  }\n\n  // For llamacpp provider, create a placeholder configuration\n  // The actual URL and authentication will be updated later when the model is loaded\n  if (provider.provider === 'llamacpp' && providerObject) {\n    // Create provider with placeholder connection info\n    const openAICompatible = createOpenAICompatible({\n      name: 'llamacpp',\n      baseURL: 'http://localhost:1337/v1', // Placeholder - will be updated when model loads\n      headers: {\n        Authorization: 'Bearer placeholder', // Placeholder - will be updated when model loads\n        Origin: 'tauri://localhost',\n      },\n      // Include usage data in streaming responses for token speed calculation\n      includeUsage: true,\n    })\n\n    // Use languageModel with custom config to include metadata extractor for timings","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/janhq/jan/blob/7205d770c1e097c3daf35a911176410e93bc5564/web-app/src/lib/ai-model.ts#L61-L97","documentation":"Thrown by createLanguageModel in ai-model.ts when the `provider` argument is null/undefined. A LanguageModel cannot be constructed without provider configuration (base URL, auth, provider type), so the factory rejects the call up front.","triggerScenarios":"Calling createLanguageModel(modelId, provider, providerObject) with provider === null or undefined — e.g. the provider record was not loaded from settings, was deleted, or the caller passed a lookup result that missed.","commonSituations":"Referring to a provider that no longer exists in settings; calling the factory before providers are fetched; a typo in the provider lookup key; chat initiated with a model whose provider entry was removed.","solutions":["Ensure the provider is loaded/resolved before creating the language model (await the providers list)","Verify the model's provider reference points to an existing configured provider","Re-add the missing provider in Settings > Providers","Guard the call site: skip or surface an error when provider is null instead of calling the factory"],"exampleFix":"// before\nconst model = createLanguageModel(modelId, provider, providerObject)\n// after\nif (!provider) {\n  throw new Error(`Provider for model ${modelId} is not configured. Add it in Settings > Providers.`)\n}\nconst model = createLanguageModel(modelId, provider, providerObject)","handlingStrategy":"validation","validationCode":"const providers = await getProviders()\nconst resolved = providers.find((p) => p.provider === model.provider)\nif (!resolved) throw new Error(`Provider \"${model.provider}\" is not configured. Add it in Settings > Providers.`)","typeGuard":"const isProviderConfigured = (p: ModelProvider | null | undefined): p is ModelProvider =>\n  !!p && typeof p.provider === 'string' && p.provider.length > 0","tryCatchPattern":"try {\n  const model = createLanguageModel(modelId, provider, providerObject)\n} catch (e) {\n  if (e.message === 'Provider configuration is required') {\n    openProviderSettings(modelId)\n  }\n}","preventionTips":["Load and cache the providers list before creating models","Validate a model's provider reference at chat start","Re-add providers after settings resets or migrations","Handle provider deletion cascades (remove orphan models)"],"tags":["configuration","provider","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"7205d770c1e097c3daf35a911176410e93bc5564","analyzedAt":"2026-09-17T14:27:30.100Z","contentChangedAt":"2026-09-17T14:27:30.100Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}