Enterprise DNA

Omni by Enterprise DNA

Enterprise DNA Resources

Insights on data, AI & business. Practical AI operating-system thinking for owners, operators, and teams doing real work.

220k+

Data professionals

Omni

AI agents and apps

Audit

Map the manual work

FastAPI + LLMs: What Engineers Actually Found
Blog AI

FastAPI + LLMs: What Engineers Actually Found

FastAPI became the default LLM backend wrapper for a reason. Practitioners share what works, what breaks, and what it really costs in production.

Sam McKay

The Setup: Why FastAPI Became the Default LLM Wrapper

When OpenAI’s API went mainstream in early 2023, the Python community needed something to wrap streaming responses, validate payloads, and handle auth without writing a Flask app from scratch. FastAPI filled that gap almost immediately. A thread on r/LocalLLaMA from March 2023 had developers noting that within weeks of GPT-4’s release, most open source LLM projects on GitHub had migrated their serving layer to FastAPI. The reason was straightforward. Pydantic models gave you typed request and response schemas for free, async handlers handled streaming without blocking, and the OpenAPI docs meant frontend teams could integrate without asking backend for help.

By mid-2024, the pattern was so common that calling it a “FastAPI wrapper” almost felt redundant. LangChain’s server, LlamaIndex’s query endpoints, and most internal tools at startups followed the same template. A senior engineer on HN put it bluntly: “FastAPI is the new Flask for anything LLM related, and I don’t think that’s going to change soon.”

What Practitioners Expected vs What They Got

The expectation going in was that FastAPI would be invisible. You’d write a few endpoints, point them at an LLM provider, and the framework would handle the boring parts. For simple chat completions, that held up. The reality got more complicated once you put real traffic on it.

A common complaint on the FastAPI subreddit and the Python Discord centered on streaming behavior. Practitioners expected Server-Sent Events to “just work” because FastAPI’s docs make it look easy. What they got instead was a debugging session around uvicorn workers, response buffering, and proxy timeouts. One developer on r/FastAPI wrote a 600-word post explaining how nginx was buffering their SSE responses because the default proxy_buffering was on. Another noted that Cloudflare would silently drop streaming connections after 100 seconds unless you configured the right headers.

The second surprise was around async. FastAPI’s async story is genuinely good, but practitioners who tried to use synchronous LLM clients inside async endpoints learned the hard way that blocking calls would stall the event loop. A thread on HN from late 2024 had multiple engineers admitting they had rewritten endpoints after seeing p99 latency spike from 800ms to 30 seconds because a single sync SDK call was hogging the loop.

Where It Genuinely Delivers

Despite the rough edges, FastAPI handles the core LLM backend job well. Practitioners consistently report a few areas where it shines.

Latency overhead is minimal. A benchmark post on the FastAPI GitHub discussions showed that a simple chat endpoint with Pydantic validation added about 3 to 8 milliseconds of overhead compared to a raw aiohttp handler. For most LLM applications where the model itself takes 400 to 2000ms, that’s noise.

Streaming works once you configure it correctly. Teams that set up SSE properly report smooth token-by-token delivery with first-token latency in the 150 to 400ms range for OpenAI’s GPT-4o-mini and 300 to 700ms for Claude Sonnet. A practitioner blog from a YC-backed startup noted they were serving 200 concurrent streaming connections on a single 4-vCPU container without breaking a sweat.

Pydantic is genuinely useful for LLM I/O. The pattern of defining a typed request schema, validating it, and getting a typed response back saves real time. One developer on the Python subreddit estimated it cut their integration bugs by roughly 60 percent compared to their previous Flask setup where everything was dict[str, Any].

Cost transparency is easier. Because FastAPI makes middleware trivial, teams commonly add a token counting middleware that logs input and output tokens per request. A team at a mid-size SaaS company reported in a podcast that this simple middleware helped them catch a regression where a prompt change had doubled their token usage overnight. Without that visibility, the cost spike would have shown up only on the monthly bill.

Where It Falls Short

The honest list of complaints is longer than the marketing would suggest.

First, the dependency story is heavier than people expect. A typical FastAPI LLM service pulls in fastapi, uvicorn, pydantic, httpx, an LLM SDK like openai or anthropic, and usually a vector store client. A clean install lands around 180 to 250MB. For teams deploying to Lambda or small containers, that matters. One engineer on HN noted they switched to a slim FastAPI-less setup using just Starlette for a 60MB image.

