Class OpenAiSetup

java.lang.Object
org.springframework.ai.openai.setup.OpenAiSetup

public final class OpenAiSetup extends Object
Helps configure the OpenAI Java SDK, depending on the platform used. This code is inspired by LangChain4j's `dev.langchain4j.model.openaiofficial.InternalOpenAiOfficialHelper` class, which is coded by the same author (Julien Dubois, from Microsoft).
Author:
Julien Dubois
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    detectModelProvider(boolean isMicrosoftFoundry, boolean isGitHubModels, @Nullable String baseUrl, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAIServiceVersion)
     
    static com.openai.client.OpenAIClientAsync
    setupAsyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String,String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor)
     
    static com.openai.client.OpenAIClient
    setupSyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String,String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor)
    Sets up a synchronous OpenAI client.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setupSyncClient

      public static com.openai.client.OpenAIClient setupSyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String,String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor)
      Sets up a synchronous OpenAI client.

      When apiKey is an empty string, the client is configured in no-auth mode: no Authorization header is sent with any request. This is useful for connecting to custom OpenAI-compatible servers that use cookie-based or other non-bearer-token authentication. To enable this mode, set spring.ai.openai.api-key= (empty value) in your application properties, or pass a NoopApiKey via AbstractOpenAiOptions.AbstractBuilder.apiKey(org.springframework.ai.model.ApiKey).

    • setupAsyncClient

      public static com.openai.client.OpenAIClientAsync setupAsyncClient(@Nullable String baseUrl, @Nullable String apiKey, @Nullable com.openai.credential.Credential credential, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAiServiceVersion, @Nullable String organizationId, boolean isAzure, boolean isGitHubModels, @Nullable String modelName, Duration timeout, int maxRetries, @Nullable Proxy proxy, @Nullable Map<String,String> customHeaders, io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable io.micrometer.core.instrument.MeterRegistry meterRegistry, @Nullable ExecutorService dispatcherExecutor)
    • detectModelProvider

      public static OpenAiSetup.ModelProvider detectModelProvider(boolean isMicrosoftFoundry, boolean isGitHubModels, @Nullable String baseUrl, @Nullable String azureDeploymentName, @Nullable com.openai.azure.AzureOpenAIServiceVersion azureOpenAIServiceVersion)