🌱SproutStack
👤 Guest

🌱 AI Engineering · Python for AI · cozy lesson

APIs, JSON and Pydantic

12 min · 1 min read · no scary math, promise

🤖
You’ve got this. Read a little, play a little — I’ll wait. No rush.

Flow

App → POST JSON → LLM → JSON back → validate → act.

import requests
from pydantic import BaseModel

class Ticket(BaseModel):
    title: str
    priority: str  # low|high

r = requests.post("https://api.example.com/chat",
  json={"messages": [{"role":"user","content":"hi"}]},
  headers={"Authorization": "Bearer $KEY"}, timeout=30)
data = Ticket.model_validate(r.json())  # throws if bad

Always: timeouts, retries with backoff, log status codes, never ship keys in frontend.

Check your understanding

Correct answers earn XP (once each).

1. Why Pydantic?

2. 401 vs 429?

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.