Spring AI — AI Engineering for Java/Spring
Spring AI provides Spring-friendly APIs for AI apps. 8.4K+ stars. Chat, embeddings, RAG, vector DBs, function calling. Major providers. Apache 2.0.
What it is
Spring AI is a framework that brings AI engineering capabilities to Java and Spring Boot applications. It provides Spring-friendly APIs for chat completions, embeddings, retrieval-augmented generation (RAG), vector database integration, function calling, and structured output parsing. It supports major AI providers including OpenAI, Anthropic Claude, Google Gemini, Mistral, Ollama, and Azure OpenAI.
Spring AI is for Java developers and enterprise teams who want to add AI capabilities to existing Spring Boot applications. If your backend is Java and you need to integrate LLMs, build RAG pipelines, or add AI-powered features, Spring AI provides familiar Spring patterns (auto-configuration, dependency injection, properties) for AI integration.
How it saves time or tokens
Spring AI abstracts provider-specific APIs behind a common interface. Switch from OpenAI to Anthropic by changing a configuration property, not your code. The auto-configuration handles client setup, retry logic, and rate limiting. RAG support with built-in vector store integrations (PGVector, Chroma, Pinecone, Milvus) means you wire up retrieval without writing embedding pipeline code from scratch. Spring Boot starters reduce AI integration to adding a dependency and setting an API key.
How to use
- Add the Spring AI starter to your pom.xml or build.gradle.
- Configure your AI provider API key in application.properties.
- Inject the ChatClient or EmbeddingClient beans and use them in your services.
Example
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
@RestController
public class AiController {
private final ChatClient chatClient;
public AiController(ChatClient.Builder builder) {
this.chatClient = builder.build();
}
@GetMapping("/ask")
public String ask(@RequestParam String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
@GetMapping("/structured")
public Movie recommend(@RequestParam String genre) {
return chatClient.prompt()
.user("Recommend a " + genre + " movie")
.call()
.entity(Movie.class);
}
}
record Movie(String title, int year, String director) {}
Related on TokRepo
- AI tools for coding -- developer tools for AI integration
- AI tools for API -- API integration frameworks
Common pitfalls
- Hardcoding the AI provider instead of using the abstraction layer. Spring AI's value is provider portability. Program against the ChatClient interface so you can switch providers by changing configuration.
- Not configuring retry and rate limiting. AI provider APIs have rate limits. Use Spring AI's built-in retry configuration to handle transient failures gracefully.
- Ignoring structured output parsing. Instead of parsing LLM responses manually, use
.entity(MyClass.class)to get typed Java objects. This reduces parsing bugs and makes AI responses type-safe.
Frequently Asked Questions
Spring AI supports OpenAI, Anthropic Claude, Google Gemini, Mistral, Amazon Bedrock, Azure OpenAI, Ollama (local models), and more. Each provider has a dedicated Spring Boot starter for auto-configuration.
Yes. Spring AI provides a complete RAG pipeline with document readers, text splitters, embedding clients, and vector store integrations. Supported vector stores include PGVector, Chroma, Pinecone, Milvus, Qdrant, and Weaviate.
Yes. Spring AI is designed as an add-on to existing Spring Boot applications. Add the starter dependency, configure the API key, and inject AI clients into your existing services using standard Spring dependency injection.
Function calling lets the AI model invoke Java methods based on the conversation. You register Java functions that the model can call to get real-time data, perform calculations, or interact with your systems. Spring AI handles the serialization and invocation.
Spring AI reached 1.0 GA status and is used in production by organizations running Spring Boot. It follows Spring's stability and backward compatibility standards. The Apache 2.0 license allows unrestricted commercial use.
Citations (3)
- Spring AI GitHub— Spring AI provides Spring-friendly APIs for AI applications
- Spring AI Documentation— Supports OpenAI, Anthropic, Google, Mistral, and more
- Spring AI Vector Store Docs— Vector store integrations for RAG pipelines
Related on TokRepo
Source & Thanks
spring-projects/spring-ai — 8,400+ GitHub stars
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.