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.
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
