Start studying
Module 14 · MLOps / LLMOps Module contents
Module 14  ·  Card 2 / 22beginner

FastAPI

FastAPI is the standard Python framework for serving models.

It is asynchronous, which suits the waiting-heavy nature of model calls.

Pydantic models define and validate request and response schemas.

Interactive API documentation is generated automatically.

Load the model once at startup, never per request.

Learn in depth ↓
Module 14 · MLOps / LLMOps · 22 concepts
In depth  /  15 lines

FastAPI, in more detail

FastAPI is the standard Python framework for putting a model behind an HTTP endpoint.

It is asynchronous, which matters because model serving is mostly waiting.

While one request waits on a GPU or an external API, others can be handled.

Pydantic models define the request and response schemas.

Validation is automatic, so a malformed request is rejected before your code runs.

Type hints drive that validation, so the schema and the code cannot drift apart.

Interactive documentation is generated from the same definitions.

That page is often the fastest way for another team to try your endpoint.

Load the model once at startup and keep it in memory.

Loading it per request is the classic mistake and makes everything unusably slow.

Use the lifespan hook so the model is ready before traffic arrives.

Blocking calls inside an async endpoint stall the whole event loop.

Push heavy synchronous work to a thread pool or a background worker.

It runs under Uvicorn, and Gunicorn manages multiple workers in production.

Each worker holds its own copy of the model, which is the memory cost of that concurrency.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
Why load the model at application startup rather than per request?
MLOps / LLMOps

22 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close