Second, error handling around LLM providers is rougher than it should be. When OpenAI or Anthropic returns a 429 or a 500, FastAPI doesn’t give you much out of the box. Practitioners report writing custom exception handlers, retry middleware, and circuit breakers by hand. A thread on r/Python had developers sharing snippets of their retry logic because the ecosystem hasn’t settled on a standard pattern yet.

Third, observability is a DIY exercise. FastAPI ships with no built-in tracing, no metrics endpoint, and no request correlation IDs. Teams that want production-grade observability bolt on OpenTelemetry, Prometheus middleware, and structured logging. A backend lead at a fintech wrote a Medium post estimating they spent about two engineer-weeks getting proper tracing set up across their LLM endpoints.

Fourth, the streaming edge cases keep biting people. Practitioners on the FastAPI Discord regularly report issues with proxy buffering, with chunked transfer encoding being stripped by intermediaries, and with clients that don’t handle SSE well. A common workaround is to fall back to WebSockets or to send full responses when streaming fails. Both add complexity.

Finally, the cost surprises aren’t in FastAPI itself but in what it enables. When the framework makes it trivial to add new endpoints, teams tend to add a lot of them. A common pattern in retrospectives is “we shipped 40 endpoints in three months and only 8 of them get traffic.” Each unused endpoint still costs something in maintenance and in the tokens it consumes when called.

Who It Fits Best

FastAPI is the right call for a specific kind of team. Solo developers and small startups building LLM products where the team is 1 to 5 engineers will get the most leverage. The framework’s productivity wins compound when you’re moving fast and don’t have a dedicated platform team.

Mid-size teams with 10 to 50 engineers can also use FastAPI, but they typically need to invest in the observability and error handling layer that smaller teams skip. The teams that struggle are the ones that treat FastAPI as a finished product when it’s really a starting point.

Large enterprises with strict compliance requirements often pick something else. A few banks and healthcare companies on HN threads have noted they use internal frameworks on top of FastAPI or move to heavier solutions like Django + Celery for the audit trail and admin tooling.

For specific use cases, FastAPI works well for chat applications, document Q&A systems, internal copilots, and any LLM feature where request-response latency matters more than batch throughput. It works less well for high-volume batch processing, for long-running agentic workflows, and for anything that needs persistent state across requests.

Common Pairings and Replacements

The pairing that comes up most often in practitioner discussions is FastAPI plus Postgres plus pgvector for retrieval. It’s the default stack for RAG applications and shows up in roughly 70 percent of the open source LLM projects on GitHub that get discussed in those communities.

For async task handling, teams pair FastAPI with either Celery or Arq. The choice usually comes down to whether you already have Redis in your stack. Arq is lighter and more Pythonic, while Celery has more features and more Stack Overflow answers.

For observability, the standard pairing is OpenTelemetry plus Langfuse or Helicone for LLM-specific tracing. Practitioners consistently report that generic APM tools don’t capture the LLM-specific metrics that matter, like tokens per request, cache hit rates, or prompt evaluation scores.

For deployment, the common choices are Fly.io, Railway, Render for smaller apps, and Kubernetes for anything serious. A common complaint on r/FastAPI is that the framework doesn’t ship with deployment guides, so teams learn the hard way about worker counts, connection pooling, and graceful shutdown.

The replacements people actually move to are interesting. Some teams switch to LitServe, which is purpose-built for LLM serving and handles batching and streaming in ways FastAPI doesn’t. Others move to a Node-based stack using Hono or Express because their frontend team already knows TypeScript. A few have gone serverless with Cloudflare Workers and Hono for low-traffic internal tools.

The Honest Take

FastAPI is the right default for most LLM backends in 2026, but it’s not magic. The framework gives you a solid foundation, typed schemas, async handlers, and automatic docs. What it doesn’t give you is the production layer: retries, circuit breakers, observability, streaming edge case handling, and cost controls.

The teams that succeed with FastAPI are the ones who treat it as a starting point and invest in the surrounding infrastructure. The teams that struggle are the ones who expect it to be a complete solution and get surprised by the gaps.

If you’re building an LLM product today, FastAPI is a reasonable choice. Just budget for the middleware, the observability, and the streaming debugging that comes with it. The productivity gains are real, but so is the operational overhead.

Enterprise DNA put together a free field guide on exactly this: the full Claude ecosystem, Claude Code, and how to roll agents out without breaking things. Get the guide.