liveBook · Manning

Spring AI OpenAI starter

As explained in Spring AI in Action

The Spring AI OpenAI integration is the Spring AI module that connects applications to OpenAI models and services.

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

How Spring AI in Action covers it

How deep it goes
Explains dependency setup, autoconfiguration, credentials, model selection, and provider differences, but stops short of implementing the underlying HTTP client.
Examples
Uses a Board Game Buddy application, GPT model selection, document embeddings, and a current-time tool exposed through a web endpoint.
What it assumes
Assumes a Spring Boot project and an API key while teaching dependency selection, configuration, ChatClient creation, and prompt submission explicitly.
What you can do after
Build Spring Boot applications that submit prompts, choose OpenAI models, access compatible providers, and supply tools or embeddings.
How it connects
Connects Spring Boot, Spring AI, ChatClient, OpenAI-compatible APIs, Azure OpenAI, embeddings, and tool calling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.