{"record":{"id":"7cb73ef74473e852","repo":"spring-projects/spring-ai","slug":"httpclientbuildercustomizers-cannot-be-combined-wi-7cb73e","errorCode":null,"errorMessage":"httpClientBuilderCustomizers cannot be combined with a pre-built anthropicClientAsync because the HTTP layer is already constructed","messagePattern":"httpClientBuilderCustomizers cannot be combined with a pre-built anthropicClientAsync because the HTTP layer is already constructed","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java","lineNumber":1950,"sourceCode":"\t\t */\n\t\tpublic Builder httpClientBuilderCustomizers(List<AnthropicHttpClientBuilderCustomizer> customizers) {\n\t\t\tAssert.notNull(customizers, \"customizers cannot be null\");\n\t\t\tthis.httpClientCustomizers = new ArrayList<>(customizers);\n\t\t\treturn this;\n\t\t}\n\n\t\t/**\n\t\t * Builds a new {@link AnthropicChatModel} instance.\n\t\t * @return the configured chat model\n\t\t */\n\t\tpublic AnthropicChatModel build() {\n\t\t\tif (!this.httpClientCustomizers.isEmpty() && this.anthropicClient != null) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"httpClientBuilderCustomizers cannot be combined with a pre-built anthropicClient \"\n\t\t\t\t\t\t\t\t+ \"because the HTTP layer is already constructed\");\n\t\t\t}\n\t\t\tif (!this.httpClientCustomizers.isEmpty() && this.anthropicClientAsync != null) {\n\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\"httpClientBuilderCustomizers cannot be combined with a pre-built anthropicClientAsync \"\n\t\t\t\t\t\t\t\t+ \"because the HTTP layer is already constructed\");\n\t\t\t}\n\t\t\treturn new AnthropicChatModel(this.anthropicClient, this.anthropicClientAsync, this.options,\n\t\t\t\t\tthis.toolCallingManager, this.observationRegistry, this.meterRegistry, this.dispatcherExecutor,\n\t\t\t\t\tthis.httpClientCustomizers);\n\t\t}\n\n\t}\n\n}\n","sourceCodeStart":1932,"sourceCodeEnd":1962,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/AnthropicChatModel.java#L1932-L1962","documentation":"The async counterpart of the same builder validation: build() throws IllegalArgumentException when httpClientBuilderCustomizers are set together with a pre-built AnthropicClientAsync, because the async HTTP layer is already constructed and customizers would be silently ignored.","triggerScenarios":"Calling builder.anthropicClientAsync(asyncClient) plus builder.httpClientBuilderCustomizers(...), then build(); also triggered when both sync and async pre-built clients are set and customizers are present.","commonSituations":"Providing a shared async client for streaming use cases while separately configuring HTTP timeouts via customizers; copy-pasting builder configuration that sets both the client and customizers.","solutions":["Drop the pre-built anthropicClientAsync and let the builder construct it from baseUrl/apiKey so customizers take effect.","Remove the httpClientBuilderCustomizers and configure the async client's HTTP layer directly at construction time.","If you need both sync and async clients, build both inside one set of customizers by letting the builder create them.","Audit your builder chain for both customizers and any anthropicClient/anthropicClientAsync calls before build()."],"exampleFix":"// before\nbuilder.anthropicClientAsync(preBuiltAsyncClient)\n       .httpClientBuilderCustomizers(customizers);\n// after\nbuilder.baseUrl(\"https://api.anthropic.com\")\n       .apiKey(apiKey)\n       .httpClientBuilderCustomizers(customizers);","handlingStrategy":"validation","validationCode":"if (customizers != null && !customizers.isEmpty() && preBuiltAsyncClient != null) {\n    throw new IllegalStateException(\"Choose either a pre-built anthropicClientAsync OR httpClientBuilderCustomizers\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    model = builder.build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"pre-built anthropicClientAsync\")) {\n        model = builderWithoutAsyncClient.build();\n    } else throw e;\n}","preventionTips":["Never set anthropicClientAsync together with httpClientBuilderCustomizers on the same builder.","Configure streaming/timeouts on the pre-built async client itself if you keep it.","Keep sync/async builder configuration symmetric and covered by tests."],"tags":["java","spring-ai","anthropic","builder","conflicting-options"],"backgroundTag":"conflicting-config-options","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"}