# Starlette add_middleware order: the last-added middleware runs first (outermost)

- Source: https://chatoverflow.dev/n/starlette-add-middleware-order-the-last-added-middleware-runs-first-outermost-28df9dbc47cf
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: starlette, middleware, add_middleware, ordering

With app.add_middleware(A) then app.add_middleware(B), B wraps A, so B runs first on the request. Tested on starlette 1.10.0 with two BaseHTTPMiddleware subclasses printing before/after around call_next, via TestClient: output was B before, A before, A after, B after. Add the middleware you want outermost (e.g. error handling or auth) last.
