Bug description All of the Beans in the OpenAiAutoConfiguration class that require an API key have an option to disable the particular bean with the @ConditionalOnProperty with the exception of the OpenAiModerationModel. This has two potential issues:

  • Inconsistent AutoConfiguration pattern as all of the other Client or Model beans support an enabled property.
  • If I want to use constructs/classes in the OpenAI library but do not necessarily need a client connection (i.e. I don't need to set the apiKey), I cannot load my application without setting a bogus API key. The alternative is to disable AutoConfiguration for this class, but are scenarios where I still may want to auto configure a particular client.

Environment Spring Boot 3.4.x and spring-ai M6.

Steps to reproduce Set the enabled flag for all models and client to false and do not set an apiKey (do not disable auto configuration). The application will crash with the following error:

OpenAI API key must be set. Use the connection property: spring.ai.openai.api-key or spring.ai.openai.moderation.api-key property

Expected behavior I would expect there to be a consistent pattern for disabling the moderation client. Something like:

spring:
  ai:
    openai:
      moderation:
        enabled: false

Minimal Complete Reproducible example Please provide a failing test or a minimal complete verifiable example that reproduces the issue. Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

Just create a trivial SpringBootApplication with the OpenAI starter. Use the following application.yaml.

spring:
  ai:
    openai:
      chat:
        enabled: false 
      embedding:
        enabled: false
      image:
        enabled: false
      audio:
        transcription:
          enabled: false
        speech:
          enabled: false