Mintplex-Labs/anything-llm · error
No token context limit was set.
Error message
No token context limit was set.
What it means
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.
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+$.
Example fix
# before (.env) LITE_LLM_MODEL_TOKEN_LIMIT=128k # after (.env) LITE_LLM_MODEL_TOKEN_LIMIT=131072
Defensive patterns
Strategy: validation
Validate before calling
const raw = process.env.LITE_LLM_MODEL_TOKEN_LIMIT;
if (raw && !/^\d+$/.test(raw.trim())) throw new Error(`LITE_LLM_MODEL_TOKEN_LIMIT must be an integer, got ${JSON.stringify(raw)}`);
const ctx = LiteLLM.promptWindowLimit(model); Type guard
const isIntegerEnv = (v) => v == null || v === "" || /^\d+$/.test(String(v).trim());
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- No LocalAi token context limit was set.
- No token context limit was set.
- LiteLLM must have a valid base path to use for the api.
- LiteLLM must have a valid model set.
- KoboldCPP must have a valid base path to use for the api.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/bd6807448fb594b0.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/AiProviders/liteLLM/index.js:61
if (!contextTexts || !contextTexts.length) return "";
return (
"\nContext:\n" +
contextTexts
.map((text, i) => {
return `[CONTEXT ${i}]:\n${text}\n[END CONTEXT ${i}]\n\n`;
})
.join("")
);
}
streamingEnabled() {
return "streamGetChatCompletion" in this;
}
static promptWindowLimit(_modelName) {
const limit = process.env.LITE_LLM_MODEL_TOKEN_LIMIT || 4096;
if (!limit || isNaN(Number(limit)))
throw new Error("No token context limit was set.");
return Number(limit);
}
// Ensure the user set a value for the token limit
// and if undefined - assume 4096 window.
promptWindowLimit() {
const limit = process.env.LITE_LLM_MODEL_TOKEN_LIMIT || 4096;
if (!limit || isNaN(Number(limit)))
throw new Error("No token context limit was set.");
return Number(limit);
}
// Short circuit since we have no idea if the model is valid or not
// in pre-flight for generic endpoints
isValidChatCompletionModel(_modelName = "") {
return true;
}
View on GitHub (pinned to 3aec848f28)