How to Use Spring AI with OpenAI

Ruby Valappil
Published in
3 min readJan 7, 2024


A simple implementation in Spring Boot

Photo by Kim Menikh on Unsplash

OpenAI is not a new name.

People often use the name synonymously with ChatGPT but at least those working in the tech world know what each one of these are.

So, when I first heard that Spring Boot has released an experimental library to support OpenAI APIs I wanted to give it a try. By the time I actually gave it a try, it was not experimental but available as a starter library.

As of today, we can integrate our Spring AI project with OpenAI or Azure OpenAPI.

In any case, we need an account with these firms that would then give us a unique API key.

In this project, I’m opting for OpenAI and not the Azure flavor of it but you are free to pick your favorite 😄

Installation and Setup

  1. As always we would need a system with Java installed.
  2. We would create a new SpringBoot project.

3. Add the following dependencies in pom.xml file