Skip to content

Spring AI

AiSupport implementation backed by Spring AI ChatClient. When this JAR is on the classpath, @AiEndpoint automatically uses Spring AI for streaming.

<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-spring-ai</artifactId>
<version>LATEST</version> <!-- check Maven Central for latest -->
</dependency>

Drop the dependency alongside atmosphere-ai and the framework auto-detects it via ServiceLoader:

@AiEndpoint(path = "/ai/chat", systemPrompt = "You are a helpful assistant")
public class MyChat {
@Prompt
public void onPrompt(String message, StreamingSession session) {
session.stream(message); // uses Spring AI ChatClient automatically
}
}

No code changes needed — the SpringAiSupport implementation has priority 100, which takes precedence over the built-in client (priority 0).

For full control, use SpringAiStreamingAdapter directly:

var session = StreamingSessions.start(resource);
springAiAdapter.stream(chatClient, prompt, session);

With advisors:

springAiAdapter.stream(chatClient, prompt, session, myAdvisor);

With a customizer:

springAiAdapter.stream(chatClient, prompt, session, spec -> {
spec.system("Custom system prompt");
});

AtmosphereSpringAiAutoConfiguration provides:

  • SpringAiStreamingAdapter bean
  • SpringAiSupport bridge bean (connects Spring-managed ChatClient to the SPI)

The ChatClient bean must be configured separately via Spring AI’s own starter.