Skip to main content

Spring AI Learning Lab

Learn Spring AI by building. A hands-on repository for Java developers moving into AI engineering, starting with chat model integrations and growing toward more advanced topics.

Stack: Java / Spring Boot / Spring AI / LLMs

In progressLicence: see repository (opens in a new tab)

Modules

Chat Model Integrations

Integrate large language models into Java applications with Spring AI. The module has one small Spring Boot application per provider: OpenAI, Anthropic, AWS Bedrock, Groq and Ollama.

  • Spring AI fundamentals
  • Chat model integration
  • LLM provider configuration
  • Sending prompts and handling responses
  • Working with different model providers
  • Building AI-powered REST APIs

Run it

Get the code

git clone https://github.com/ayushstwt/spring-ai-learning-lab.git
cd spring-ai-learning-lab

Run the Ollama example

Needs Java 21 and Ollama running locally on port 11434. It uses a local model, so no API key is needed. The other provider folders run the same way once their environment variables are set.

ollama pull qwen2.5:1.5b
cd 01-chat-model-integrations/spring-ai-ollama
./mvnw spring-boot:run # Windows: .\mvnw.cmd spring-boot:run

Send a prompt

Run this from a second terminal.

curl "http://localhost:8080/api/chat?message=Hello"

Versions, from the build files: Java 21, Spring Boot 4.2.0, Spring AI 2.1.0.

Environment variables

Names only. Set them in your shell before starting the application that needs them.

NameWhat it does
OPENAI_API_KEYAPI key for the OpenAI example.
ANTHROPIC_API_KEYAPI key for the Anthropic example.
GROQ_API_KEYAPI key for the Groq example.
BEDROCK_MODEL_IDModel for the AWS Bedrock example. Required, with no default. AWS credentials are also needed.
AWS_REGIONRegion for the AWS Bedrock example. Default us-east-1.

API at a glance

MethodPathPurpose
GET/api/chat?message=...Send a prompt, get the reply as text (every example)

Why it exists

It is a place to learn Spring AI by running small, focused applications. Each provider example uses the same ChatClient controller, so you can compare what changes between providers: mainly the dependency and the configuration.