liveBook · Manning

Spring AI

As explained in Spring AI in Action

Spring AI is a Java library that provides abstractions and integrations for incorporating generative AI capabilities into Spring applications.

Spring AI is a Spring and Spring Boot extension for adding generative AI capabilities to Java applications. Its central abstraction provides a consistent client interface across AI providers and models, hiding provider-specific request and response handling. section 1.0 section 1.1

Figure 1.1 Spring AI coordinates interaction with AI providers and models.
figure

Spring AI coordinates prompt submission and generated responses between an application and supported AI providers. section 1.1

A minimal application starts like any Spring Boot project: generate it with Spring Initializr, add Spring Web and an AI provider starter, and let Spring Boot autoconfiguration create the required components. A Spring AI BOM manages compatible Spring AI dependencies. section 1.1.1

Question-and-answer REST service

Inject ChatClient.Builder into a service and build a ChatClient. Construct a prompt with prompt().user(question).call().content(), wrap the generated text in an Answer record, and expose the service through a Spring MVC controller at POST /ask. Configure the provider credential through spring.ai.openai.api-key or the SPRING_AI_OPENAI_API_KEY environment variable. section 1.1.2

Spring AI extends the basic client abstraction with:

  • Provider integrations for OpenAI, Azure OpenAI, Anthropic, MistralAI, Google, Amazon Bedrock, and locally served Ollama models. section 1.4 section 1.2.2
  • Model and generation controls through application properties, ChatClient default options, or prompt-level options. section 3.4.1
  • Prompt templates, conversation history, retrieval-augmented generation, tools, Model Context Protocol, audio transcription, speech generation, image understanding, and image generation. section 1.3 section 8.4
  • Tool-driven generation, where the model requests a tool call, the application executes it, and the result returns to the model for a final response. section 6.1.2

How Spring AI in Action covers it

How deep it goes
Explains setup, configuration, ChatClient usage, provider selection, generation options, and advanced integrations beyond basic prompt-response calls.
Examples
Demonstrates a Board Game Buddy question service, OpenAI and Ollama configuration, curl and HTTPie requests, and a current-time tool call.
What it assumes
Assumes Java and Spring Boot application development; teaches provider configuration, prompt submission, and model selection through an incremental application.
What you can do after
Build it from scratch as a Spring Boot REST service using ChatClient, selectable providers, configurable models, and application-integrated tools.
How it connects
Connects Spring Boot, LLMs, REST APIs, prompt templates, chat history, retrieval-augmented generation, tool calling, MCP, and multimodal AI.

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.