POST /v2/runs/{run_id}/cancel
Request cancellation of an accessible run owned by this authenticated actor.
Ownership matches the actor type and identity that started the run, including the distinction between a personal API key and a platform session. Acceptance acknowledges the request; it does not guarantee execution has already stopped. Polling the Location URL separately requires analytics read permission.
How to use
Use the originating actor type and identity. A 202 acknowledges cancellation signalling, not a stopped execution; poll afterward. A 404 can indicate nonownership. Side effects already performed cannot be undone by cancellation.
Authentication and permissions
Required permissions: projects.run. Resource and owner access checks also apply.
Personal API key (sk_...) or supported user access JWT. See Authentication and authorization for endpoint restrictions and scopes. Use exactly one Authorization header.
Cancellation accepted. Poll the Location URL for the current run state.
Base response model for StackAI API endpoints.
Provides Pydantic validation and serialization with a helper method to convert to FastAPI's JSONResponse when needed.
Serialization contract: status_code never reaches the body (it only feeds
to_json_response), and response_code/meta are omitted when unset so
success bodies carry no filler. Error handlers that set them keep them.
Machine-readable response code, when provided.
Invalid run ID.
Authentication required.
Project run permission or credential scope required, or run logging disabled.
Run not found, inaccessible, or not owned by the authenticated actor.
Run is no longer cancellable.
Validation Error
Cancellation signalling failed; the request may already have changed run state.
curl --fail-with-body -sS -X POST \
"$STACKAI_BASE_URL/v2/runs/${RUN_ID}/cancel" \
-H "Authorization: Bearer $STACKAI_API_KEY"{
"response_code": "text",
"meta": {
"ANY_ADDITIONAL_PROPERTY": "anything"
}
}Last updated
Was this helpful?

