***

title: as_router
slug: /reference/python/agents/swml-service/as-router
description: Create a FastAPI APIRouter for mounting the service into an existing application.
max-toc-depth: 3
---------------------

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

[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.

<Tip>
  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].
</Tip>

## **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
```