{"record":{"id":"a8ceeb62b9ee349e","repo":"Mintplex-Labs/anything-llm","slug":"no-nvidia-nim-token-context-limit-was-set","errorCode":null,"errorMessage":"No NVIDIA NIM token context limit was set.","messagePattern":"No NVIDIA NIM token context limit was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"server/utils/AiProviders/nvidiaNim/index.js","lineNumber":89,"sourceCode":"        return [];\n      });\n\n    if (!model.length) return;\n    const modelInfo = model.find((model) => model.id === modelId);\n    if (!modelInfo) return;\n    process.env.NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT = Number(\n      modelInfo.max_model_len || 4096\n    );\n  }\n\n  streamingEnabled() {\n    return \"streamGetChatCompletion\" in this;\n  }\n\n  static promptWindowLimit(_modelName) {\n    const limit = process.env.NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT || 4096;\n    if (!limit || isNaN(Number(limit)))\n      throw new Error(\"No NVIDIA NIM token context limit was set.\");\n    return Number(limit);\n  }\n\n  // Ensure the user set a value for the token limit\n  // and if undefined - assume 4096 window.\n  promptWindowLimit() {\n    const limit = process.env.NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT || 4096;\n    if (!limit || isNaN(Number(limit)))\n      throw new Error(\"No NVIDIA NIM token context limit was set.\");\n    return Number(limit);\n  }\n\n  async isValidChatCompletionModel(_ = \"\") {\n    return true;\n  }\n\n  /**\n   * Generates appropriate content array for a message + attachments.","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/nvidiaNim/index.js#L71-L107","documentation":"static promptWindowLimit reads NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT with a `|| 4096` fallback, then throws 'No ... token context limit was set' if the value is falsy or non-numeric. The `|| 4096` already prevents unset/empty from reaching the check, so in practice this throws ONLY when the env var is set to a non-numeric string (e.g. '8k', '4,096', 'unlimited'). The message ('not set') is therefore misleading — it really means 'not a number'.","triggerScenarios":"Setting NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT to a value Number() cannot parse to a finite number — e.g. '8k', '4096 tokens', '4,096', or any non-numeric string. Unset/empty values fall back to 4096 and do NOT throw.","commonSituations":"User adds a unit suffix ('8k') or thousands separator ('4,096'); copies a human-readable string instead of a plain integer; the static path is hit during class-level lookups before an instance is built.","solutions":["Set NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT to a plain integer string, e.g. 8192.","Remove any unit suffixes or thousands separators.","If you intended the default, simply unset the variable (it defaults to 4096).","Verify with Number(process.env.NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT) in a REPL."],"exampleFix":"// before\nNVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT=8k   // Number('8k') -> NaN -> throws\n\n// after\nNVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT=8192","handlingStrategy":"validation","validationCode":"// Validate the token limit is a plain integer before the static call\nconst raw = process.env.NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT;\nif (raw != null && raw !== '' && !/^\\d+$/.test(String(raw).trim())) {\n  throw new Error(`NVIDIA_NIM_LLM_MODEL_TOKEN_LIMIT='${raw}' is not a plain integer.`);\n}","typeGuard":"function isValidTokenLimit(raw) {\n  return raw == null || raw === '' || (/^\\d+$/.test(String(raw).trim()) && Number(raw) > 0);\n}","tryCatchPattern":"try {\n  NvidiaNimLLM.promptWindowLimit(modelName);\n} catch (e) {\n  if (/No NVIDIA NIM token context limit/i.test(e.message)) {\n    // the env var is set but non-numeric — fix or unset it (defaults to 4096)\n  }\n}","preventionTips":["Remember the misleading message: it fires on non-numeric, not on missing (unset => 4096).","Always use a plain integer string (no 'k', no commas, no units).","Validate numeric env vars at startup."],"tags":["nvidia-nim","configuration","token-limit","validation","misleading-message"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}