managementHandler(corsair, opts) returns a single function: (req: Request) => Promise<Response>. Mount it anywhere that speaks the Fetch API. For Next.js, Express, and Hono there are one-line adapters.
Routes
The handler dispatches 9 read/write routes. Connect/OAuth is covered separately on the Connect page.
All routes return JSON. Errors return
{ error, message, …extra } with a non-2xx status — see Errors.
Options
basePath defaults to "/api/corsair". Set it to whatever prefix your framework mounts the handler under. The handler strips it before matching routes, so /api/corsair/tenants → /tenants.
onError lets you log or rewrite errors. Return a Response to take over, or undefined to fall through to the default JSON error.
Framework adapters
Each adapter is a thin wrapper aroundmanagementHandler. All three are exported from the corsair root.
Next.js
app/api/corsair/[[...path]]/route.ts
GET, POST, and OPTIONS share one handler — hub delivery at the base path plus management subpaths.
Express
server.ts
(req, res) to a Fetch Request and back.
Hono
server.ts
Request/Response.
In-process API
Sometimes you don’t want HTTP — you want to call the same operations directly from server code (e.g. inside a server action, a job, or a CLI). The handler is built on top ofcorsair.manage.*, available without going through the handler:
in-process.ts
manage.* method with the same shape.
Errors
Errors come back as JSON in this flat shape:corsair.manage.* calls throw errors with status, code, message, and extra fields — the same shape HTTP clients surface as CorsairClientError. Common codes you’ll see from the management routes:
Connect-route codes are documented on the Connect page.