Skip to main content

Spring Boot Overview

ai4j-spring-boot-starter wires the Core SDK into Spring Boot's configuration, Bean lifecycle, and business layering. It is not a new AI implementation, nor is it a mandatory entry point — if you are not on a Spring project, start directly with the Core SDK.

In one sentence

The Spring Boot starter solves:

Inside a Spring Boot application, manage AI4J's model services, service registry, HTTP client, RAG components, and extension points through configuration and Beans.

It handles "wiring into the Spring container"; it does not redefine the underlying semantics of Chat, Responses, Tool, MCP, or RAG.

When to use the starter

ScenarioFits?
Validate a model call from a plain Java main method firstNo starter needed
Existing Spring Boot project, config-driven model integrationFits
Need Bean injection of AiService or AiServiceRegistryFits
Need multi-provider / multi-instance configurationFits
Need to override the HTTP client, service, or RAG Beans on the business sideFits
Need Agent, Coding Agent, or FlowGramUnderstand the Core SDK first, then wire the corresponding upper-layer module

Minimum path

For a first integration, follow this order:

  1. Quickstart for Spring Boot
  2. Spring Boot Quickstart
  3. Auto Configuration
  4. Configuration Reference
  5. Bean Extension

Get a single provider working first, then consider the ai.platforms[] multi-instance registry.

What the starter auto-configures for you

CapabilityDescription
Configuration bindingReads ai.* configuration and maps it to configuration property objects
Unified service entry pointCreates or exposes AiService
Multi-instance registryManages multiple provider instances via AiServiceRegistry
HTTP clientUnifies OkHttp configuration, timeouts, and connection capabilities
Compatibility entry pointKeeps the legacy entry point or compatibility shim to help migrate old examples
RAG-related BeansWhen conditions are met, auto-configures vector, assembler, reranker, and other capabilities

The actual model protocol, Tool schema, MCP transport, and RAG ingestion still belong to the Core SDK.

Single instance and multi-instance

Single instance

Suitable for getting one provider working first:

ai:
openai:
api-key: ${OPENAI_API_KEY}
base-url: https://api.openai.com

Multi-instance

Suitable for managing multiple providers, multiple model configurations, or multiple tenant-level entry points at the same time:

ai:
platforms:
- id: primary-openai
type: OPENAI
api-key: ${OPENAI_API_KEY}
base-url: https://api.openai.com

Multi-instance is not an alias for the single-instance configuration. It enters the AiServiceRegistry mental model, and downstream business code should take services on demand by id.

Extension points

What you want to extendStart here
Override default BeansBean Extension
Inspect configuration optionsConfiguration Reference
Common business patternsCommon Patterns
Return to model and Tool semanticsCore SDK
Build a Spring-scoped solutionSolutions

Pre-launch checklist

  • key, baseUrl, and model are not hard-coded.
  • dev/test/prod configuration sources are distinguishable.
  • Single-instance and multi-instance are not mixed into ambiguous routing.
  • HTTP timeouts, proxies, logging, and error handling meet project requirements.
  • The override order of custom Beans is explainable.
  • Security boundaries for RAG, MCP, and Tool are still confirmed against their respective main lines.

Related pages:

Further reading

  1. Quickstart
  2. Auto Configuration
  3. Configuration Reference
  4. Bean Extension
  5. Common Patterns