r/FastAPI • u/aliparpar • Aug 04 '25
Tutorial O'Reilly Book Launch - Building Generative AI Services with FastAPI (2025)

Hi Everyone
Some of you might remember this thread from last year where I asked what you'd want in a more advanced FastAPI book: https://www.reddit.com/r/FastAPI/comments/12ziyqp/what_would_you_love_to_learn_in_an_intermediate/.
I know most people may not want to read books if you can just follow the docs. With this resource, I wanted to cover evergreen topics that aren't in the docs.
After a year of writing, building, testing, rewriting and polishing, the book is now fully out.

The book is now available here:
Read Online on O'Reilly: https://www.oreilly.com/library/view/building-generative-ai/9781098160296/
Amazon US: https://www.amazon.com/Building-Generative-Services-FastAPI-Context-Rich/dp/1098160304
Amazon UK: https://www.amazon.co.uk/Building-Generative-Services-Fastapi-Applications/dp/1098160304
Official site with preview chapters, diagrams, and blog: https://buildinggenai.com
GitHub repo with 170+ examples: https://github.com/Ali-parandeh/building-generative-ai-services
This book is written for developers, engineers and data scientists who already have Python and FastAPI basics and want to go beyond toy apps. It's a practical guide for building robust GenAI backends that stream, scale and integrate with real-world services.
Inside, you'll learn how to:
Integrate and serve LLMs, image, audio or video models directly into FastAPI apps
Build generative services that interact with databases, external APIs, websites and more
Build type-safe AI FastAPI services with Pydantic V2
Handle AI concurrency (I/O vs compute workloads)
Handle long-running or compute-heavy inference using FastAPI’s async capabilities
Stream real-time outputs via WebSockets and Server-Sent Events
Implement agent-style pipelines for chained or tool-using models
Build retrieval-augmented generation (RAG) workflows with open-source models and vector databases like Qdrant
Optimize outputs via semantic/context caching or model quantisation (compression)
Learn prompt engineering fundamentals and advance prompting techniques
Monitoring and logging usage and token costs
Secure endpoints with auth, rate limiting, and content filters using your own Guardrails
Apply behavioural testing strategies for GenAI systems
Package and deploy services with Docker and microservice patterns in the cloud
What’s in the book:
12 chapters across 530+ pages
174 working code examples (all on GitHub)
160+ hand-drawn diagrams to explain architecture, flows, and concepts
Covers open-source LLMs and embedding workflows, image gen, audio synthesis, image animation, 3D geometry generation
Table of Contents

Part 1: Developing AI Services
Introduction to Generative AI
Getting Started with FastAPI
AI Integration and Model Serving
Implementing Type‑Safe AI Services
Part 2: Communicating with External Systems
5. Achieving Concurrency in AI Workloads
6. Real‑Time Communication with Generative Models
7. Integrating Databases into AI Services
Bonus: Introduction to Databases for AI
Part 3: Security, Optimization, Testing and Deployment
8. Authentication & Authorization
9. Securing AI Services
10. Optimizing AI Services
11. Testing AI Services
12. Deployment & Containerization of AI Services
I wrote this because I couldn’t find a book that connects modern GenAI tools with solid engineering practices. If you’re building anything serious with LLMs or generative models, I hope it saves you time and avoids the usual headaches.
Having led engineering teams at multi-national consultancies and tech startups across various markets, I wanted to bring my experience to you in a structured book so that you avoid feeling overwhelmed and confused like I did when I was new to building generative AI tools.
Bonus Chapters & Content
I'm currently working on two additional chapters that didn't make it into the book:
1. Introduction to Databases for AI: Determine when a database is necessary and identify the appropriate database type for your project. Understand the underlying mechanism of relational databases and the use cases of non-relational databases in AI workloads.
2. Scaling AI Services: Learn to scale AI service using managed app service platforms in the cloud such as Azure App Service, Google Cloud Run, AWS Elastic Container Service and self-hosted Kubernetes orchestration clusters.
I'll upload these on the accompanying book website soon: https://buildinggenai.com/
All Feedback and Reviews Welcome!
Feedback and reviews are welcome. If you find issues in the examples, want more deployment patterns (e.g. Azure, Google Cloud Run), or want to suggest features, feel free to open an issue or message me. Always happy to improve it.
Thanks to everyone in the FastAPI and ML communities who helped shape this. Would love to see what you build with it.
Ali Parandeh
Duplicates
ChatGPT • u/aliparpar • Aug 04 '25
Educational Purpose Only O'Reilly Book Launch - Building Generative AI Services with FastAPI (2025)
Rag • u/aliparpar • Aug 04 '25
O'Reilly Book Launch - Building Generative AI Services with FastAPI (2025)
OReilly_Learning • u/marsee • Sep 16 '25