{"record":{"id":"e0f6e6afcf75405c","repo":"Mintplex-Labs/anything-llm","slug":"no-token-context-limit-was-set","errorCode":null,"errorMessage":"No token context limit was set.","messagePattern":"No token context limit was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/genericOpenAi/index.js","lineNumber":102,"sourceCode":"    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    if (process.env.GENERIC_OPENAI_STREAMING_DISABLED === \"true\") return false;\n    return \"streamGetChatCompletion\" in this;\n  }\n\n  static promptWindowLimit(_modelName) {\n    const limit = process.env.GENERIC_OPEN_AI_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.GENERIC_OPEN_AI_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":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/genericOpenAi/index.js#L84-L120","documentation":"Thrown by the static promptWindowLimit(_modelName) when the resolved limit is falsy or non-numeric. Because of the `|| 4096` fallback an unset var yields 4096 (valid), so in practice this fires only when GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT is set to a non-numeric string such as 'unlimited' or '4k'. The static variant is used before an instance exists.","triggerScenarios":"Calling GenericOpenAiLLM.promptWindowLimit(modelName) (static) while GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT is a non-numeric, non-empty value like 'large' or 'auto'. An empty/undefined value is safe (defaults to 4096).","commonSituations":"User typed a human word instead of a number in the token-limit field; copy-pasted a config with units ('8k'); UI validation not enforcing numeric input.","solutions":["Set GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT to a plain integer, e.g. 8192","Leave it unset to accept the 4096 default","Add UI/env validation to reject non-numeric token limits","After fixing, restart the server"],"exampleFix":"// before\n// .env: GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT=8k\n\n// after\n// .env: GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT=8192","handlingStrategy":"validation","validationCode":"function validTokenLimit() {\n  const raw = process.env.GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT;\n  if (raw == null || raw === '') return 4096;\n  const n = Number(raw);\n  if (Number.isNaN(n)) {\n    throw new ConfigError('GENERIC_OPEN_AI_MODEL_TOKEN_LIMIT must be numeric.');\n  }\n  return n;\n}","typeGuard":"const isTokenLimit = (v) =>\n  v == null || v === '' ? true : (typeof v === 'string' || typeof v === 'number') && !Number.isNaN(Number(v));","tryCatchPattern":null,"preventionTips":["Enforce numeric input in the provider-settings UI","Default to 4096 explicitly in config templates","Run a startup config validator over all numeric env vars"],"tags":["generic-openai","configuration","token-limits","validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}