I have a flow run that got stuck in a Running state. How can I cancel it from the Orion client?

From the flow run page in the UI, copy the flow run ID:

Now, paste the ID into this script and run it to change the state to Cancelled (or any other state):

import asyncio
from prefect.client import get_client
from prefect.orion.schemas.states import Cancelled

async def main():
    async with get_client() as client:
        id_ = "7a5a454a-98ba-49d4-978e-9f566d735c0a"
        response = await client.set_flow_run_state(flow_run_id=id_, state=Cancelled())

if __name__ == "__main__":

You should see the result similar to this:

state=Cancelled(message=None, type=CANCELLED, result=None, flow_run_id=7a5a454a-98ba-49d4-978e-9f566d735c0a) status=SetStateStatus.ACCEPT details=StateAcceptDetails(type='accept_details')

And in the UI we can confirm that the amazing alligator got cancelled!