{"record":{"id":"2a9cdc6b23a9c143","repo":"Mintplex-Labs/anything-llm","slug":"no-model-router-found-for-this-workspace","errorCode":null,"errorMessage":"No model router found for this workspace.","messagePattern":"No model router found for this workspace\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/modelRouter/index.js","lineNumber":38,"sourceCode":"  /**\n   * Resolve the route and instantiate the delegate LLM provider.\n   * Must be called before any chat methods.\n   *\n   * Flow:\n   * 1. Evaluate calculated rules (always — they're free)\n   * 2. Evaluate LLM rules (uses cache to avoid expensive calls)\n   * 3. If nothing matched, use the sticky route (previous model stays)\n   * 4. If sticky expired, fall back to the default model\n   *\n   * @param {Object} context - { prompt, conversationHistory, conversationTokenCount }\n   * @param {Object} opts - { user, thread }\n   */\n  async resolve(context = {}, { user = null, thread = null } = {}) {\n    this.router = await this.routerService.resolveRouterForWorkspace(\n      this.workspace\n    );\n    if (!this.router)\n      throw new Error(\"No model router found for this workspace.\");\n\n    const rules = this.router.rules || [];\n    const stickyMs = (this.router.cooldown_seconds ?? 300) * 1000;\n    this._routeKey = this.routerService.routeCacheKey(\n      user?.id,\n      this.workspace.slug,\n      thread?.slug\n    );\n\n    this.routerService.logRoutingContext(this.router, rules, context);\n\n    // Step 1: Calculated rules (always re-evaluated, they're instant)\n    const calcResult = this.routerService.evaluateCalculatedRules(\n      rules,\n      context\n    );\n    if (calcResult) {\n      this.resolvedRoute = calcResult;","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/modelRouter/index.js#L20-L56","documentation":"AnythingLLMModelRouter.resolve() must load a model-router configuration before it can route; it calls ModelRouterService.resolveRouterForWorkspace(), which returns null when the workspace has no router_id or the referenced router record cannot be loaded (e.g. deleted). resolve() then throws this error, so no delegate LLM provider is ever created.","triggerScenarios":"Workspace chat uses the model router but workspace.router_id is null (router never assigned or detached); the referenced router row was deleted while workspaces still point at it; a stale in-process workspace object is used after the router was removed; calling resolve() on a workspace whose router assignment is still mid-save.","commonSituations":"Admin deletes a model router that workspaces still reference; DB restore/migration drops model_routers rows; race between router reassignment and an incoming chat request.","solutions":["Open workspace settings and (re)select a model router so router_id is set on the workspace, then retry","If the router was deleted, create a new model router and assign it to the workspace","Verify the workspace record actually has a non-null router_id — null always produces this error","Restart the server (or let the router cache invalidate) after router configuration changes"],"exampleFix":"// before\nconst router = new AnythingLLMModelRouter(workspace);\nawait router.resolve(ctx); // throws when workspace.router_id is null\n// after\nif (!workspace.router_id)\n  throw new Error('Attach a model router to this workspace first');\nawait router.resolve(ctx);","handlingStrategy":"validation","validationCode":"const svc = ModelRouterService.getInstance();\nconst router = await svc.resolveRouterForWorkspace(workspace);\nif (!router)\n  throw new Error('Workspace has no model router attached — assign one in workspace settings');","typeGuard":"function hasRouterAttached(workspace) {\n  return typeof workspace?.router_id === 'number' && workspace.router_id > 0;\n}","tryCatchPattern":"try {\n  await modelRouter.resolve(context, { user, thread });\n} catch (e) {\n  if (e.message === 'No model router found for this workspace.') {\n    // fall back to the workspace default LLM, or prompt the user to attach a router\n  }\n  throw e;\n}","preventionTips":["Assign a router to the workspace before enabling router mode","When deleting routers, detach dependent workspaces first","Invalidate the router cache (or restart) after router configuration changes","Guard resolve() calls with hasRouterAttached(workspace)"],"tags":["model-router","anythingllm","workspace","configuration"],"backgroundTag":"missing-configuration-record","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"}