{"record":{"id":"c27f0c55d6de05ce","repo":"nocobase/nocobase","slug":"llm-service-not-found","errorCode":null,"errorMessage":"LLM service not found","messagePattern":"LLM service not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/@nocobase/plugin-ai/src/server/manager/ai-manager.ts","lineNumber":194,"sourceCode":"      model,\n    };\n\n    if (webSearch === true) {\n      modelOptions.builtIn = { webSearch: true };\n    }\n\n    if (reasoning) {\n      modelOptions._reasoning = reasoning;\n    }\n\n    const service = await this.plugin.db.getRepository('llmServices').findOne({\n      filter: {\n        name: llmService,\n      },\n    });\n\n    if (!service) {\n      throw new Error('LLM service not found');\n    }\n\n    const providerOptions = this.llmProviders.get(service.provider);\n    if (!providerOptions) {\n      throw new Error('LLM service provider not found');\n    }\n\n    if (webSearch === true && providerOptions.webSearchModels && !providerOptions.webSearchModels.includes(model)) {\n      throw new Error(`Web search is not supported by model \"${model}\"`);\n    }\n\n    const Provider = providerOptions.provider;\n    const provider = new Provider({\n      app: this.plugin.app,\n      serviceOptions: service.options,\n      modelOptions,\n    });\n","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/nocobase/nocobase/blob/fa42722fefe44265490dff2c27d79e2882bce4fa/packages/plugins/@nocobase/plugin-ai/src/server/manager/ai-manager.ts#L176-L212","documentation":"getLLMService looks up the llmServices repository row by `filter: { name: llmService }`. If no row matches the given service name, it throws 'LLM service not found'. The caller supplied a name, but it does not correspond to any stored LLM service.","triggerScenarios":"Calling getLLMService({ llmService: 'X', model: 'Y' }) where no llmServices record named 'X' exists — e.g. a typo, or the record was deleted after the client cached the name.","commonSituations":"Frontend holding a stale service name after an admin renamed or deleted the LLM service; environment promotion where llmServices data was not migrated; hand-written API calls guessing service names; case-sensitivity mismatches ('OpenAI' vs 'openai').","solutions":["List existing services (listAllEnabledModels or query the llmServices collection) and use an exact existing `name`.","If the service was deleted, re-create it in the AI settings and re-select the model in the UI.","Copy the llmServices data to the target environment if the error appears after promoting between dev/staging/prod.","Fix any typo/casing mismatch between the client-provided llmService and the stored name."],"exampleFix":"// before\nawait aiManager.getLLMService({ llmService: 'open-ai', model: 'gpt-4o' }); // typo, no such row\n// after\nawait aiManager.getLLMService({ llmService: 'my-openai', model: 'gpt-4o' }); // matches llmServices.name","handlingStrategy":"validation","validationCode":"const services = await app.db.getRepository('llmServices').find();\nconst names = new Set(services.map((s) => s.name));\nif (!names.has(llmService)) throw new Error(`Unknown llmService \"${llmService}\"; available: ${[...names].join(', ')}`);","typeGuard":"function serviceExists(name: string, services: { name: string }[]): boolean {\n  return services.some((s) => s.name === name);\n}","tryCatchPattern":"try {\n  const svc = await aiManager.getLLMService({ llmService, model });\n} catch (e) {\n  if (e.message === 'LLM service not found') {\n    // fall back to the first enabled service\n    const [alt] = await aiManager.listAllEnabledModels();\n    return alt ? aiManager.getLLMService({ llmService: alt.llmService, model: alt.enabledModels[0].value }) : null;\n  }\n  throw e;\n}","preventionTips":["Populate service names from the server's list endpoint instead of hardcoding strings.","Re-fetch AI config after admins add/rename/delete services.","Watch case sensitivity when matching service names."],"tags":["database","llm","lookup-failed"],"backgroundTag":"resource-not-found","analyzedSha":"fa42722fefe44265490dff2c27d79e2882bce4fa","analyzedAt":"2026-09-01T00:54:31.202Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}