{"record":{"id":"cd8ce71f53183558","repo":"Mintplex-Labs/anything-llm","slug":"deepseek-chat-this-model-is-not-valid-for-chat","errorCode":null,"errorMessage":"DeepSeek chat: ${this.model} is not valid for chat completion!","messagePattern":"DeepSeek chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/deepseek/index.js","lineNumber":99,"sourceCode":"\n  /**\n   * Parses and prepends reasoning from the response and returns the full text response.\n   * @param {Object} response\n   * @returns {string}\n   */\n  #parseReasoningFromResponse({ message }) {\n    let textResponse = message?.content;\n    if (\n      !!message?.reasoning_content &&\n      message.reasoning_content.trim().length > 0\n    )\n      textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;\n    return textResponse;\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `DeepSeek chat: ${this.model} is not valid for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions\n        .create({\n          model: this.model,\n          messages,\n          temperature,\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (\n      !result?.output?.hasOwnProperty(\"choices\") ||\n      result?.output?.choices?.length === 0","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/deepseek/index.js#L81-L117","documentation":"Thrown by getChatCompletion when isValidChatCompletionModel returns false. Unlike cache-based providers, DeepSeek's validator calls this.openai.models.list() and checks whether any returned model id matches this.model. If the DeepSeek API is unreachable, returns an empty list (the .catch fallback yields {data:[]}), or the model id is not in the live list, the guard rejects the call.","triggerScenarios":"DEEPSEEK_MODEL_PREF is set to a model id not returned by GET /v1/models (e.g. a typo or a model DeepSeek retired); the models.list() call fails due to network/auth issues, causing the catch to return an empty data array, which makes every model id fail validation.","commonSituations":"DeepSeek deprecating 'deepseek-coder' or similar legacy ids; transient network failure to api.deepseek.com during the models.list() call masking a valid model as invalid; an expired API key causing models.list() to 401 and silently return an empty list.","solutions":["Verify the model id against the live GET https://api.deepseek.com/v1/models response using the same API key.","Check that DEEPSEEK_API_KEY is valid — if it is expired, models.list() silently returns empty and every model fails.","Default to 'deepseek-chat' (the constructor fallback) if unsure.","If the API is temporarily unreachable, retry — the validation is network-dependent and will pass once connectivity is restored."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-validate the model against DeepSeek's live list\nconst models = await fetch('https://api.deepseek.com/v1/models', {\n  headers: { Authorization: `Bearer ${process.env.DEEPSEEK_API_KEY}` },\n}).then(r => r.json()).catch(() => ({ data: [] }));\nconst isValid = models.data?.some(m => m.id === modelId);\nif (!isValid) throw new Error(`Model ${modelId} not found in DeepSeek /v1/models`);","typeGuard":null,"tryCatchPattern":"try {\n  return await deepseek.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/is not valid for chat completion/i.test(e.message))\n    throw new Error(`DeepSeek model \"${modelId}\" invalid or API unreachable. Check DEEPSEEK_API_KEY and model id.`);\n  throw e;\n}","preventionTips":["Be aware isValidChatCompletionModel makes a network call — a transient failure or expired key makes every model appear invalid.","Default to 'deepseek-chat' to minimize invalid-model risk.","Validate the API key independently before relying on model-list validation."],"tags":["deepseek","invalid-model","chat-completion","model-validation","network-dependent"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}