<@ULVA73B9P> how can I in prefect @ flow programma...
# ask-marvin
d
@Marvin how can I in prefect @ flow programmatically get the flow run url?
m
thought for 68.8 seconds
In Prefect 3.x, you can get the current flow run’s URL from the runtime context:
Copy code
from prefect import flow
from prefect.runtime import flow_run

@flow(log_prints=True)
def my_flow():
    print(f"Flow run UI URL: {flow_run.ui_url}")
    print(f"Flow run API URL: {flow_run.api_url}")

my_flow()
Notes: - Works from inside a running flow (or task). Outside a run context these will be
None
. - The URLs are built from your
PREFECT_UI_URL
and
PREFECT_API_URL
settings, so it works the same for Prefect Cloud and self-hosted Server. Docs: - Runtime context guide - Runtime flow_run API