{"record":{"id":"69da8482af23ccbb","repo":"Mintplex-Labs/anything-llm","slug":"no-token-context-limit-was-set-69da84","errorCode":null,"errorMessage":"No token context limit was set.","messagePattern":"No token context limit was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/koboldCPP/index.js","lineNumber":63,"sourceCode":"    if (!contextTexts || !contextTexts.length) return \"\";\n    return (\n      \"\\nContext:\\n\" +\n      contextTexts\n        .map((text, i) => {\n          return `[CONTEXT ${i}]:\\n${text}\\n[END CONTEXT ${i}]\\n\\n`;\n        })\n        .join(\"\")\n    );\n  }\n\n  streamingEnabled() {\n    return \"streamGetChatCompletion\" in this;\n  }\n\n  static promptWindowLimit(_modelName) {\n    const limit = process.env.KOBOLD_CPP_MODEL_TOKEN_LIMIT || 4096;\n    if (!limit || isNaN(Number(limit)))\n      throw new Error(\"No 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.KOBOLD_CPP_MODEL_TOKEN_LIMIT || 4096;\n    if (!limit || isNaN(Number(limit)))\n      throw new Error(\"No token context limit was set.\");\n    return Number(limit);\n  }\n\n  // Short circuit since we have no idea if the model is valid or not\n  // in pre-flight for generic endpoints\n  isValidChatCompletionModel(_modelName = \"\") {\n    return true;\n  }\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/koboldCPP/index.js#L45-L81","documentation":"Static KoboldCPPLLM.promptWindowLimit(_modelName) reads KOBOLD_CPP_MODEL_TOKEN_LIMIT with a 4096 default and throws 'No token context limit was set.' only if the value is falsy or Number(limit) is NaN. Because of the `|| 4096` fallback the falsy branch is dead code; the only live trigger is the env var being set to a non-numeric string. The static variant is used by AnythingLLM's provider-selection code to compute context windows before an instance exists.","triggerScenarios":"Calling KoboldCPPLLM.promptWindowLimit(modelName) (statically, during provider capability lookup) while KOBOLD_CPP_MODEL_TOKEN_LIMIT contains a non-numeric value such as '4,096', '4096 tokens', '16k', or a stray quote. The NaN check converts it into this throw.","commonSituations":"Users pasting a formatted number with a thousands separator or unit into .env; a trailing space plus quote (\"4096\") from copy-paste; accidentally documenting the var inline (4096 # context) which JS Number() cannot parse; CI injecting the var as 'null' or 'undefined' from a template.","solutions":["Set the variable to a plain integer: KOBOLD_CPP_MODEL_TOKEN_LIMIT=8192.","Remove commas, units, quotes, and inline comments from the value.","Or simply unset/delete the variable — the code falls back to 4096.","Sanitize at deploy time: assert /^[0-9]+$/ against the var before starting the server."],"exampleFix":"# before (.env)\nKOBOLD_CPP_MODEL_TOKEN_LIMIT=16,384\n\n# after (.env)\nKOBOLD_CPP_MODEL_TOKEN_LIMIT=16384","handlingStrategy":"validation","validationCode":"const raw = process.env.KOBOLD_CPP_MODEL_TOKEN_LIMIT;\nif (raw !== undefined && raw !== \"\" && !/^\\d+$/.test(raw.trim())) {\n  throw new Error(`KOBOLD_CPP_MODEL_TOKEN_LIMIT must be a bare integer, got: ${raw}`);\n}\nconst window = KoboldCPPLLM.promptWindowLimit(modelName);","typeGuard":"function isParsableTokenLimit(value) {\n  return value !== undefined && value !== null && value !== \"\" && !isNaN(Number(value));\n}","tryCatchPattern":null,"preventionTips":["Validate every *_TOKEN_LIMIT env var with /^\\d+$/ at process boot.","Never paste formatted numbers or units into .env; use plain integers.","Prefer leaving the var unset to accept the 4096 default over guessing values."],"tags":["koboldcpp","anythingllm","env-var","nan","token-limit","configuration"],"backgroundTag":"invalid-env-var-value","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"}