FreeFoundations · 25 min · Beginner
🤖

Intro to LLM APIs

How AI models receive and respond to requests

💡

What Is Intro to LLM APIs?

Simple overview · Real-world examples included

No experience needed for this one — this is the starting point for everything. We will build the simplest possible AI-powered app: a Java Spring Boot server that receives a message from you and sends it to ChatGPT (or Claude), then returns the AI's answer. Think of your app as a "middleman" — it sits between the user and the AI. By the end of this topic, you will have a real working API endpoint you can test from any browser or tool like Postman.

🎯 What You'll Learn

How LLMs tokenize and process input
Request/response structure of OpenAI & Claude APIs
Build your first AI endpoint in Spring Boot
Handle errors, timeouts and rate limits

🌍 Real-World Use Case

A customer service portal that routes messages using AI classification

📊 How It Works — Interactive Flowchart

Hover nodes for quick tip · Click to open detail · Press "Run Data Flow" to animate

Click any box to learn what it does
🧑‍💻
You
Send message
Step 1
⚙️
Spring Boot
Your server
Step 2
🔢
Tokenizer
Text → Numbers
Step 3
🌐
API Call
To OpenAI
Step 4
🤖
AI Model
Generates text
Step 5
Response
Back to you
Step 6

🛠️ Step-by-Step Implementation

Click any step to expand · Check the circle to mark complete · Progress saves in your browser

Implementation ProgressClick ○ to mark a step complete
0 / 6
01
Set up Spring Boot project
💡 WHY AM I DOING THIS?

Spring Boot gives you a production-ready server in minutes. Without it you'd write hundreds of lines of boilerplate.

▶ WHAT HAPPENS IN THIS STEP

We create a new project using Spring Initializr with the Spring AI dependency.

📄 FILES TO CREATE / MODIFY
+pom.xml
+src/main/java/com/example/AiApplication.java
+src/main/resources/application.properties
📁 FOLDER STRUCTURE
ai-demo/
├── src/
│   ├── main/
│   │   ├── java/com/example/
│   │   │   ├── AiApplication.java
│   │   │   └── controller/
│   │   │       └── ChatController.java
│   │   └── resources/
│   │       └── application.properties
└── pom.xml
💻 CODE EXAMPLE
<!-- pom.xml -->
<dependency>
  <groupId>org.springframework.ai</groupId>
  <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
⚠ COMMON MISTAKES
Forgetting to add spring-ai BOM to dependencyManagement
Using Java 8 instead of Java 17+
▶ HOW TO TEST
Run: mvn spring-boot:run — should see "Started AiApplication" in logs
✅ EXPECTED RESULT
Server starts on http://localhost:8080 with no errors
02
Configure OpenAI API key
The API key authenticates your app with OpenAI
03
Create ChatClient bean
ChatClient is Spring AI's main interface to the LLM
04
Build REST controller
The controller exposes your AI as an HTTP endpoint
05
Add error handling
LLM APIs can fail — rate limits, network issues, invalid inputs
06
Test with Postman
Testing manually confirms everything works end-to-end before building a frontend

✍️ How to Write the Prompt for This Topic

System: "You are a helpful assistant." User: "Classify this message: {message}" — Start simple, then layer specifics.

🎯

Job Interview Prep

8 curated questions · 0 / 8 mastered
Click answers, then rate yourself to track progress
LEVEL:

💡 Don't memorise answers word-for-word. Understand the concept, then explain it in your own words using a real example from this topic's project — that's what impresses interviewers.

⚡ Live AI Demo

LIVE AI DEMO — CLAUDE HAIKUSign up for 3 free demos/day
0/500

📦 Clone & Run the Sample Project

📦
github.com / ai-dev-academy / ai-dev-academy-projects

01-intro-to-llm-apis

Hello AI — Spring Boot REST endpoint calling OpenAI

Spring Boot 3.xOpenAI APIMavenJava 17
QUICK START — RUN IN 5 STEPS
1
Clone the full repo
git clone https://github.com/ai-dev-academy/ai-dev-academy-projects.git
2
Enter the topic folder
cd ai-dev-academy-projects/01-intro-to-llm-apis
3
Set up your API key
cp .env.example .env
# Then open .env and add your API key
4
Run the project
mvn spring-boot:run
5
Test the endpoint
curl -X POST http://localhost:8080/ai/chat \
  -H "Content-Type: application/json" \
  -d '"Hello, what is Intro to LLM APIs?"'
OPEN IN YOUR IDE
← DashboardAll Topics →