SkillsApr 1, 2026·1 min read

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.

TL;DR
Spring AI provides Spring-friendly APIs for building AI applications in Java with chat, embeddings, RAG, and function calling.
§01

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.

§02

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.

§03

How to use

  1. Add the Spring AI starter to your pom.xml or build.gradle.
  2. Configure your AI provider API key in application.properties.
  3. Inject the ChatClient or EmbeddingClient beans and use them in your services.
§04

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) {}
§05

Related on TokRepo

§06

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

What AI providers does Spring AI support?+

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.

Does Spring AI support RAG?+

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.

Can I use Spring AI with existing Spring Boot apps?+

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.

What is function calling in Spring AI?+

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.

Is Spring AI production-ready?+

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)
🙏

Source & Thanks

spring-projects/spring-ai — 8,400+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets