lucian
10/17/2025, 12:48 PMMarvin
10/17/2025, 12:48 PMMarvin
10/17/2025, 12:56 PMACCOUNT_ID=<your_account_id>
WORKSPACE_ID=<your_workspace_id>
FLOW_RUN_ID=<the_flow_run_id>
PREFECT_API_KEY=<your_api_key>
curl -X POST \
"<https://api.prefect.cloud/api/accounts/$ACCOUNT_ID/workspaces/$WORKSPACE_ID/flow_runs/$FLOW_RUN_ID/set_state>" \
-H "Authorization: Bearer $PREFECT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "CANCELLING",
"message": "User requested cancellation"
}'
2) Prefect Cloud – force cancel (bypass orchestration)
curl -X POST \
"<https://api.prefect.cloud/api/accounts/$ACCOUNT_ID/workspaces/$WORKSPACE_ID/flow_runs/$FLOW_RUN_ID/set_state?force=true>" \
-H "Authorization: Bearer $PREFECT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "CANCELLED",
"message": "Immediate cancellation requested"
}'
3) Self-hosted Prefect Server – graceful cancel
SERVER_URL=<http://127.0.0.1:4200>
FLOW_RUN_ID=<the_flow_run_id>
curl -X POST \
"$SERVER_URL/api/flow_runs/$FLOW_RUN_ID/set_state" \
-H "Content-Type: application/json" \
-d '{
"type": "CANCELLING",
"message": "User requested cancellation"
}'
Notes
- CANCELLING is a non-terminal state that prompts infrastructure-aware cleanup; the run will transition to CANCELLED when cleanup completes.
- CANCELLED is terminal; using it with ?force=true will bypass orchestration checks. Use with care as it may not give infrastructure a chance to shut down cleanly.
- Optional fields you can include: name, timestamp (ISO 8601), and state_details.
Docs
- Cancel workflows
- Set flow run state (REST API)
- States in Prefect
If you share whether you’re on Cloud or self-hosted and whether you want graceful or forceful cancellation, I can tailor the exact command for your setup.