Spring Boot Quickstart
If you haven't yet got your first Spring Boot request working, start here.
1. The shortest success path
This page verifies exactly four things:
- Pull in
ai4j-spring-boot-starter - Configure
ai.*inapplication.yml - Inject
AiService - Issue your first
ChatCompletion
If these four steps hold, it means:
- The starter is in your project
- Auto-configuration has taken effect
- Configuration binding is working
- A usable AI4J Bean is already sitting in the container
2. Minimum dependency
The minimum dependency is just:
ai4j-spring-boot-starter
This path assumes the Core SDK has already been brought into the container by the starter; you don't need to manually reassemble the lower-level entry points.
3. Minimum configuration
ai:
openai:
api-key: ${OPENAI_API_KEY}
If your network environment requires a proxy, add ai.okhttp.* as well.
The core judgment at this step is not "have you memorized every field", but rather:
- Whether the configuration actually enters the Spring environment
- Whether the provider's minimum required fields are in place
4. Minimum invocation
@Autowired
private AiService aiService;
public String chatOnce(String userInput) throws Exception {
IChatService chatService = aiService.getChatService(PlatformType.OPENAI);
ChatCompletion req = ChatCompletion.builder()
.model("gpt-4o-mini")
.message(ChatMessage.withUser(userInput))
.build();
return chatService.chatCompletion(req)
.getChoices().get(0).getMessage().getContent().getText();
}
What this code actually verifies is:
- Spring has injected
AiService AiServicecan resolve a service byPlatformType- The first model request already runs inside a business Bean
5. Where to go next once it works
Continue in this order:
If you're not yet clear on the underlying capability boundaries, go back and fill in:
6. What to check first when it doesn't work
Check in this order:
- Whether the starter was actually pulled in
- Whether the
ai.*configuration is being read by Spring - Whether the API Key / network / proxy are working
- Whether you can't get the Bean at all, or you can get the Bean but the request fails
If it's a wiring-stage problem, revisit: