{"record":{"id":"14ab41d2c114019a","repo":"Mintplex-Labs/anything-llm","slug":"localai-chat-this-model-is-not-valid-for-chat-14ab41","errorCode":null,"errorMessage":"LocalAi chat: ${this.model} is not valid for chat completion!","messagePattern":"LocalAi chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/localAi/index.js","lineNumber":158,"sourceCode":"\n    return {\n      textResponse: result.output.choices[0].message.content,\n      metrics: {\n        prompt_tokens: promptTokens,\n        completion_tokens: completionTokens,\n        total_tokens: promptTokens + completionTokens,\n        outputTps: completionTokens / result.duration,\n        duration: result.duration,\n        model: this.model,\n        provider: this.className,\n        timestamp: new Date(),\n      },\n    };\n  }\n\n  async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `LocalAi chat: ${this.model} is not valid for chat completion!`\n      );\n\n    const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({\n      func: this.openai.chat.completions.create({\n        model: this.model,\n        stream: true,\n        messages,\n        temperature,\n      }),\n      messages,\n      runPromptTokenCalculation: true,\n      modelTag: this.model,\n      provider: this.className,\n    });\n    return measuredStreamRequest;\n  }\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/localAi/index.js#L140-L176","documentation":"Thrown by LocalAiLLM.streamGetChatCompletion when `isValidChatCompletionModel(this.model)` returns false. Like error 238, this is dead code because isValidChatCompletionModel unconditionally returns true. Note the casing inconsistency: the message says 'LocalAi chat' (mixed case) while the getChatCompletion variant (error 238) says 'LocalAI chat' (all caps) — a minor string mismatch that makes log-grepping inconsistent.","triggerScenarios":"Unreachable in normal operation. The guard `if (!(await this.isValidChatCompletionModel(this.model)))` always evaluates to false because the method returns true. Would only fire if the class or a subclass overrode isValidChatCompletionModel with validation that rejects the model.","commonSituations":"Practically never seen. The streaming path is the primary chat code path in AnythingLLM. If a future change adds real model validation, this guard would become active. The casing inconsistency in the message is a latent bug for log-based error searching.","solutions":["This error should not occur — if encountered, investigate custom subclasses or monkey-patching of isValidChatCompletionModel.","Fix the message casing inconsistency: change 'LocalAi chat' to 'LocalAI chat' for consistency with the getChatCompletion variant (error 238).","If adding real model validation, override isValidChatCompletionModel to query the LocalAI server's model list."],"exampleFix":"// before — inconsistent casing between getChatCompletion and streamGetChatCompletion\nthrow new Error(\n  `LocalAi chat: ${this.model} is not valid for chat completion!`\n);\n\n// after — consistent casing\nthrow new Error(\n  `LocalAI chat: ${this.model} is not valid for chat completion!`\n);","handlingStrategy":"validation","validationCode":"// This error is currently unreachable because isValidChatCompletionModel always returns true.\n// If you add real validation, check the model before calling streamGetChatCompletion:\nasync function validateLocalAIModel(provider) {\n  const res = await fetch(`${process.env.LOCAL_AI_BASE_PATH}/models`);\n  const data = await res.json();\n  const available = (data.data || []).map((m) => m.id);\n  if (!available.includes(provider.model)) {\n    throw new Error(`Model \"${provider.model}\" not available on LocalAI server.`);\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"// Currently unnecessary since the guard is dead code, but for future-proofing:\ntry {\n  const stream = await localaiProvider.streamGetChatCompletion(messages, { temperature: 0.7 });\n} catch (e) {\n  // Note: message says 'LocalAi' (mixed case), not 'LocalAI'\n  if (e.message.includes('not valid for chat completion')) {\n    console.error('LocalAI model validation failed for:', localaiProvider.model);\n  } else {\n    throw e;\n  }\n}","preventionTips":["This error is dead code in current implementation — no prevention needed.","If adding real model validation, override isValidChatCompletionModel to check the server's model list.","Fix the message casing inconsistency ('LocalAi' vs 'LocalAI') so log-based error searching works reliably."],"tags":["localai","model-validation","dead-code","runtime","streaming","unreachable","string-inconsistency"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}