the placement of the version number within endpoints varies among providers.

currently, OpenAiApi includes the version number in the paths: "/v1/chat/completions" and "/v1/embeddings", rather than in the base url. however, many OpenAI compatible providers place the version number differently, e.g.:

  • Gemini: https://generativelanguage.googleapis.com/v1beta/openai
  • Cloudflare: https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai

although it is possible to configure both base-url and completions-path in properties, this requires additional consideration when creating multiple chat clients. the constructor OpenAiApi(String baseUrl, String apiKey) is insufficient, while OpenAiApi(String baseUrl, String apiKey, String completionsPath, String embeddingsPath, RestClient.Builder restClientBuilder, WebClient.Builder webClientBuilder, ResponseErrorHandler responseErrorHandler) is somewhat overly complex.

Comment From: ThomasVitale

In the latest version of Spring AI (1.0.0-M6), you can use the OpenAiApi.Builder for convenience:

var openAiApi = OpenAiApi.builder()
    .apiKey("")
    .baseUrl("")
    .completionsPath("")
    .embeddingsPath("")
    .build();