alibaba/spring-ai-alibaba · error · BizException

Unauthorized

Unauthorized

Error message

Required to authorize, please login.

What it means

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.

Solutions

  1. Authenticate the user and propagate accountId into AgentContext before invoking the agent
  2. Check token validity/expiry and re-login
  3. Bypass for service-to-service calls only with an explicit service identity
Defensive patterns

Strategy: validation

When it happens

Trigger: 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.

Common situations: See trigger scenarios.


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/8e894e499d8657f1. Report an issue: GitHub.

Appendix: source

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

			.doOnNext(response -> postHandle(context, response))
			// final call
			.doFinally(signal -> statistics(context, signal));
	}

	/**
	 * Validates and initializes the agent context with request parameters
	 */
	private void checkAndInitContext(AgentContext context, AgentRequest request) {
		Long start = System.currentTimeMillis();
		try {
			// check input params
			if (Objects.isNull(request)) {
				throw new BizException(ErrorCode.MISSING_PARAMS.toError("request"));
			}

			String uid = context.getAccountId();
			if (Objects.isNull(uid)) {
				throw new BizException(ErrorCode.UNAUTHORIZED.toError());
			}

			String appId = request.getAppId();
			if (StringUtils.isBlank(appId)) {
				throw new BizException(ErrorCode.MISSING_PARAMS.toError("appId"));
			}

			if (CollectionUtils.isEmpty(request.getMessages())) {
				throw new BizException(ErrorCode.MISSING_PARAMS.toError("messages"));
			}

			if (Objects.isNull(context.getWorkspaceId())) {
				throw new BizException(ErrorCode.MISSING_PARAMS.toError("workspace_id"));
			}

			// get app config
			Application app = appService.getApp(appId);
			if (app == null) {

View on GitHub (pinned to f82da0b50f)