{"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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/nvidiaNim/index.js#L139-L175","documentation":"Unlike the other providers' isValidChatCompletionModel catalog check, NvidiaNimLLM.getChatCompletion simply does `if (!this.model)` — a presence check only. isValidChatCompletionModel for NIM is a stub returning true. this.model = modelPreference || process.env.NVIDIA_NIM_LLM_MODEL_PREF with NO default, so the throw fires when neither is provided. The message ('not valid or defined') is accurate: it's really 'not defined'.","triggerScenarios":"Calling getChatCompletion when neither the constructor's modelPreference arg nor NVIDIA_NIM_LLM_MODEL_PREF env var was set — this.model is undefined/empty.","commonSituations":"Self-hosted NIM selected without specifying which served model to target; env var typo; caller (provider factory) not passing modelPreference; NIM endpoint serves multiple models and none was chosen.","solutions":["Set NVIDIA_NIM_LLM_MODEL_PREF to a model id the NIM endpoint actually serves.","Or pass modelPreference when constructing NvidiaNimLLM.","Confirm the model is loaded/available on the NIM endpoint (GET /v1/models).","Check for typos in the env var name."],"exampleFix":"// before\n// NVIDIA_NIM_LLM_MODEL_PREF unset, no modelPreference passed -> !this.model -> throws\n\n// after\nNVIDIA_NIM_LLM_MODEL_PREF=meta/llama-3.1-8b-instruct","handlingStrategy":"validation","validationCode":"// Ensure a model is configured before calling getChatCompletion\nif (!process.env.NVIDIA_NIM_LLM_MODEL_PREF && !modelPreference) {\n  throw new Error('No NIM model selected — set NVIDIA_NIM_LLM_MODEL_PREF to a model the endpoint serves.');\n}\n// Optionally confirm the endpoint actually serves it\nconst served = await fetch(`${basePath}/models`).then(r => r.json());\nconst ids = served.data?.map(m => m.id) ?? [];\nif (!ids.includes(process.env.NVIDIA_NIM_LLM_MODEL_PREF)) {\n  throw new Error(`NIM endpoint does not serve '${process.env.NVIDIA_NIM_LLM_MODEL_PREF}'. Available: ${ids.join(', ')}`);\n}","typeGuard":"function hasNimModel(model) {\n  return typeof model === 'string' && model.trim().length > 0;\n}","tryCatchPattern":"try {\n  await llm.getChatCompletion(messages, { temperature });\n} catch (e) {\n  if (/NVIDIA NIM chat:.*not valid or defined/i.test(e.message)) {\n    // model undefined — set NVIDIA_NIM_LLM_MODEL_PREF or pass modelPreference\n  }\n}","preventionTips":["NIM has no default model — always set NVIDIA_NIM_LLM_MODEL_PREF.","Cross-check the id against GET /v1/models on the endpoint.","Note isValidChatCompletionModel is a stub for NIM; the only real guard is presence."],"tags":["nvidia-nim","model-validation","configuration","self-hosted"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}