05.03

Response models and status codes

skillmaxingPython with AIResponse models and status codes
Visual lesson

Response models and status codes

Included with Pro · 4:16
Lessons · 1,028 words

A response has two parts a client reads before anything else: the status code, which says what kind of thing happened, and the body's shape, which says what to do with it. FastAPI lets you declare both on the route, and then enforces them. The return annotation becomes the response model, so whatever your function returns is validated and filtered through it. The status_code argument sets the success status, and HTTPException sets an error one.

The filtering is the part that matters for Relay. A ticket row in PostgreSQL will grow columns that clients must never see: an internal note, the embedding vector, the agent's scratchpad. A response model is the wall between the storage shape and the public shape.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online