{"record":{"id":"7a636ceb776f0895","repo":"spring-projects/spring-ai","slug":"request-failed","errorCode":null,"errorMessage":"Request failed","messagePattern":"Request failed","errorType":"exception","errorClass":"AnthropicIoException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/http/okhttp/SpringAiAnthropicHttpClient.java","lineNumber":126,"sourceCode":"\n\tpublic static Builder builder() {\n\t\treturn new Builder();\n\t}\n\n\t/** Test-only accessor */\n\tOkHttpClient getOkHttpClient() {\n\t\treturn this.okHttpClient;\n\t}\n\n\t@Override\n\tpublic HttpResponse execute(HttpRequest request, RequestOptions requestOptions) {\n\t\tHttpRequest preparedRequest = prepareRequest(request);\n\t\tCall call = newCall(preparedRequest, requestOptions);\n\t\ttry {\n\t\t\treturn this.backend.prepareResponse(toHttpResponse(call.execute()));\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new AnthropicIoException(\"Request failed\", e);\n\t\t}\n\t\tfinally {\n\t\t\tHttpRequestBody body = preparedRequest.body();\n\t\t\tif (body != null) {\n\t\t\t\tbody.close();\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic CompletableFuture<HttpResponse> executeAsync(HttpRequest request, RequestOptions requestOptions) {\n\t\tHttpRequest preparedRequest = prepareRequest(request);\n\t\tCompletableFuture<HttpResponse> future = new CompletableFuture<>();\n\n\t\tCall call = newCall(preparedRequest, requestOptions);\n\t\tcall.enqueue(new Callback() {\n\t\t\t@Override\n\t\t\tpublic void onResponse(Call call, Response response) {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/http/okhttp/SpringAiAnthropicHttpClient.java#L108-L144","documentation":"SpringAiAnthropicHttpClient.execute wraps any IOException raised while executing the OkHttp call into AnthropicIoException with the message 'Request failed'. This covers connection failures, DNS errors, timeouts, TLS problems and stream read errors during the synchronous HTTP exchange with the Anthropic API.","triggerScenarios":"Calling any Anthropic API operation through this OkHttp-based client when the TCP connection cannot be established, is reset, times out, or TLS handshake fails; call.execute() or the response body read throws IOException.","commonSituations":"No network/VPN access or corporate proxy blocking api.anthropic.com; DNS resolution failure; server dropping connections; read timeout set too low for long completions.","solutions":["Check network connectivity and proxy settings to api.anthropic.com (curl https://api.anthropic.com to verify).","Inspect the cause (e.getCause() on AnthropicIoException) to distinguish timeout vs. connect vs. TLS failure.","Increase OkHttp read/call timeouts for long streaming requests.","Add retry with exponential backoff for transient IO errors."],"exampleFix":"// before\nResponse<ChatResponse> resp = client.chatCompletionRequest(params); // fails on network hiccup\n// after\ntry {\n    Response<ChatResponse> resp = client.chatCompletionRequest(params);\n} catch (AnthropicIoException e) {\n    logger.warn(\"Transient network failure, retrying\", e);\n    resp = retryWithBackoff(() -> client.chatCompletionRequest(params));\n}","handlingStrategy":"retry","validationCode":"static void assertApiReachable() {\n    try (var s = new Socket(\"api.anthropic.com\", 443)) { /* reachable */ }\n    catch (IOException e) { throw new IllegalStateException(\"Anthropic API unreachable: \" + e.getMessage()); }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return client.chatCompletionRequest(params);\n} catch (AnthropicIoException e) {\n    if (e.getCause() instanceof SocketTimeoutException) return retryWithBackoff(...);\n    throw e;\n}","preventionTips":["Configure sensible connect/read timeouts and retry with exponential backoff.","Verify proxy/firewall allows outbound HTTPS to api.anthropic.com.","Log e.getCause() to distinguish timeout, connect, and TLS failures."],"tags":["network","okhttp","io"],"backgroundTag":"http-request-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}