From 1ab07d312fe5f1b687fe15e39a628976c7b5e19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 2 Apr 2026 21:16:17 -0700 Subject: [PATCH 1/2] Export FastAPI app from runner so custom routes can be added Move the FastAPI instance to module level so other packages can import it and register routes before main() is called. main() now configures the existing app with transport-specific routes instead of creating a new one. --- src/pipecat/runner/run.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/pipecat/runner/run.py b/src/pipecat/runner/run.py index 76c870468..90f7b8ce1 100644 --- a/src/pipecat/runner/run.py +++ b/src/pipecat/runner/run.py @@ -110,6 +110,22 @@ RUNNER_DOWNLOADS_FOLDER: Optional[str] = None RUNNER_HOST: str = "localhost" RUNNER_PORT: int = 7860 +app: FastAPI = FastAPI() +"""The FastAPI application instance. + +Import this to add custom routes from other packages before calling +:func:`main`:: + + from pipecat.runner.run import app, main + + @app.get("/my-route") + async def my_route(): + return {"hello": "world"} + + if __name__ == "__main__": + main() +""" + def _get_bot_module(): """Get the bot module from the calling script.""" @@ -164,10 +180,8 @@ async def _run_telephony_bot(websocket: WebSocket, args: argparse.Namespace): await bot_module.bot(runner_args) -def _create_server_app(args: argparse.Namespace): - """Create FastAPI app with transport-specific routes.""" - app = FastAPI() - +def _configure_server_app(args: argparse.Namespace): + """Configure the module-level FastAPI app with transport-specific routes.""" app.add_middleware( CORSMiddleware, allow_origins=["*"], @@ -188,8 +202,6 @@ def _create_server_app(args: argparse.Namespace): else: logger.warning(f"Unknown transport type: {args.transport}") - return app - def _setup_webrtc_routes(app: FastAPI, args: argparse.Namespace): """Set up WebRTC-specific routes.""" @@ -997,8 +1009,8 @@ def main(parser: Optional[argparse.ArgumentParser] = None): RUNNER_HOST = args.host RUNNER_PORT = args.port - # Create the app with transport-specific setup - app = _create_server_app(args) + # Configure the app with transport-specific routes + _configure_server_app(args) # Run the server uvicorn.run(app, host=args.host, port=args.port) From 796a10fe9ca83f3abd177ad08c21919358a5c9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 2 Apr 2026 21:16:49 -0700 Subject: [PATCH 2/2] Add changelog for #4234 --- changelog/4234.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/4234.added.md diff --git a/changelog/4234.added.md b/changelog/4234.added.md new file mode 100644 index 000000000..ab178c4d6 --- /dev/null +++ b/changelog/4234.added.md @@ -0,0 +1 @@ +- The development runner now exports a module-level `app` FastAPI instance (`from pipecat.runner.run import app`) so you can register custom routes before calling `main()`.