跳转到内容
EN

停止后台任务(扩展)

POST/agent/v1/sessions/{session_id}/background_tasks/{task_id}/stop● 支持

请求参数

  • session_idstring必填

    path: 会话 ID(sesn_...),由 sessions.create 或 sessions.list 返回。资源和线程调用的 session_id 查询参数也接受同一 ID,且必须与路径值一致。

  • task_idstring必填

    path: Background task id (task_...), as listed by sessions.background_tasks.list.

返回

200

复用 TaskStop:持久化 stop_requested_at 并终止进程组。返回 BackgroundTask;终止尚未观察到时仍可为 running,但不可取消。已结束或不支持停止的任务返回 409。

错误按 Anthropic 错误格式返回(type / message / request_id),参见 错误码

请求示例

curl
curl -X POST https://api.deepraxis.com/agent/v1/sessions/sesn_example/background_tasks/task_example/stop \
  -H "Authorization: Bearer $PRAXIS_API_KEY"
Python
import requests

opts = dict(
    base_url="https://api.deepraxis.com/agent",
    api_key="$PRAXIS_API_KEY",
)

# /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
resp = requests.post(
    f"{opts['base_url']}/v1/sessions/sesn_example/background_tasks/task_example/stop",
    headers={"Authorization": f"Bearer {opts['api_key']}"},
)
print(resp.status_code, resp.json())
TypeScript
const opts = {
  baseURL: "https://api.deepraxis.com/agent",
  apiKey: "$PRAXIS_API_KEY",
};

// /agent 是我们自己的 Managed Agents 形状,直接发 HTTP 请求(Bearer 认证)
const resp = await fetch(`${opts.baseURL}/v1/sessions/sesn_example/background_tasks/task_example/stop`, {
  method: "POST",
  headers: { Authorization: `Bearer ${opts.apiKey}`, "Content-Type": "application/json" },
});
console.log(resp.status, await resp.json());

响应示例 200

{
  "id": "task_example",
  "kind": "bash",
  "thread_id": null,
  "title": "Build application",
  "status": "cancelled",
  "started_at": "2026-10-05T14:00:00.000Z",
  "ended_at": "2026-10-05T14:00:12.000Z",
  "cancellable": false,
  "notified_at": null,
  "trigger_count": null
}

响应

HTTP 200

Current task after stop request

application/json

名称 类型 说明
id string Identifier of the object, as returned by the API; pass it in the path of follow-up calls on the same resource.
kind string Kind of background task: bash for a command started with run_in_background, monitor for a monitor watch.
title string Short human-readable title of the task or object.
thread_id string | null Execution thread the task belongs to; null for the primary thread.
status string Current lifecycle state.
started_at string RFC 3339 time at which the task started.
ended_at string | null RFC 3339 time at which the task ended; null while it is running.
cancellable boolean Whether the task can still be stopped.
notified_at string | null RFC 3339 time of the latest run that the task's notification started; null while no notification has been delivered.
trigger_count integer | null For a monitor task, how many times its matches woke the session; null for other kinds or before the first notification.