{"record":{"id":"8e894e499d8657f1","repo":"alibaba/spring-ai-alibaba","slug":"unauthorized","errorCode":"Unauthorized","errorMessage":"Required to authorize, please login.","messagePattern":"Required to authorize, please login\\.","errorType":"error_code","errorClass":"BizException","httpStatus":401,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AgentServiceImpl.java","lineNumber":142,"sourceCode":"\t\t\t.doOnNext(response -> postHandle(context, response))\n\t\t\t// final call\n\t\t\t.doFinally(signal -> statistics(context, signal));\n\t}\n\n\t/**\n\t * Validates and initializes the agent context with request parameters\n\t */\n\tprivate void checkAndInitContext(AgentContext context, AgentRequest request) {\n\t\tLong start = System.currentTimeMillis();\n\t\ttry {\n\t\t\t// check input params\n\t\t\tif (Objects.isNull(request)) {\n\t\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"request\"));\n\t\t\t}\n\n\t\t\tString uid = context.getAccountId();\n\t\t\tif (Objects.isNull(uid)) {\n\t\t\t\tthrow new BizException(ErrorCode.UNAUTHORIZED.toError());\n\t\t\t}\n\n\t\t\tString appId = request.getAppId();\n\t\t\tif (StringUtils.isBlank(appId)) {\n\t\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"appId\"));\n\t\t\t}\n\n\t\t\tif (CollectionUtils.isEmpty(request.getMessages())) {\n\t\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"messages\"));\n\t\t\t}\n\n\t\t\tif (Objects.isNull(context.getWorkspaceId())) {\n\t\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"workspace_id\"));\n\t\t\t}\n\n\t\t\t// get app config\n\t\t\tApplication app = appService.getApp(appId);\n\t\t\tif (app == null) {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AgentServiceImpl.java#L124-L160","documentation":"checkAndInitContext throws BizException(UNAUTHORIZED) when AgentRequest is present but context.getAccountId() is null — the caller has no authenticated session, so the agent run cannot be attributed or authorized.","triggerScenarios":"Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AgentServiceImpl.java:142 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Authenticate the user and propagate accountId into AgentContext before invoking the agent","Check token validity/expiry and re-login","Bypass for service-to-service calls only with an explicit service identity"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}