Class SpringAiOpenAiHttpClient
java.lang.Object
org.springframework.ai.openai.http.okhttp.SpringAiOpenAiHttpClient
- All Implemented Interfaces:
com.openai.core.http.HttpClient,AutoCloseable
public final class SpringAiOpenAiHttpClient
extends Object
implements com.openai.core.http.HttpClient
OkHttp-backed
HttpClient for the OpenAI 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 OpenAiOkHttpClient.Builder doesn't expose an interceptor seam —
see the SDK's Custom
HTTP client guide for the integration pattern.
Attribution: the body of this class is a Java port of OkHttpClient from
openai-java-client-okhttp (Apache License 2.0, authored by OpenAI). Only the
Micrometer wiring in SpringAiOpenAiHttpClient.Builder.build() is original to Spring AI.
- Since:
- 2.0.0
- Author:
- Soby Chacko, Ilayaperumal Gopinathan
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidclose()com.openai.core.http.HttpResponseexecute(com.openai.core.http.HttpRequest request, com.openai.core.RequestOptions requestOptions) CompletableFuture<com.openai.core.http.HttpResponse>executeAsync(com.openai.core.http.HttpRequest request, com.openai.core.RequestOptions requestOptions) okhttp3.OkHttpClientMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.openai.core.http.HttpClient
execute, executeAsync
-
Method Details
-
getOkHttpClient
public okhttp3.OkHttpClient getOkHttpClient() -
builder
-
execute
public com.openai.core.http.HttpResponse execute(com.openai.core.http.HttpRequest request, com.openai.core.RequestOptions requestOptions) - Specified by:
executein interfacecom.openai.core.http.HttpClient
-
executeAsync
public CompletableFuture<com.openai.core.http.HttpResponse> executeAsync(com.openai.core.http.HttpRequest request, com.openai.core.RequestOptions requestOptions) - Specified by:
executeAsyncin interfacecom.openai.core.http.HttpClient
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacecom.openai.core.http.HttpClient
-