> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# as_router

> Create a FastAPI APIRouter for mounting the service into an existing application.

[serve]: /docs/server-sdks/reference/python/agents/swml-service/serve

[agentserver]: /docs/server-sdks/reference/python/agents/agent-server

Create a FastAPI `APIRouter` for this service. Use this to mount the service into an
existing FastAPI application rather than running a standalone server with
[`serve()`][serve]. The router handles
both GET and POST requests at the root path and any registered routing callback paths.

The router also registers the GET/POST `/swaig` endpoint alongside the root and
routing-callback routes, so SWAIG tools hosted on the service are reachable when it is
mounted this way.

Use `as_router()` for production deployments where you want to control the ASGI
application lifecycle, or when hosting multiple services on the same FastAPI instance
via [`AgentServer`][agentserver].

## **Returns**

`APIRouter` — A FastAPI router with all endpoints registered.

## **Example**

```python {10}
from fastapi import FastAPI
from signalwire import SWMLService

app = FastAPI()

service = SWMLService(name="ivr", route="/ivr")
service.add_verb("answer", {})
service.add_verb("play", {"url": "https://example.com/welcome.mp3"})

app.include_router(service.as_router(), prefix="/ivr")

# Run with: uvicorn myapp:app --host 0.0.0.0 --port 3000
```