The Spring AI project provides a Spring-friendly API and abstractions for developing AI applications.
Its goal is to apply Spring ecosystem design principles, such as portability and modular design, to the AI domain and promote using strongly-typed data structures and APIs 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.
Create a project on start.spring.io with the Spring Web and OpenAI dependencies, set the spring.ai.openai.api-key property, and inject the auto-configured ChatClient.Builder:
@RestController
class ChatController {
private final ChatClient chatClient;
ChatController(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
}
@GetMapping("/ai")
String ask(@RequestParam(defaultValue = "Tell me a joke") String message) {
return this.chatClient.prompt()
.user(message)
.call()
.content();
}
}The Quickstart explains each step and runs the same code against a local model. From there, continue with:
- Project Setup - the BOM, the starters and the repositories.
- Choosing a Model Provider - what each provider supports.
- The tutorials: Chat with Your Documents, Give the Model Tools, A Conversational App with Sessions and Build and Use an MCP Server.
Spring Boot version compatibility:
| Spring AI | Branch | Spring Boot |
|---|---|---|
| 2.1.x | main | 4.2.x |
| 2.0.x | 2.0.x | 4.1.x |
| 1.1.x | 1.1.x | 3.5.x |
This is a high level feature overview. The reference documentation follows the same structure.
- ChatClient - Fluent API for communicating with AI chat models, with synchronous and streaming calls, idiomatically similar to the WebClient and RestClient APIs.
- Advisors - Encapsulate recurring generative AI patterns, transform the data sent to and from the model, and provide portability across models and use cases.
- Prompts and Templates - Messages, prompt templates and prompt engineering patterns.
- Structured Output - Mapping of AI model output to POJOs.
- 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, with Tool Search for large tool sets and Tool Call Confirmation to let a person approve a call.
- Memory - The Session API keeps a conversation as an append-only log of events, with turn-aware compaction, recall and a JDBC repository.
- Agents - The advisor chain of a
ChatClientand its tools form the agent harness, with examples of the common workflow patterns.
- Portable Model APIs across AI providers:
- Support for all major AI Model providers such as Anthropic, OpenAI, Amazon Bedrock, Google, Ollama, Mistral AI, DeepSeek, and more. Access to model-specific features is also available.
- Support for all major Vector Store providers such as Amazon Bedrock Knowledge Base, Amazon S3, Apache Cassandra, Azure Vector Search, Chroma, Couchbase, Elasticsearch, GemFire, MariaDB, Milvus, MongoDB Atlas, Neo4j, OpenSearch, Oracle, Oracle Coherence, PostgreSQL/PGVector, Pinecone, Qdrant, Redis, Typesense, and Weaviate.
- Portable Vector Store API across providers, including a novel SQL-like metadata filter API.
- Document ingestion ETL framework for Data Engineering, with document readers for PDF, Markdown, HTML, Office formats and more.
- Retrieval Augmented Generation (RAG) - Out-of-the-box RAG flows as advisors, and a modular architecture to build your own.
- Semantic Caching - Returns a cached response to a semantically similar request.
- MCP (Model Context Protocol) - First-class support via 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.
- Observability - Metrics and traces for the
ChatClient, advisors, models, tool calls and vector stores. - Evaluation and Testing - Utilities to help evaluate generated content and protect against hallucinated responses, with Testcontainers and Docker Compose support.
- Resilience and Safety - Retry of failed model calls, and guardrails for unwanted content.
- 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.
- Community-maintained projects add agent tools, MCP security, agent protocols and more model and vector store integrations. They follow their own release schedule and support terms, which that page describes.
- Reference documentation
- Javadoc
- Upgrade notes
- Modules and Starters - Every artifact, with its auto-configuration and starter.
- Samples and Workshops
- Spring AI Examples - Contains example projects that explain specific features in more detail.
- Awesome Spring AI - A curated list of awesome resources, tools, tutorials, and projects for building generative AI applications using Spring AI
- Spring AI Community - A community-driven organization for building Spring-based integrations with AI models, agents, vector databases, and more.
You don’t need to build from source to use Spring AI. If you want to try out the latest and greatest, Spring AI can be built and published to your local Maven repository:
./mvnw clean installThis command builds all modules, runs unit tests, and publishes artifacts to your local Maven repository.
Please read our contribution guidelines for more details.
We welcome contributions of all kinds! Please read our contribution guidelines before submitting a pull request or an issue.