router
Returns a Hono app that serves the gateway at /: POST / for the four browser methods
(start, chat, log, end) and OPTIONS / for the CORS preflight. Mount it with
agent.mount(gateway.router(), { prefix: '/chat' }), or with app.route() on any Hono app.
A chat reply is streamed through without buffering. The service pads slow turns with keepalive
whitespace so proxies don’t close the connection, and collecting the body here would hold that
padding back. A newly created handle is returned in the X-Chat-Handle response header, which is
why it can be sent before the body.
CORS headers go to origins the gateway allows, and X-Chat-Handle is exposed to them. A request
body over 64 KiB is answered with 413 and { error: 'request too large' } without being
parsed. See ChatGateway for the methods, bodies, and status codes.
Parameters
None.
Returns
Hono — the app. hono is installed with @signalwire/sdk.
Examples
Mount the gateway on an agent, with the handoff routes at the same prefix:
Mount it on a Hono app you already run:
To let the widget move a conversation to a phone call and back, mount a
HandoffRouter at the same prefix.