{"record":{"id":"948f3531ab0f7d58","repo":"alibaba/nacos","slug":"failed-to-request-api-s-after-all-servers-s-tr","errorCode":null,"errorMessage":"Failed to request API: %s after all servers(%s) tried: %s","messagePattern":"Failed to request API: (.+?) after all servers\\((.+?)\\) tried: (.+?)","errorType":"exception","errorClass":"NacosException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/com/alibaba/nacos/client/ai/remote/AiHttpClientProxy.java","lineNumber":462,"sourceCode":"    private String requestAgentApi(String api, AgentHttpMethod method,\n        List<QueryParameter> parameters, Map<String, String> form, RequestResource resource)\n        throws NacosException {\n        List<String> servers = serverListManager.getServerList();\n        if (servers.isEmpty()) {\n            throw new NacosException(NacosException.INVALID_PARAM, \"no server available\");\n        }\n        NacosException exception = new NacosException();\n        int index = ThreadLocalRandom.current().nextInt(servers.size());\n        for (int i = 0; i < Math.max(servers.size(), MAX_RETRY); i++) {\n            String server = servers.get(index % servers.size());\n            try {\n                return callAgentServer(api, method, parameters, form, server, resource);\n            } catch (NacosException e) {\n                exception = e;\n            }\n            index = (index + 1) % servers.size();\n        }\n        throw new NacosException(exception.getErrCode(),\n            \"Failed to request API: \" + api + \" after all servers(\" + servers + \") tried: \"\n                + exception.getMessage());\n    }\n    \n    private String callAgentServer(String api, AgentHttpMethod method,\n        List<QueryParameter> parameters, Map<String, String> form, String server,\n        RequestResource resource) throws NacosException {\n        Header header = Header.newInstance();\n        header.addAll(securityProxy.getIdentityContext(resource));\n        header.addParam(HTTP_CLIENT_ID_HEADER, httpClientId);\n        if (AgentHttpMethod.GET != method) {\n            header.addParam(HttpHeaderConsts.REQUEST_MODULE, Constants.AI.AI_MODULE);\n        }\n        String url = appendQuery(buildUrl(server, api), parameters);\n        try {\n            HttpRestResult<String> restResult;\n            if (AgentHttpMethod.GET == method) {\n                restResult = nacosRestTemplate.get(url, header, Query.EMPTY, String.class);","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/client/src/main/java/com/alibaba/nacos/client/ai/remote/AiHttpClientProxy.java#L444-L480","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded last error message/code to find the per-server cause, then fix it cluster-wide.","Check server health and logs across all listed servers.","Verify credentials/namespace are correct for every server.","Confirm the agent API endpoint exists on the deployed server version; retry after resolving the underlying error."],"exampleFix":"// before\ntry { httpClient.requestAgentApi(...); }\ncatch (NacosException e) { /* only top message seen */ }\n// after\ntry { httpClient.requestAgentApi(...); }\ncatch (NacosException e) {\n    LOGGER.error(\"All servers failed; code={} msg={}\", e.getErrCode(), e.getMessage());\n    // e.getMessage() lists api, server list, and the last server's error for diagnosis\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    client.requestAgentApi(...);\n} catch (NacosException e) {\n    // message lists api, servers, and the last server's error.\n    int code = e.getErrCode();\n    if (isTransientCode(code)) {\n        // backoff and retry; underlying cause is cluster-wide/transient\n    }\n    throw e;\n}","preventionTips":["Inspect the embedded last error to find the cluster-wide root cause.","Verify health/credentials/version across all servers.","Retry idempotent calls after resolving the per-server failure."],"tags":["ai","http","retry","all-servers-failed","agent-api","network"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}