Request/Response and dispatches through an embedded Hono app, so the same route definitions run anywhere. Three hosting modes:
Next.js catch-all (recommended)
One route file serves every registered route:app/api/[[...route]]/route.ts
/{basePath}/* (default /api/*), including /api/openapi.json and /api/llms.txt. Unmatched paths get a JSON 404 with rediscovery links automatically.
Next.js per-file
One route file per endpoint also works:app/api/search/route.ts
- Verb declaration: the exported const name (
GET/POST) controls which verb Next.js serves, while.method()controls the verb advertised in discovery. The router defaults toPOST(orGETwhen.query()is used), so any other GET route must declare it explicitly. - Discovery needs a barrel: Next.js lazy-loads route files, so your
openapi.jsonroute must import a barrel module that imports every route file, or unloaded routes won’t appear in the spec. - 404 fallback: mount
router.notFound()in a catch-all so stale agent calls get a JSON 404 with rediscovery links instead of an HTML error page.
Hono / Bun / Node / any fetch runtime
router.fetch(request) is a standard fetch handler; router.hono() exposes the internal app for mounting into a larger one. See examples/hono for a runnable server.
basePath
RouterConfig.basePath (default 'api') controls the mount and advertised prefix: routes serve at {baseUrl}/{basePath}/{path}. Pass an empty string to mount at the origin root.
Discovery endpoints
The router generates two discovery surfaces from your route definitions:/openapi.json: OpenAPI 3.1 with pricing extensions. Indexed by AgentCash, x402scan, and mppscan./llms.txt: plain-text guidance for agents.
router.fetch (and the Next.js catch-all) serves both under the basePath automatically, plus the root aliases on fetch runtimes. On Next.js, add the conventional root paths with two one-line route files:
app/openapi.json/route.ts
app/llms.txt/route.ts
router.wellKnown() (the /.well-known/x402 listing) is deprecated. It still works for legacy x402 clients, but new integrations should rely on /openapi.json and /llms.txt. See Become discoverable for the full discovery contract.