{"record":{"id":"53fd485b67765b8c","repo":"Mintplex-Labs/anything-llm","slug":"nvidia-nim-chat-this-model-is-not-valid-or-def","errorCode":null,"errorMessage":"NVIDIA NIM chat: ${this.model} is not valid or defined model for chat completion!","messagePattern":"NVIDIA NIM chat: (.+?) is not valid or defined model for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/nvidiaNim/index.js","lineNumber":157,"sourceCode":"    attachments = [],\n  }) {\n    const prompt = {\n      role: \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [\n      prompt,\n      ...formatChatHistory(chatHistory, this.#generateContent),\n      {\n        role: \"user\",\n        content: this.#generateContent({ userPrompt, attachments }),\n      },\n    ];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!this.model)\n      throw new Error(\n        `NVIDIA NIM chat: ${this.model} is not valid or defined model for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.nvidiaNim.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":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/nvidiaNim/index.js#L139-L175","documentation":"Unlike most providers, NvidiaNimLLM has no hardcoded default model: this.model = modelPreference || process.env.NVIDIA_NIM_LLM_MODEL_PREF. getChatCompletion checks `if (!this.model)` and throws this error before making any request when both the workspace-selected model and the env default are absent.","triggerScenarios":"NVIDIA NIM selected as the provider but no model chosen in the workspace chat settings and NVIDIA_NIM_LLM_MODEL_PREF not set; the selected model string is empty (cleared in UI or saved as ''); calling getChatCompletion programmatically without passing modelPreference.","commonSituations":"Fresh NIM setup where the model dropdown was skipped; .env missing the model preference; UI state cleared after reconfiguring the provider; programmatic use that assumes a default model exists.","solutions":["Pick a model in the workspace chat settings (this supplies modelPreference at construction)","Or set NVIDIA_NIM_LLM_MODEL_PREF in .env to an id the NIM server actually hosts (check: curl $NVIDIA_NIM_LLM_BASE_PATH/models)","Restart the server after setting the env default","Verify the stored workspace chat model is a non-empty string"],"exampleFix":"# before\n# (no model selected; NVIDIA_NIM_LLM_MODEL_PREF unset)\n# after\nNVIDIA_NIM_LLM_MODEL_PREF=meta/llama-3.1-8b-instruct","handlingStrategy":"validation","validationCode":"const model = modelPreference || process.env.NVIDIA_NIM_LLM_MODEL_PREF;\nif (!model)\n  throw new Error('No NVIDIA NIM model selected — choose one in workspace settings or set NVIDIA_NIM_LLM_MODEL_PREF');\nconst llm = new NvidiaNimLLM(embedder, model);","typeGuard":null,"tryCatchPattern":"try {\n  await llm.getChatCompletion(messages);\n} catch (e) {\n  if (/NVIDIA NIM chat: .* is not valid or defined/.test(e.message)) {\n    // config error: select a model or set NVIDIA_NIM_LLM_MODEL_PREF, then retry\n  }\n  throw e;\n}","preventionTips":["Always select a model in workspace chat settings when using NIM (there is no built-in default)","Set NVIDIA_NIM_LLM_MODEL_PREF as a deployment-wide fallback","Verify the saved workspace model is a non-empty string before instantiating the provider","Cross-check the id against GET $NVIDIA_NIM_LLM_BASE_PATH/models"],"tags":["nvidia-nim","anythingllm","model-selection","configuration","chat-completion"],"backgroundTag":"missing-model-id","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}