Skip to content

OpenAiAutoConfiguration does not recognize the API Key configured via property key: 'spring.ai.openai.image.api-key' #1818

Open
@hardikSinghBehl

Description

@hardikSinghBehl

Bug description
When only an ImageModel bean is needed, while configuring the OpenAI API key via the below property:

spring:
  ai:
    openai:
      image:
        api-key: ${OPENAI_API_KEY}

I got the below error:

Caused by: java.lang.IllegalArgumentException: OpenAI API key must be set. Use the connection property: spring.ai.openai.api-key or spring.ai.openai.chat.api-key property.

The error persisted when I tried disabling the chat client autoconfiguration using:

spring:
  ai:
    chat:
      client:
        enabled: false

Ended up using the spring.ai.openai.api-key property to resolve the startup exception but the former key should've worked as well.

Environment
Using the Spring AI version : 1.0.0-M4 with Java 23

Expected behavior
The expectation of having the API key recognized when configured through the property spring.ai.openai.image.api-key was not met.

Steps to reproduce and Minimal Complete Reproducible example
Reproducible example can be found here. Execute the below command to get the exception:

OPENAI_API_KEY="api-key-goes-here" mvn test -Dtest=ImageGeneratorLiveTest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions