Setup
1
Create a FastAPI app
2
Register it in aegra.json
3
Start the server
Route priority
Custom routes follow this priority order:
You can override the root route
/ and /info, but you cannot override the Agent Protocol endpoints or health checks.
Authentication on custom routes
By default, custom routes do not have Aegra’s authentication applied. You have two options:Option 1: Apply auth to all custom routes
Setenable_custom_route_auth in your config:
401 on every FastAPI HTTP route your app declares, including routes from included routers and from mounted FastAPI sub-apps. Auth runs before any other dependency on those routes, including app-level and router-level ones.
Aegra’s own routes are not affected: /health, /live, /ready, /info and the docs pages stay public, and the Agent Protocol routes keep their usual auth. Aegra’s default / stays public too. If your app declares its own /, that is a custom route, and this setting protects it.
This setting does not cover:
- Websocket routes. Authentication here runs on the HTTP request, so websocket connections pass through. Authenticate them inside the handler.
- Plain Starlette routes added with
app.add_route, and mounted non-FastAPI apps such asStaticFiles. These take no FastAPI dependency.
Option 2: Apply auth to specific routes
Use therequire_auth dependency on individual routes:
CORS configuration
Configure CORS for your custom routes inaegra.json:
allow_origin_regex, the default is allow_origins: ["*"] with allow_credentials: false. When you specify concrete origins and no regex, allow_credentials defaults to true automatically. When allow_origin_regex is non-null, allow_credentials defaults to false, and if allow_origins is omitted, it defaults to []. An explicit origin list and regex are combined, while an explicit "*" remains a wildcard. You can always set allow_credentials explicitly to override the default. The regex is passed to Starlette and matched against the complete origin.
Note: the allow_credentials default only recognizes an exact ["*"] or "*". A wildcard mixed with other concrete origins (e.g. ["*", "https://example.com"]) currently still defaults allow_credentials to true, even though Starlette treats that list as allow-all — tracked in #633. Set allow_credentials explicitly if you use a mixed list.