Shubham
10/08/2025, 7:30 AMMarvin
10/08/2025, 7:30 AMMarvin
10/08/2025, 7:33 AMprefect installed and these env vars set:
- PREFECT_API_URL (workspace-scoped URL)
- PREFECT_API_KEY (for Prefect Cloud)
- Minimal code in your Modal app to trigger a deployment
import os
from prefect.deployments.flow_runs import run_deployment
# Ensure these are set in Modal env:
# os.environ["PREFECT_API_URL"] = "<https://api.prefect.cloud/api/accounts/<account-id>/workspaces/<workspace-id>>"
# os.environ["PREFECT_API_KEY"] = "<your-api-key>"
flow_run = run_deployment(
name="my-flow/my-deployment", # or the deployment UUID
parameters={"param1": "value"},
flow_run_name="triggered-from-modal",
)
print(f"Created flow run: {flow_run.id}")
# Track in UI or via client if you want to monitor state
Helpful docs:
- run_deployment API: run_deployment docs
- REST endpoint (alternative): Create flow run from deployment
- Configuring API URL/key: Configure Prefect settings
- Background on work pools/workers: Work pools and workers overview
A couple of clarifying questions to make sure you’re set up correctly:
- Do you want the flow to actually run on Modal infrastructure? If so, you’d need to run a Prefect worker from Modal or build a custom pattern that has Modal start your job and report back; Prefect doesn’t provide a native “Modal” work pool type.
- Or do you just want Modal to trigger a run that executes elsewhere (e.g., Docker/Kubernetes/managed pool)? If that’s the case, the above code is sufficient—just make sure the deployment’s work pool has a worker (or is a managed/serverless pool).