🌱 AI Engineering · Your First AI App · cozy lesson
Making Your First LLM API Call
12 min · 1 min read · no scary math, promise
🤖
You’ve got this. Read a little, play a little — I’ll wait. No rush.
Code
import os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
out = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role":"system","content":"Be concise. Answer only from context."},
{"role":"user","content":"Summarize RAG in 2 lines."}
],
temperature=0.2,
)
print(out.choices[0].message.content)
Add timeout, retry on 429/5xx, log usage. Next: tune temperature/top-p.
💛 Enjoying? Try 5 playful quizzes or watch it move.
Check your understanding
Correct answers earn XP (once each).
1. Where to keep keys?
2. System message is for…
My notes (saved in this browser)
Select text above → Save selection, or write your own. AlgoMaster-style notebook, local-first for MVP.
No notes yet. Your highlights will live here.
Finished reading? Seal it with a tick ✅
The checkbox in the explorer turns green too — same progress.