Kyle McChesney
10/16/2025, 10:11 PMMarvin
10/16/2025, 10:11 PMMarvin
10/16/2025, 10:14 PMfrom prefect.runtime import flow_run
# Full UI URL for the currently-running flow run
url = flow_run.ui_url
print(url)
Notes:
- This returns the correct URL for both Cloud and Server.
- It returns None if called outside of an active flow run.
If you need to build a URL from a flow-run ID outside of execution, you can use the URL helper after fetching the flow run model:
import asyncio
from prefect.client.orchestration import get_client
from prefect.utilities.urls import url_for
async def flow_run_url(flow_run_id: str) -> str | None:
async with get_client() as client:
fr = await client.read_flow_run(flow_run_id)
return url_for(fr) # constructs the UI URL for that FlowRun
# Example:
# print(asyncio.run(flow_run_url("f9b2d1f8-....")))
Docs:
- Runtime context
- prefect.runtime API
- prefect.utilities.urls.url_for
If you’re trying to generate the URL from outside a running flow without fetching the model, let me know your environment (Cloud vs Server) and I can share a minimal approach for that too.