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

Show parent comment

1

u/stocktradernoob Dec 30 '25

What do u mean re not mingling AI models in backend code?

4

u/[deleted] Dec 30 '25

Deploy the model apart from the backend code. For example, using something like Amazon Sagemaker for the model and from there use EC2 machines to run the backend and call the AI model. This way you can also build the backend in a different programming language if you need it.

1

u/[deleted] Dec 30 '25

Nice