Spring AI is an application framework for AI engineering.
Its goal is to apply Spring ecosystem design principles, such as portability and modular design, to the AI domain, and to promote using POJOs as the building blocks of an application.
At its core, Spring AI addresses the fundamental challenge of AI integration: Connecting your enterprise Data and APIs with the AI Models.
Features
Spring AI provides the following features:
ChatClient
ChatClient API - Fluent API for communicating with AI Chat Models, with synchronous and streaming calls, idiomatically similar to the WebClient and RestClient APIs.
Advisors API - Encapsulates recurring Generative AI patterns, transforms data sent to and from Language Models (LLMs), and provides portability across various models and use cases.
Multimodality - Images, audio and other media next to text in a message.
Tool Calling - Permits the model to request the execution of client-side tools and functions, thereby accessing necessary real-time information as required. Tool Search handles large tool sets, and Tool Call Confirmation lets a person approve a call.
Session API - Keeps a conversation as an append-only log of events, with turn-aware compaction, recall and a JDBC repository. It replaces the deprecated Chat Memory.
Agent workflow patterns - Worked examples of the common agentic patterns, built with the ChatClient and its tools.
Models
Support for all major AI Model providers such as Anthropic, OpenAI, Amazon Bedrock, Google, Ollama, Mistral AI, and DeepSeek. Supported model types include:
MCP (Model Context Protocol) - Boot Starters and MCP Java Annotations for building AI applications that consume MCP servers or expose Spring-based services to the AI ecosystem, for both the modern and the legacy generation of the protocol.
Across the Application
Observability - Provides insights into AI-related operations.
AI Model Evaluation - Utilities to help evaluate generated content and protect against hallucinated responses.
Spring Boot Auto Configuration and Starters for all AI Models and Vector Stores - use start.spring.io to select the Model or Vector Store of choice.
This feature set lets you implement common use cases such as "Q&A over your documentation" or "Chat with your documentation."
Create a Spring Boot Web application with a Spring AI OpenAI boot starter dependency. This Spring Initializr link can help you bootstrap the application.
(With start.spring.io you can select any AI Models or Vector Stores that you want to use in your new applications).
Add your OpenAI key to the application.properties:
spring.ai.openai.api-key=<YOUR OPENAI KEY>
Add the following snippet to your SpringAiDemoApplication class:
@Bean
public CommandLineRunner runner(ChatClient.Builder builder) {
return args -> {
ChatClient chatClient = builder.build();
String response = chatClient.prompt("Tell me a joke").call().content();
System.out.println(response);
};
}
Run the application:
./mvnw spring-boot:run
Want to get started in another way? View the Getting Started section in the reference documentation.