alibaba/nacos · error · NacosException

400

400

Error message

Unknown AI request type: %s

What it means

Thrown by AiGrpcClient.requestToServer when the Request object is not one of the recognized AI request supertypes (AbstractAgentClientRpcRequest, AbstractMcpRequest, AbstractAgentRequest, AbstractPromptRequest). Because security headers cannot be attached for an unrecognized type, the request is rejected with code 400 before being sent. This is essentially an internal-programmer error indicating a new/unsupported request type reached the dispatcher.

Source

Thrown at client/src/main/java/com/alibaba/nacos/client/ai/remote/AiGrpcClient.java:868

            if (request instanceof AbstractAgentClientRpcRequest) {
                AbstractAgentClientRpcRequest agentRequest =
                    (AbstractAgentClientRpcRequest) request;
                request.putAllHeader(getSecurityHeaders(agentRequest.extractNamespaceId(),
                    agentRequest.extractAgentName()));
            } else if (request instanceof AbstractMcpRequest) {
                AbstractMcpRequest mcpRequest = (AbstractMcpRequest) request;
                request.putAllHeader(
                    getSecurityHeaders(mcpRequest.getNamespaceId(), mcpRequest.getMcpName()));
            } else if (request instanceof AbstractAgentRequest) {
                AbstractAgentRequest agentRequest = (AbstractAgentRequest) request;
                request.putAllHeader(getSecurityHeaders(agentRequest.getNamespaceId(),
                    agentRequest.getAgentName()));
            } else if (request instanceof AbstractPromptRequest) {
                AbstractPromptRequest promptRequest = (AbstractPromptRequest) request;
                request.putAllHeader(getSecurityHeaders(promptRequest.getNamespaceId(),
                    promptRequest.getPromptKey()));
            } else {
                throw new NacosException(400,
                    String.format("Unknown AI request type: %s",
                        request.getClass().getSimpleName()));
            }
            
            response = requestTimeout < 0 ? rpcClient.request(request)
                : rpcClient.request(request, requestTimeout);
            if (ResponseCode.SUCCESS.getCode() != response.getResultCode()) {
                // If the 403 login operation is triggered, refresh the accessToken of the client
                int errorCode = request instanceof AbstractAgentClientRpcRequest
                    ? mapAgentClientErrorCode(response.getErrorCode())
                    : response.getErrorCode();
                if (NacosException.NO_RIGHT == errorCode) {
                    securityProxy.reLogin();
                }
                throw new NacosException(errorCode, response.getMessage());
            }
            if (responseClass.isAssignableFrom(response.getClass())) {
                return (T) response;

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Ensure custom AI request types extend one of the recognized abstract bases (AbstractAgentRequest, AbstractPromptRequest, AbstractMcpRequest, AbstractAgentClientRpcRequest).
  2. Avoid dispatching non-AI requests through AiGrpcClient.requestToServer.
  3. Align client and API/SDK versions so the request hierarchy is consistent.

Example fix

// before
class MyRequest extends Request { ... } // unrecognized
// after
class MyRequest extends AbstractAgentRequest { ... } // categorized; namespaceId/agentName available
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(request instanceof AbstractAgentRequest)
    && !(request instanceof AbstractPromptRequest)
    && !(request instanceof AbstractMcpRequest)
    && !(request instanceof AbstractAgentClientRpcRequest)) {
    throw new IllegalArgumentException("Unsupported AI request type: " + request.getClass());
}

Type guard

request instanceof AbstractAgentRequest
    || request instanceof AbstractPromptRequest
    || request instanceof AbstractMcpRequest
    || request instanceof AbstractAgentClientRpcRequest

Prevention

When it happens

Trigger: Passing a Request subclass that the client does not know how to categorize - e.g. a custom Request type, a new request class not extending one of the recognized abstract AI request bases, or a non-AI Request leaking into the AI request path.

Common situations: Custom request subclass introduced without extending AbstractAgentRequest/AbstractPromptRequest/etc.; cross-wiring a config/naming Request into the AI client; SDK version mismatch where a newer request type is sent through an older client.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/6a5588cfd539e35d. Report an issue: GitHub.