Spring AI OpenAI starter connects a Spring Boot application to OpenAI models through a Spring AI abstraction. It supplies autoconfiguration for ChatClient.Builder, so an application can inject a builder, create a ChatClient, and submit prompts without implementing the underlying REST exchange directly. section 1.2 section 1.2.1
A minimal project setup includes:
- Add implementation 'org.springframework.ai:spring-ai-starter-model-openai' alongside Spring Web. section 1.1.1 section 1.2.1
- Manage Spring AI versions with the Spring AI BOM; the demonstrated project uses Spring AI 1.0.3. section 1.1.1
- Provide an OpenAI API key through spring.ai.openai.api-key or the OPENAI_API_KEY environment variable. section 6.1.1 section 4.3.1
The default model is GPT-4o mini. Select another OpenAI model, such as GPT-4.1 or GPT-4.1 nano, with spring.ai.openai.chat.options.model. The same starter can also target many mostly OpenAI-compatible APIs, while Azure OpenAI requires a separate starter and provider-specific settings. section 1.2 section 1.2.1
Board Game Buddy and time lookup
A Board Game Buddy application uses the starter to answer questions about tabletop games. A separate time application injects ChatClient.Builder, builds a ChatClient, and exposes a /time endpoint; adding a @Tool method lets the model obtain current time from Java time-zone data instead of guessing. section 1.1.1 section 6.1.1
Listing 1.1 The Gradle build file for our project
plugins {
id 'java'
id 'org.springframework.boot' version '3.5.5'
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(24)
}
}
repositories {
mavenCentral()
}
ext {
set('springAiVersion', "1.0.3") #1
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.ai:spring-ai-starter-model-openai'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
dependencyManagement {
imports {
mavenBom "org.springframework.ai:spring-ai-bom:${springAiVersion}" #2
}
}
tasks.named('test') {
useJUnitPlatform()
}
Use the Gradle build listing to inspect the starter dependency, Spring AI BOM, Spring Boot version, and Java toolchain together. section 1.1.1
