Skip to content

Conversation

@ghtjr410
Copy link

@ghtjr410 ghtjr410 commented Jan 9, 2026

Issue

Closes langchain4j/langchain4j#4286

Change

Add support for multiple named OpenAI chat models in Spring Boot starter.

Configuration

# Global settings (inherited by all named models)
langchain4j.open-ai.chat-model.api-key=${OPENAI_API_KEY}

# Named models
langchain4j.open-ai.chat-model.fast.model-name=gpt-4.1-mini
langchain4j.open-ai.chat-model.smart.model-name=gpt-5.2

Usage

@AiService(wiringMode = EXPLICIT, chatModel = "openAiChatModelFast")
interface FastAssistant { }

@AiService(wiringMode = EXPLICIT, chatModel = "openAiChatModelSmart")
interface SmartAssistant { }

Implementation

  • Uses BeanDefinitionRegistryPostProcessor to dynamically register named model beans
  • Scans Environment for unknown property keys under chat-model.* prefix
  • Supports global property inheritance (api-key, base-url, etc.)
  • No changes to Properties.java - 100% backwards compatible
  • Named models support ChatModelListener callbacks and Spring RestClient integration

Bean Naming Convention

Configuration Bean Name
chat-model.fast.* openAiChatModelFast
chat-model.4-1-mini.* openAiChatModel41Mini

General checklist

  • There are no breaking changes
  • I have added unit and/or integration tests for my change
  • The tests cover both positive and negative cases
  • I have manually run all the unit and integration tests in the module I have added/changed, and they are all green
  • I have added/updated the documentation
  • I have added an example in the examples repo (only for "big" features)

Checklist for adding new Spring Boot starter

N/A - This PR modifies an existing starter.

@ghtjr410 ghtjr410 force-pushed the feature/4286-support-multiple-named-openai-models branch from 53db89b to 5a0dbf9 Compare January 9, 2026 00:46
@ghtjr410 ghtjr410 marked this pull request as ready for review January 9, 2026 04:10
@dliubarskyi
Copy link
Member

@ThomasVitale I would appreciate a review from you, if you have some spare time 🙏

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.

[FEATURE] Support multiple OpenAI models in the spring boot starter

2 participants