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
  • Method Details

    • getOkHttpClient

      public okhttp3.OkHttpClient getOkHttpClient()
    • builder

      public static SpringAiOpenAiHttpClient.Builder builder()
    • execute

      public com.openai.core.http.HttpResponse execute(com.openai.core.http.HttpRequest request, com.openai.core.RequestOptions requestOptions)
      Specified by:
      execute in interface com.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:
      executeAsync in interface com.openai.core.http.HttpClient
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface com.openai.core.http.HttpClient