Build Your First Spring AI Application with OpenAI Using Spring Boot A developer demonstrates how to build a Spring AI application using OpenAI with Spring Boot, covering project setup, configuration, and creating a REST API that sends prompts to an AI model. The tutorial walks through connecting Spring Boot to OpenAI, using the ChatClient and ChatModel abstractions, and emphasizes secure API key handling. The result is a working AI-powered Spring Boot endpoint that returns AI responses. If you have been following this Spring AI series, you already understand the two most important abstractions: ChatClient and ChatModel . In the previous article, we learned that: Your Java Code | v ChatClient | v ChatModel | v AI Provider ChatClient gives us a developer-friendly API, while ChatModel handles the underlying model integration. Now it is time to build something real. In this article, we will build our first Spring AI application using OpenAI . We will start from project setup and configuration, connect Spring Boot to OpenAI, create a REST API, send prompts to an AI model, and understand what happens behind the scenes. By the end, you will have a working AI-powered Spring Boot API. Our application will expose a simple REST endpoint: GET /api/chat?message=Explain dependency injection The flow will look like this: Client | v Spring Boot REST API | v ChatClient | v ChatModel | v OpenAI | v AI Response The goal is intentionally simple. We want to understand the complete flow before adding more advanced concepts such as RAG, tools, memory, structured output, and AI agents. Before starting, you should have: You should also be comfortable with dependency injection and creating REST controllers. If you have followed the previous articles in this series, most of this should already be familiar. The easiest way to create the project is through Spring Initializr. Choose: Project: Maven Language: Java Spring Boot: Your compatible Spring Boot version Packaging: Jar Java: 17 or later For dependencies, we need Spring Web and the Spring AI OpenAI starter. Your project will eventually look something like: spring-ai-openai-demo │ ├── src │ ├── main │ │ ├── java │ │ │ └── com.example.demo │ │ │ └── DemoApplication.java │ │ │ │ │ └── resources │ │ └── application.properties │ └── pom.xml Add the Spring AI OpenAI model starter to your Maven configuration. For example: