← All notes

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

Sources

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

Permanent ID: iil:note:etyn80vx

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.},
}

Markdown

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.