{"record":{"id":"bd6807448fb594b0","repo":"Mintplex-Labs/anything-llm","slug":"no-token-context-limit-was-set-bd6807","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/liteLLM/index.js","lineNumber":61,"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.LITE_LLM_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.LITE_LLM_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":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/liteLLM/index.js#L43-L79","documentation":"Static LiteLLM.promptWindowLimit(_modelName): `const limit = process.env.LITE_LLM_MODEL_TOKEN_LIMIT || 4096; if (!limit || isNaN(Number(limit))) throw 'No token context limit was set.'`. The || 4096 fallback means a missing var can never trigger it; only a set-but-non-numeric value can (Number() → NaN). Used statically by AnythingLLM to size context windows before instantiation.","triggerScenarios":"Calling LiteLLM.promptWindowLimit(model) with LITE_LLM_MODEL_TOKEN_LIMIT set to something like '128k', '32_768', '131072 # claude', or a quoted number — anything Number() cannot parse. Integer strings, hex-free floats, and empty/unset values are all fine (empty/unset hit the 4096 fallback).","commonSituations":"Copying human-readable context sizes ('200k') from model spec sheets into .env; dotenv files with CRLF line endings leaving a trailing \\r; secret-manager injection adding quotes around numeric values; deploy pipelines templating 'None' when the var is unconfigured.","solutions":["Use a bare integer: LITE_LLM_MODEL_TOKEN_LIMIT=8192.","Strip units, commas, underscores, quotes, and comments from the value; check for hidden CRLF with cat -A .env.","Or delete the variable to accept the 4096 default.","Guard in CI: reject deploys where the var is set and fails ^\\d+$."],"exampleFix":"# before (.env)\nLITE_LLM_MODEL_TOKEN_LIMIT=128k\n\n# after (.env)\nLITE_LLM_MODEL_TOKEN_LIMIT=131072","handlingStrategy":"validation","validationCode":"const raw = process.env.LITE_LLM_MODEL_TOKEN_LIMIT;\nif (raw && !/^\\d+$/.test(raw.trim())) throw new Error(`LITE_LLM_MODEL_TOKEN_LIMIT must be an integer, got ${JSON.stringify(raw)}`);\nconst ctx = LiteLLM.promptWindowLimit(model);","typeGuard":"const isIntegerEnv = (v) => v == null || v === \"\" || /^\\d+$/.test(String(v).trim());","tryCatchPattern":null,"preventionTips":["Validate numeric env vars with a strict regex at boot — before any provider is constructed.","Write limits as plain decimal integers; no 128k, 16,384, or quoted values.","Unset rather than zero/blank-pad the variable when unsure; the 4096 default is safe."],"tags":["litellm","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"}