Building a FastAPI Interface for the Model Registry
Study Log
July 16, 2026Python, FastAPI, AI Engineering, MLOps, Pydantic

Building a FastAPI Interface for the Model Registry

Today the model registry I've been building has received its first HTTP interface with five endpoints: register, list, get, promote, and infer. After carefully building the BaseModel ABC, ModelMetadata, and ModelRegistry classes to work seamlessly with each other, running uvicorn model_registry.api:app --reload and opening /docs to see the entire system working interactively was genuinely satisfying.

The more interesting moment of today came from a bug. FastAPI's JSON encoder tried to serialize a ModelMetadata instance directly and failed with vars() argument must have __dict__ attribute. I quickly remembered why the model objects didn't have a __dict__: The __slots__ I implemented on my fourth post removed __dict__ to improve computing efficiency, so any library trying to serialize the objects using it would break.

While my first intuition was to undo __slots__, I quickly remembered that I shouldn't expose raw domain objects to the HTTP layer anyways. Instead, I implemented a simple function to convert a model's metadata to a Pydantic ModelResponse and applied it to all endpoints. This way, we keep the domain layer and the API layer separate, and FastAPI only sees Pydantic models it knows how to serialize.

I was surprised by how the recent things I've been working on started showing up at once. The asynchronous interface endpoints, exception handling patterns, ABC contracts, and overwritten dunder methods all came together in this HTTP interface.

Back to Study Log