Skip to main content
POST
/
v1
/
tasks
/
{task_id}
/
stop
Stop Task
curl --request POST \
  --url https://api.xpander.ai/v1/tasks/{task_id}/stop \
  --header 'x-api-key: <api-key>'
{
  "id": "<string>",
  "agent_id": "<string>",
  "organization_id": "<string>",
  "input": {
    "text": "",
    "files": [],
    "user": {
      "id": "<string>",
      "email": "<string>"
    }
  },
  "created_at": "2023-11-07T05:31:56Z",
  "status": "pending",
  "internal_status": "<string>",
  "last_executed_node_id": "<string>",
  "agent_version": "<string>",
  "started_at": "2023-11-07T05:31:56Z",
  "paused_at": "2023-11-07T05:31:56Z",
  "finished_at": "2023-11-07T05:31:56Z",
  "result": "<string>",
  "parent_execution": "<string>",
  "sub_executions": [],
  "finished_sub_executions": [],
  "is_manually_stopped": false,
  "payload_extension": {},
  "hitl_request": {
    "wait_node_id": "<string>"
  },
  "pending_eca_request": {
    "connector_name": "<string>",
    "auth_url": "<string>"
  },
  "source": "<string>",
  "worker_id": "<string>",
  "additional_context": "<string>",
  "instructions_override": "<string>",
  "expected_output": "<string>",
  "test_run_node_id": "<string>",
  "is_orchestration": false,
  "output_format": "text",
  "voice_id": "<string>",
  "output_schema": {},
  "events_streaming": false,
  "used_mutating_tools": false,
  "is_continuous": false,
  "mcp_servers": [],
  "triggering_agent_id": "<string>",
  "title": "<string>",
  "think_mode": "default",
  "disable_attachment_injection": false,
  "deep_planning": {
    "enabled": false,
    "enforce": false,
    "started": false,
    "question_raised": false,
    "tasks": []
  },
  "execution_attempts": 1,
  "user_tokens": {},
  "user_oidc_token": "<string>",
  "return_metrics": false,
  "tokens": {
    "completion_tokens": 0,
    "prompt_tokens": 0,
    "total_tokens": 0
  },
  "llm_model_provider": "<string>",
  "llm_model_name": "<string>",
  "llm_reasoning_effort": "low"
}

Documentation Index

Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt

Use this file to discover all available pages before exploring further.

Cancel a running task. Sends a stop signal to the worker executing the task, marks the execution as stopped, and sets is_manually_stopped: true. Returns the updated task record. The endpoint is idempotent: calling it on a task that is already in a terminal state (completed, failed, stopped) returns the current execution unchanged.

Path Parameters

task_id
string
required
Unique identifier of the task to stop (UUID format)

Response

Returns the updated Agent Execution object with status set to stopped and is_manually_stopped set to true.

Example Request

curl -X POST -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/<task-id>/stop"

Example Response

{
  "id": "fbd08e4d-cfa7-4838-b6e6-e51855ac2ba3",
  "agent_id": "<agent-id>",
  "organization_id": "<org-id>",
  "status": "stopped",
  "is_manually_stopped": true,
  "created_at": "2026-05-13T10:12:04.123456Z",
  "started_at": "2026-05-13T10:12:05.001234Z",
  "finished_at": "2026-05-13T10:12:42.998877Z",
  "result": null,
  "source": "api"
}

Response Status Codes

StatusMeaning
200Stop signal accepted (or task already in a terminal state)
401Unauthorized (invalid API key)
403Forbidden (task belongs to a different organization)
404Task not found
422Validation error (malformed task_id)

Important Notes

  • Idempotent - Tasks already in completed, failed, or stopped are returned unchanged
  • Asynchronous - The worker may take a few seconds to observe the stop signal and exit cleanly. Poll Get Task until status becomes stopped
  • Self-hosted environments - For agents running in a self-hosted environment, the stop request is routed cross-environment via the asset-command channel
  • Manual flag - is_manually_stopped: true distinguishes user-initiated cancels from system-side terminations

Example: Stop and confirm

TASK_ID="<task-id>"

curl -s -X POST -H "x-api-key: <your-api-key>" \
  "https://api.xpander.ai/v1/tasks/$TASK_ID/stop" > /dev/null

while true; do
  STATUS=$(curl -s -H "x-api-key: <your-api-key>" \
    "https://api.xpander.ai/v1/tasks/$TASK_ID" | jq -r '.status')

  if [[ $STATUS == "stopped" || $STATUS == "completed" || $STATUS == "failed" ]]; then
    echo "Final status: $STATUS"
    break
  fi

  sleep 2
done

Use Cases

  • Cancel a runaway agent - Halt an execution that is consuming too much time or tokens
  • User-initiated cancel - Wire a “Stop” button in your UI to this endpoint
  • Abort long-running tasks - Free up worker capacity when a task is no longer needed
  • Recover from stuck tasks - Force-terminate executions that are not progressing

Authorizations

x-api-key
string
header
required

API Key for authentication

Path Parameters

task_id
string
required

Response

Successful Response

id
string
required
agent_id
string
required
organization_id
string
required
input
AgentExecutionInput · object
required
created_at
string<date-time>
required
status
enum<string> | null
default:pending
Available options:
pending,
executing,
paused,
error,
failed,
completed,
stopped
internal_status
string | null
last_executed_node_id
string | null
agent_version
string | null
started_at
string<date-time> | null
paused_at
string<date-time> | null
finished_at
string<date-time> | null
result
string | null
parent_execution
string | null
sub_executions
string[] | null
finished_sub_executions
string[] | null
is_manually_stopped
boolean | null
default:false
payload_extension
Payload Extension · object
hitl_request
HumanInTheLoopRequest · object

Model representing human-in-the-loop approval records for tasks.

Attributes: wait_node_id (str): The id of the node that triggered this HITL.

pending_eca_request
PendingECARequest · object
source
string | null
worker_id
string | null
additional_context
string | null
instructions_override
string | null
expected_output
string | null
test_run_node_id
string | null
is_orchestration
boolean | null
default:false
output_format
enum<string> | null
default:text
Available options:
text,
markdown,
json,
voice
voice_id
string | null
output_schema
Output Schema · object
events_streaming
boolean | null
default:false
used_mutating_tools
boolean | null
default:false
is_continuous
boolean | null
default:false
mcp_servers
Mcp Servers · object[] | null
triggering_agent_id
string | null
title
string | null
think_mode
enum<string> | null
default:default
Available options:
default,
harder
disable_attachment_injection
boolean | null
default:false
deep_planning
DeepPlanning · object
execution_attempts
integer | null
default:1
user_tokens
User Tokens · object
user_oidc_token
string | null
return_metrics
boolean | null
default:false
tokens
LLMTokens · object
llm_model_provider
string | null

Snapshot of the effective LLM provider used for this execution. Reflects the per-execution override when supplied on the invocation request, otherwise falls back to the agent's configured provider.

llm_model_name
string | null

Snapshot of the effective model name used for this execution. Reflects the per-execution override when supplied on the invocation request, otherwise falls back to the agent's configured model.

llm_reasoning_effort
enum<string> | null

Snapshot of the effective reasoning effort used for this execution. Reflects the per-execution override when supplied on the invocation request, otherwise falls back to the agent's configured reasoning effort.

Available options:
low,
medium,
high,
xhigh