alibaba/nacos · error · NacosException

Failed to request API: %s after all servers(%s) tried: %s

Error message

Failed to request API: %s after all servers(%s) tried: %s

What it means

Thrown by AiHttpClientProxy.requestAgentApi after the client tried every server in the list (up to max(servers, MAX_RETRY)) and each callAgentServer threw a NacosException. The thrown exception carries the last server's error code and a message naming the API, the full server list, and the last error. It is an aggregate all-servers-failed failure, not specific to one server.

Source

Thrown at client/src/main/java/com/alibaba/nacos/client/ai/remote/AiHttpClientProxy.java:462

    private String requestAgentApi(String api, AgentHttpMethod method,
        List<QueryParameter> parameters, Map<String, String> form, RequestResource resource)
        throws NacosException {
        List<String> servers = serverListManager.getServerList();
        if (servers.isEmpty()) {
            throw new NacosException(NacosException.INVALID_PARAM, "no server available");
        }
        NacosException exception = new NacosException();
        int index = ThreadLocalRandom.current().nextInt(servers.size());
        for (int i = 0; i < Math.max(servers.size(), MAX_RETRY); i++) {
            String server = servers.get(index % servers.size());
            try {
                return callAgentServer(api, method, parameters, form, server, resource);
            } catch (NacosException e) {
                exception = e;
            }
            index = (index + 1) % servers.size();
        }
        throw new NacosException(exception.getErrCode(),
            "Failed to request API: " + api + " after all servers(" + servers + ") tried: "
                + exception.getMessage());
    }
    
    private String callAgentServer(String api, AgentHttpMethod method,
        List<QueryParameter> parameters, Map<String, String> form, String server,
        RequestResource resource) throws NacosException {
        Header header = Header.newInstance();
        header.addAll(securityProxy.getIdentityContext(resource));
        header.addParam(HTTP_CLIENT_ID_HEADER, httpClientId);
        if (AgentHttpMethod.GET != method) {
            header.addParam(HttpHeaderConsts.REQUEST_MODULE, Constants.AI.AI_MODULE);
        }
        String url = appendQuery(buildUrl(server, api), parameters);
        try {
            HttpRestResult<String> restResult;
            if (AgentHttpMethod.GET == method) {
                restResult = nacosRestTemplate.get(url, header, Query.EMPTY, String.class);

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Read the embedded last error message/code to find the per-server cause, then fix it cluster-wide.
  2. Check server health and logs across all listed servers.
  3. Verify credentials/namespace are correct for every server.
  4. Confirm the agent API endpoint exists on the deployed server version; retry after resolving the underlying error.

Example fix

// before
try { httpClient.requestAgentApi(...); }
catch (NacosException e) { /* only top message seen */ }
// after
try { httpClient.requestAgentApi(...); }
catch (NacosException e) {
    LOGGER.error("All servers failed; code={} msg={}", e.getErrCode(), e.getMessage());
    // e.getMessage() lists api, server list, and the last server's error for diagnosis
}
Defensive patterns

Strategy: retry

Try / catch

try {
    client.requestAgentApi(...);
} catch (NacosException e) {
    // message lists api, servers, and the last server's error.
    int code = e.getErrCode();
    if (isTransientCode(code)) {
        // backoff and retry; underlying cause is cluster-wide/transient
    }
    throw e;
}

Prevention

When it happens

Trigger: Every server in the list failed the agent API call with a NacosException - e.g. all returned 5xx, all were unreachable (wrapped), or all rejected the call. The loop exhausted servers/MAX_RETRY without a single success.

Common situations: Cluster-wide outage or misconfiguration; all servers running an incompatible version returning errors; auth/credentials invalid across all servers; network partition isolating all servers; the requested agent API path not present on any server.

Related errors


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