Class SpringAiAnthropicHttpClient
java.lang.Object
org.springframework.ai.anthropic.http.okhttp.SpringAiAnthropicHttpClient
- All Implemented Interfaces:
com.anthropic.core.http.HttpClient,AutoCloseable
public final class SpringAiAnthropicHttpClient
extends Object
implements com.anthropic.core.http.HttpClient
OkHttp-backed
HttpClient for the Anthropic Java SDK, with Micrometer's
OkHttpObservationInterceptor attached so each HTTP attempt produces an
observation (span + metric + traceparent propagation). When a MeterRegistry is
supplied, OkHttpConnectionPoolMetrics is also bound. We own this code because
the SDK's stock AnthropicOkHttpClient.Builder doesn't expose an interceptor
seam — see the SDK's
Custom
HTTP client guide for the integration pattern and
anthropic-sdk-java
#315 for the upstream fix being tracked.
Attribution: the body of this class is a Java port of OkHttpClient from
anthropic-java-client-okhttp (Apache License 2.0, authored by Anthropic). Only
the Micrometer wiring in SpringAiAnthropicHttpClient.Builder.build() is original to Spring AI.
- Since:
- 2.0.0
- Author:
- Soby Chacko
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidclose()com.anthropic.core.http.HttpResponseexecute(com.anthropic.core.http.HttpRequest request, com.anthropic.core.RequestOptions requestOptions) CompletableFuture<com.anthropic.core.http.HttpResponse>executeAsync(com.anthropic.core.http.HttpRequest request, com.anthropic.core.RequestOptions requestOptions) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.anthropic.core.http.HttpClient
execute, executeAsync
-
Method Details
-
builder
-
execute
public com.anthropic.core.http.HttpResponse execute(com.anthropic.core.http.HttpRequest request, com.anthropic.core.RequestOptions requestOptions) - Specified by:
executein interfacecom.anthropic.core.http.HttpClient
-
executeAsync
public CompletableFuture<com.anthropic.core.http.HttpResponse> executeAsync(com.anthropic.core.http.HttpRequest request, com.anthropic.core.RequestOptions requestOptions) - Specified by:
executeAsyncin interfacecom.anthropic.core.http.HttpClient
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacecom.anthropic.core.http.HttpClient
-