> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # router > Build the APIRouter that exposes the gateway to a browser. [ref-chatgateway]: /docs/server-sdks/reference/python/agents/chat-gateway [mount]: /docs/server-sdks/reference/python/agents/agent-base/mount [handoffrouter]: /docs/server-sdks/reference/python/agents/handoff-router Return an `APIRouter` exposing this gateway, ready to hand to `include_router`. It serves `POST /` for the four browser methods and `OPTIONS /` for the CORS preflight. The router returns chat bodies with `StreamingResponse`; the public endpoint may already have buffered the response it received from the AI chat service. A newly minted handle is returned in the `X-Chat-Handle` header. ## **Parameters** None. ## **Returns** `fastapi.APIRouter`. ## **Example** Mount it on an app you already run: ```python {11} import os from fastapi import FastAPI from signalwire.ai_chat import ChatGateway app = FastAPI() gateway = ChatGateway( config_url="https://bayview-taxi.example.com/swml", key="pk_your_publishable_key", secret=os.environ["SIGNALWIRE_CHAT_GATEWAY_SECRET"], ) app.include_router(gateway.router(), prefix="/chat") ``` An agent already serves a FastAPI app, so it can host the gateway too. Use [`mount()`][mount], which keeps the new routes ahead of the agent's catch-all: ```python {9} import os agent = MyAgent() gateway = ChatGateway( config_url="https://bayview-taxi.example.com/swml", secret=os.environ["SIGNALWIRE_CHAT_GATEWAY_SECRET"], ) agent.mount(gateway.router(), prefix="/chat") agent.run() ``` To let the widget move a conversation to a phone call and back, mount a [`HandoffRouter`][handoffrouter] at the same prefix. > Build the APIRouter that exposes the gateway to a browser.