Skip to content

Conversation

@academey
Copy link
Contributor

Summary

  • Extract OpenAiApi creation to a separate @bean method
  • Update OpenAiChatModel to inject the OpenAiApi bean instead of creating it internally
  • Add test to verify OpenAiApi bean registration

Details

This PR addresses #3878 where OpenAiApi was not available for injection despite documentation suggesting it could be used to configure multiple OpenAI-compatible ChatClients.

Changes

  1. OpenAiChatAutoConfiguration.java:

    • Moved openAiApi from private method to public @Bean method
    • Updated openAiChatModel to inject the OpenAiApi bean
  2. OpenAiModelConfigurationTests.java:

    • Added import for OpenAiApi
    • Added verification that OpenAiApi bean is registered in chatModelActivation test
    • Added new test openAiApiBean to specifically test OpenAiApi bean injection

Testing

All existing tests pass, plus new test confirms OpenAiApi can be injected as a bean.

Fixes #3878

Signed-off-by: Hyunjoon Park [email protected]

- Extract OpenAiApi creation to a separate @bean method
- Update OpenAiChatModel to inject the OpenAiApi bean
- Add test to verify OpenAiApi bean registration

This allows users to inject OpenAiApi directly as suggested in the
documentation for configuring multiple OpenAI-compatible ChatClients.

Fixes spring-projects#3878

Signed-off-by: Hyunjoon Park <[email protected]>
@sobychacko
Copy link
Contributor

Merged via f41c27d and backported to 1.0.x.

@sobychacko sobychacko closed this Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAiApi object is not registered as a bean via AutoConfiguration

2 participants