{"record":{"id":"8ecb39e5a971b58e","repo":"Mintplex-Labs/anything-llm","slug":"x1b-33m-contextlimit-warning-x1b-0m-could-not-d","errorCode":null,"errorMessage":"\\x1b[33m[.contextLimit warning]\\x1b[0m Could not determine .promptWindowLimit for provider ${provider}. This could lead to incorrect context window management by AnythingLLM since we cannot determine the context window limit for this provider/model combination.","messagePattern":"\\\\x1b\\[33m\\[\\.contextLimit warning\\]\\\\x1b\\[0m Could not determine \\.promptWindowLimit for provider (.+?)\\. This could lead to incorrect context window management by AnythingLLM since we cannot determine the context window limit for this provider/model combination\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/utils/agents/aibitat/providers/ai-provider.js","lineNumber":565,"sourceCode":"\n  /**\n   * Get the context limit for a provider/model combination using static method in AIProvider class.\n   * @param {string} provider\n   * @param {string} modelName\n   * @returns {number}\n   */\n  static contextLimit(provider = \"openai\", modelName) {\n    if (typeof provider !== \"string\") {\n      console.log(\n        `\\x1b[43m\\x1b[30m[.contextLimit warning] A non-string provider for .contextLimit was given — Returning fallback context limit of 8000.\\x1b[0m\\n\\x1b[43m\\x1b[30mThis is a bug and should be reported so that context windows are properly managed by AnythingLLM.\\x1b[0m`\n      );\n      console.trace();\n      return 8_000;\n    }\n\n    const llm = getLLMProviderClass({ provider });\n    if (!llm || !llm.hasOwnProperty(\"promptWindowLimit\")) {\n      console.warn(\n        `\\x1b[33m[.contextLimit warning]\\x1b[0m Could not determine .promptWindowLimit for provider ${provider}. This could lead to incorrect context window management by AnythingLLM since we cannot determine the context window limit for this provider/model combination.`\n      );\n      return 8_000;\n    }\n    return llm.promptWindowLimit(modelName);\n  }\n\n  /**\n   * Get the system prompt for a provider, with memories appended (when enabled).\n   * @param {object} opts\n   * @param {import(\"@prisma/client\").workspaces | null} opts.workspace\n   * @param {import(\"@prisma/client\").users | null} opts.user\n   * @param {string} [opts.prompt] - current user message, used for reranking injected memories\n   * @returns {Promise<string>}\n   */\n  static async systemPrompt({ workspace = null, user = null, prompt = \"\" }) {\n    const { SystemSettings } = require(\"../../../../models/systemSettings\");\n    const { promptWithMemories } = require(\"../../../memories\");","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/utils/agents/aibitat/providers/ai-provider.js#L547-L583","documentation":"AiProvider.contextLimit resolved the provider class via getLLMProviderClass and either found nothing or the class lacks a promptWindowLimit static, so it returns a hard fallback of 8,000 tokens. All context management (history trimming, prompt sizing) for that provider/model will assume 8k, which under- or over-fills the real window.","triggerScenarios":"provider string not matching a known key of the provider registry (typo like 'opeanai'); a custom/new provider class added without a static promptWindowLimit(modelName) method; a provider registered under a different name than the one passed in.","commonSituations":"Contributing a new LLM provider and forgetting the limit method; swapping provider identifiers after a refactor; using a fork where the registry map was extended but the class was not.","solutions":["Verify the provider string is spelled exactly as registered in getLLMProviderClass.","Add a static promptWindowLimit(modelName) to the provider class returning the correct token count.","Register the provider class in getLLMProviderClass's map so the lookup succeeds.","Until fixed, expect 8000 to be used — pick models whose real window is close or explicitly size prompts yourself."],"exampleFix":"// before\nclass MyProvider extends Provider { /* no promptWindowLimit */ }\n\n// after\nclass MyProvider extends Provider {\n  static promptWindowLimit(modelName = \"my-model\") {\n    return 128_000;\n  }\n}","handlingStrategy":"type-guard","validationCode":"// When registering a provider, assert it supports context limits:\nconst cls = getLLMProviderClass({ provider: 'myprovider' });\nif (!cls || !('promptWindowLimit' in cls)) {\n  throw new Error('provider class must implement static promptWindowLimit');\n}","typeGuard":"function hasPromptWindowLimit(cls) {\n  return !!cls && typeof cls.promptWindowLimit === 'function';\n}","tryCatchPattern":null,"preventionTips":["Add a static promptWindowLimit(modelName) to every new provider class.","Register the class under the exact provider key used in config.","Unit-test contextLimit for each provider string you ship.","Watch for this warning after provider refactors — it silently changes trimming behavior."],"tags":["context-window","llm-provider","fallback","configuration"],"backgroundTag":"unknown-context-window-size","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}