<@ULVA73B9P> if I deploy modal app without workpoo...
# ask-marvin
s
@Marvin if I deploy modal app without workpool and set prefect api in python script in app and can I call deployment from modal app
m
thought for 194.5 seconds
Short answer: Yes—you can trigger a Prefect deployment from your Modal app by setting the Prefect API URL/key in that app and calling the deployment via Prefect’s Python client. However, the deployment itself must target a work pool. Without a work pool (and an available worker), the flow run will sit in “awaiting infrastructure” and won’t execute. If you use Prefect Cloud’s managed/serverless work pool, you don’t need to run your own worker. What this looks like (Prefect 3.x): - Requirements - The deployment must be configured with a work pool. - If you don’t want to run a worker yourself, use a managed/serverless work pool in Prefect Cloud. - Otherwise, run a worker for the pool where the deployment is registered. - Your Modal environment needs
prefect
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
Copy code
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).