APIRouter splits a FastAPI app across modules and is included with include_router
Answer: Use APIRouter to declare path operations in their own modules, then attach those routers to the main FastAPI app with app.include_router(). Think of APIRouter as a mini FastAPI class: the same options, such as parameters, responses, dependencies, and tags, are supported.
Prefixes, tags, and dependencies
You can set a path prefix, tags, extra responses, and dependencies on the router so you do not repeat them on every path operation. The prefix must not include a final /. You can declare those parameters on app.include_router() without having to modify the original APIRouter.
How Starlette splits routes
Starlette has a simple request routing system. A routing table is defined as a list of routes. In large applications you can break out parts of the routing table, based on a common path prefix, using Mount.
See also
Claims
- id: C1 claim: APIRouter is used to declare path operations in a module. source: S1 evidence: "create the path operations for that module using
APIRouter"
- id: C2 claim: include_router adds an APIRouter to the main FastAPI application. source: S1 evidence: "add each
APIRouterto the mainFastAPIapplication"
- id: C3 claim: Starlette takes a routing table as a list of routes. source: S2 evidence: "A routing table is defined as a list of routes"
- id: C4 claim: Starlette can split routes that share a common path prefix. source: S2 evidence: "based on a common path prefix"
Sources
- [S1] Bigger Applications - Multiple Files. fastapi/fastapi (GitHub). https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/bigger-applications.md . License: MIT. Accessed 2026-11-17.
- [S2] HTTP Routing (Starlette). Kludex/starlette (GitHub). https://github.com/Kludex/starlette/blob/main/docs/routing.md . License: BSD-3-Clause. Accessed 2026-11-17.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: fastapi/fastapi (GitHub), Bigger Applications - Multiple Files, MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez; Kludex/starlette (GitHub), HTTP Routing (Starlette), BSD-3-Clause (https://raw.githubusercontent.com/Kludex/starlette/main/LICENSE.md). Copyright (c) 2018, Encode OSS Ltd. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: fastapi/fastapi (GitHub), Bigger Applications - Multiple Files, MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez; Kludex/starlette (GitHub), HTTP Routing (Starlette), BSD-3-Clause (https://raw.githubusercontent.com/Kludex/starlette/main/LICENSE.md). Copyright (c) 2018, Encode OSS Ltd.
Cite this
iinventedlight. 2026. "APIRouter splits a FastAPI app across modules and is included with include_router." iinventedlight Library, iil:note:etyn80vx, version of 2026-11-17. https://iinventedlight.com/library/notes/fastapi-apirouter/. License: CC-BY-4.0.
@misc{iil_note_etyn80vx,
author = {{iinventedlight}},
title = {{APIRouter splits a FastAPI app across modules and is included with include\_router}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/fastapi-apirouter/},
note = {Permanent ID iil:note:etyn80vx. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/fastapi-apirouter.md.