r/FastAPI • • Dec 30 '25

Question FastAPI + Pydantic V2: Is anyone else using it to build AI microservices?

Hey r/FastAPI community!

I’ve been diving deep into FastAPI lately, especially with Pydantic V2 and its shiny new features (like computed fields and strict validation). With the AI/LLM boom happening right now, I’ve started building async microservices for AI pipelines things like prompt chaining, RAG systems, and real-time inference endpoints.What I’ve noticed: FastAPI’s native async support + Pydantic V2’s performance feels perfect for handling streaming responses from models likeOpenAI, Llama, etc. Dependency injection makes it super clean to manage API keys, model clients, and context caching. But… I’m curious how others are structuring their projects.

Questions for you all:

  1. Are you using FastAPI for AI/ML services? If yes, what does your stack look like?
  2. Any cool tips for integrating with message queues e.g., Celery, RabbitMQ, Kafka for async task handling?
  3. What’s your take on scaling WebSockets in FastAPI for real-time AI responses?
52 Upvotes

32 comments sorted by

View all comments

26

u/gob_magic Dec 30 '25

Yup. Same. FastAPI, Pydantic 2, SQLAlchemy 2, Redis for cache and all on docker with a clean CI/CD deployment.

Groq for LLM API.

No Langchain.

Traceability and Observability are in progress

3

u/pyhannes Dec 31 '25

I'm using Prefect for task execution and observability including the new Prefect PydanticAI integration. Quite nice!

1

u/ArtofRemo Jan 01 '26

do you use prefect instead of Celery/RabbitMQ setup and if so, how does it compare and integrate with your backend ? Ive looked into Prefect before and it felt OK but it couldn't sell me on offloading my jobsystem just yet. Thanks in advance, I feel most of us here are working on similar stacks..

2

u/pyhannes Jan 01 '26

Yes I removed celery and flower and replaced it by Prefect. Much easier to deploy workflows with different dependencies as your main app and much better observability.

2

u/swb_rise Dec 31 '25

Just API or there's frontend too?

2

u/gob_magic Dec 31 '25

Good question. Ideally static assets generated from React (pnpm, vite), Astro, etc. and deployed to Cloudflare pages or similar services.

Haven’t looked into HTMX yet.

1

u/BelottoBR Jan 03 '26

Quite a noob here but how to do it without langchain?!

1

u/gob_magic Jan 10 '26

It really depends on your use case. If langchain makes it easy why not. Or any other tool. My use case was chain of thought and simple tool use which can be coded by yourself after some experiments.

1

u/arbiter_rise Mar 05 '26

May I ask what the main reasons are for implementing Traceability and Observability?

2

u/gob_magic Mar 05 '26

Observability is to check if systems are up and running. What’s failing, keep an eye on things.

Traceability is tracking where exactly things went wrong. If my api calls 3 other api and runs two cpu processes and write to the db few times. I need to know what failed in the pipeline and why.

1

u/arbiter_rise Mar 05 '26

Ah, thanks for the explanation. My question earlier wasn’t very clear.

What I actually wanted to ask was how you set up observability for the LLM system. I’m particularly curious whether you integrated LLM observability with your existing application observability, or if you set them up as separate systems.