Chainlit can be mounted as a FastAPI sub application.

import chainlit as cl

async def main():
    await cl.Message(content="Hello World").send()
from fastapi import FastAPI
from chainlit.utils import mount_chainlit

app = FastAPI()

def read_main():
    return {"message": "Hello World from main app"}

mount_chainlit(app=app, target="", path="/chainlit")

In the example above, we have a FastAPI application with a single endpoint /app. We mount the Chainlit application to the /chainlit path.

Start the FastAPI server:

uvicorn main:app --host --port 80