# List Every API Endpoint in a FastAPI App

An agent maps 23 endpoints in a FastAPI backend, 22 outside development, traces CurrentUser and superuser dependencies, and finds 6 public routes.

[Run this on Rush](https://cloud.getrush.ai/run/api-endpoint-inventory/fastapi/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `backend/app/main.py`, which mounts `api_router` at `/api/v1`, then `backend/app/api/main.py`. Lines 7 to 10 include the login, users, utils and items routers; lines 13 and 14 include `private` only when `FASTAPI_ENV == "development"`. In `api/deps.py` it traces the aliases: `CurrentUser` (line 49) is any active user and `get_current_active_superuser` (line 52) adds a superuser check.

It then reads every handler in `api/routes/` and notes checks the dependencies miss: `items.py` limits non-superusers to their own `owner_id`, and `users.py:172` lets a normal user read only their own record. To check the reading it dumps `app.openapi()` with and without the development router, and runs the backend tests against a local Postgres 16.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Write endpoints.md for the backend of this FastAPI repository: every method and composed path, including routers that exist only in some environments, the handler file:line, the dependencies that authenticate or require a superuser (trace Annotated aliases like CurrentUser), inline ownership checks, and the request and response models. Install with uv, run the backend tests against a local Postgres, and compare your table with app.openapi(). Report the endpoint count and which routes are public. Do not change application code.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on fastapi/full-stack-fastapi-template at f4bcfab: 1 file changed, 91 insertions(+), all of it `endpoints.md`. It lists 23 operations in development and 22 elsewhere: 6 public in development (5 elsewhere), 11 for any active user and 6 for superusers. The app's own OpenAPI output puts a security requirement on exactly those 17. `uv run bash scripts/test.sh` on the untouched clone ended `58 passed, 55 warnings in 9.39s`.

For the reviewer: the development-only `POST /api/v1/private/users/` creates a user with no authentication, recorded as public rather than as a bug. The 58 passes needed a `uuid-ossp` stand-in added to the sandbox Postgres, not a stock install.

## Run it on every Monday morning

An automation with a `schedule` trigger, `cron` `0 9 * * 1` in your team's `timezone`, runs this prompt against main each week. Diffing this week's `endpoints.md` with last week's shows a route that lost its `CurrentUser` dependency.

## Why run it on Rush?

Counting the routes depends on the environment: the `private` router adds an unauthenticated user-creation route in development only. Outside development, the app would not even import until `backend/app/frontend` existed, so the run created it briefly to count the other 22.

## Frequently asked questions

### How were the access counts checked?

The dependency tree decides access, not a decorator. FastAPI's OpenAPI marks a `security` requirement on every route that reaches `reusable_oauth2`, and those 17 matched the 11 `CurrentUser` and 6 superuser routes read from source.

### Did the agent call the endpoints over HTTP?

No. It checked its table against `app.openapi()` and the 58 backend tests, not live requests. The ownership checks in `items.py` and `users.py` come from reading the handlers.

## More FastAPI jobs

- [Fix a FastAPI App Bug From a Datadog Monitor Alert](https://getrush.ai/run/fix-datadog-alerts/fastapi/)
- [Fix Failing GitHub Actions Checks in a FastAPI App](https://getrush.ai/run/fix-failing-ci/fastapi/)
- [Fix a FastAPI App From a Grafana Alert](https://getrush.ai/run/fix-grafana-alerts/fastapi/)

## The same job on other stacks

- [Inventory the API Endpoints of a Gin Service](https://getrush.ai/run/api-endpoint-inventory/gin/)
- [Inventory the API Endpoints of a Go Service](https://getrush.ai/run/api-endpoint-inventory/go/)
- [List Every API Endpoint in a Phoenix App](https://getrush.ai/run/api-endpoint-inventory/phoenix/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
