Skip to main content

Cancel the current turn

Call requirements, permissions, request fields, response fields, and error handling.

Request and permissions

POST https://openapi.qwenwork.ai/v1/session/sessions/{session_id}/cancel Authentication: Authorization: Bearer <access_token>; use an access token obtained through user OAuth authorization. Required business Scope: session.session.execute Authorization methods declared by the contract: Organization authorization (organization), personal authorization (personal) The platform must enable the Scope for the application. The user must have the corresponding business permissions, and the target resource must be within their accessible scope. Whether personal or organization authorization is available to the application depends on the actual console configuration.

Behavior and limitations

Omitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; the open platform validates the corresponding Scope declared by each endpoint. Cloud sessions: Interrupt the executing turn. The session remains alive; use DELETE /sessions/{session_id} to end it. The response explains what was cancelled:
  • 202, status: cancelling—a turn was executing and an interruption request has been sent. This does not mean the turn has stopped; confirm through GET /sessions/{session_id}.
  • 200, status: noop—nothing was executing. reason specifies the situation: no_active_turn or not_started.
  • 409—the session has ended.
Queued prompts are unaffected. To withdraw one, use DELETE /sessions/{session_id}/prompt-queue/{prompt_id}. Remote-control sessions: Shares public gateway authentication with cloud sessions; this endpoint requires the business Scope stated below. No controller device ID or pairing is required. The target remote-control master switch must be enabled. If explicitly disabled, returns 403 FORBIDDEN with detail.reason=ACP_HOST_DISABLED; rejected write requests return detail.acceptance=not_accepted. An explicitly nonexistent session returns 404 NOT_FOUND with detail.reason=SESSION_NOT_FOUND. Commands route only to target connections signed in to the currently authenticated account. Offline targets, unknown targets, and targets belonging to other accounts all return device unavailable. Unknown request body fields are rejected. All write operations require Idempotency-Key. Do not retry automatically after a timeout or disconnection, even with the same key: acceptance may be unknown, desktop deduplication is bounded, and persistence across restarts is not guaranteed. Errors include detail.acceptance (not_accepted or unknown). No queuing, offline execution, or automatic fallback to cloud is provided. Send an empty JSON object. A validated cancellation acknowledgment returns 202 and status=cancelling, which does not mean execution has stopped; confirm the terminal event separately. Conditional cancellation of a specified turn is unsupported. Call through the open platform, retaining the existing oauth_app Token, identity resolution, application IP restrictions, and resource ownership checks. Cloud and remote-control parameters retain their actual contract semantics. Short paths such as /sessions in this page are relative to the common prefix /v1/session. Use the full path at the top of this page for actual requests. Supported session types: cloud, remote In the full JSON, x-session-variants preserves the parameters, request bodies, and responses for cloud and remote-control sessions separately. Do not mix fields from the two branches.

Path parameters

ParameterTypeRequiredDescription and constraints
session_idstringYesSession identifier: a UUID for cloud sessions; an opaque identifier on the selected device for remote-control sessions.
Minimum length: 1
Maximum length: 256

Query parameters

ParameterTypeRequiredDescription and constraints
session_typestringNoOmitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; the open platform validates the corresponding Scope declared by each endpoint.
Default: "cloud"
Allowed values: ["cloud", "remote"]
device_idstringNoRequired only for remote control. An opaque target device identifier from device discovery; it must be URL-encoded. The target connection must be signed in to the currently authenticated account.
Minimum length: 1
Maximum length: 256

Header parameters

ParameterTypeRequiredDescription and constraints
Idempotency-KeystringNoRemote-control sessions only: a stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.
A stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.
Minimum length: 1
Maximum length: 128

Request body

The request body is optional.

application/json

A child field is required only when its containing object exists. Union branches are listed separately; this does not mean that fields from all branches are required simultaneously.
FieldTypeRequiredDescription and constraints
$schemastringNoURL of the JSON Schema for this object.
Format: "uri"

Successful responses

Preserve the original response structure of each business endpoint; do not add a common code/msg/data wrapper.

HTTP 200

Nothing was cancelled. status is noop; reason explains why: no_active_turn (the session is idle) or not_started (the runtime is still preparing). This is not an error—the request was understood, but there was no running turn to interrupt. Response type: application/json
FieldTypeRequiredDescription and constraints
$schemastringNoURL of the JSON Schema for this object.
Format: "uri"
command_idstringNoThe id of this cancellation, present only when cancellation was actually sent. It is passed to the agent as commandId and appears in runtime logs and traces, making it useful when reporting that cancellation did not take effect. It is not echoed in the event stream.
reasonstringNoWhy nothing was cancelled; present only when status is "noop". "no_active_turn": the session is idle. "not_started": the session is still preparing its runtime.
statusstringYes"cancelling" means cancel has been sent to the executing turn—this is a request, not confirmation that it has stopped. Poll GET /sessions/{id} until the turn leaves running. "noop" means nothing could be cancelled at that time; see reason.
turn_idstringNoThe turn being cancelled. null or absent when nothing was running.

HTTP 202

Accepted Response type: application/json
FieldTypeRequiredDescription and constraints
$schemastringNoAt least one of: branch 1
URL of the JSON Schema for this object.
Format: "uri"
command_idstringNoAt least one of: branch 1
The id of this cancellation, present only when cancellation was actually sent. It is passed to the agent as commandId and appears in runtime logs and traces, making it useful when reporting that cancellation did not take effect. It is not echoed in the event stream.
reasonstringNoAt least one of: branch 1
Why nothing was cancelled; present only when status is "noop". "no_active_turn": the session is idle. "not_started": the session is still preparing its runtime.
statusstringYesAt least one of: branch 1
"cancelling" means cancel has been sent to the executing turn—this is a request, not confirmation that it has stopped. Poll GET /sessions/{id} until the turn leaves running. "noop" means nothing could be cancelled at that time; see reason.
turn_idstringNoAt least one of: branch 1
The turn being cancelled. null or absent when nothing was running.
$schemastringNoAt least one of: branch 2
URL of the JSON Schema for this object.
Format: "uri"
session_idstringYesAt least one of: branch 2
—
statusstringYesAt least one of: branch 2
The command has been acknowledged; wait for the turn's terminal event to confirm it has stopped.
Allowed values: ["cancelling"]

Error responses

HTTPDescription and handling
defaultError. Branch on code, not just the HTTP status code—multiple conditions can share the same status code.
Retain the request ID and error fields in the response for troubleshooting. A write operation may already have taken effect after a timeout or disconnection. Do not automatically retry merely because no successful response was received.

Full field contract

The JSON below contains the complete request, response, and error schemas, nested constraints, and public extension definitions for this endpoint. Copy it for verification. Success examples not declared in the contract are not inferred.
{
  "components": {
    "schemas": {
      "SessionPublicCancelResponse": {
        "additionalProperties": false,
        "properties": {
          "$schema": {
            "description": "URL of the JSON Schema for this object.",
            "examples": [
              "https://example.com/schemas/CancelResponse.json"
            ],
            "format": "uri",
            "readOnly": true,
            "type": "string"
          },
          "command_id": {
            "description": "The id of this cancellation, present only when cancellation was actually sent. It is passed to the agent as commandId and appears in runtime logs and traces, making it useful when reporting that cancellation did not take effect. It is not echoed in the event stream.",
            "examples": [
              "cmd_4a71e6b9"
            ],
            "type": "string"
          },
          "reason": {
            "description": "Why nothing was cancelled; present only when status is \"noop\". \"no_active_turn\": the session is idle. \"not_started\": the session is still preparing its runtime.",
            "type": "string"
          },
          "status": {
            "description": "\"cancelling\" means cancel has been sent to the executing turn—this is a request, not confirmation that it has stopped. Poll GET /sessions/{id} until the turn leaves running. \"noop\" means nothing could be cancelled at that time; see reason.",
            "type": "string"
          },
          "turn_id": {
            "description": "The turn being cancelled. null or absent when nothing was running.",
            "examples": [
              "2f7a1e88-4c05-4b93-8d61-3ea90c5b7d24"
            ],
            "type": "string"
          }
        },
        "required": [
          "status"
        ],
        "type": "object"
      },
      "SessionPublicErrorBody": {
        "additionalProperties": false,
        "properties": {
          "code": {
            "description": "Stable machine-readable error code. Branch on it rather than the HTTP status code, because different conditions can share the same status. New codes may be added; treat unrecognized values as unexpected errors in that HTTP status class.",
            "examples": [
              "VALIDATION_ERROR"
            ],
            "type": "string"
          },
          "detail": {
            "description": "Structured context whose shape depends on code—for example, the fields rejected by validation. null when no additional information is available."
          },
          "message": {
            "description": "Human-readable explanation for logs and error displays. The wording is not part of the contract and may change without a version increment.",
            "examples": [
              "Request validation failed"
            ],
            "type": "string"
          },
          "trace_id": {
            "description": "W3C trace id for this request. Include it when reporting problems—it locates the request in platform logs. If the request carried no trace context, this is 32 zero characters.",
            "examples": [
              "00000000000000000000000000000000"
            ],
            "type": "string"
          }
        },
        "required": [
          "code",
          "message",
          "detail",
          "trace_id"
        ],
        "type": "object"
      },
      "SessionPublicRemoteCancelInBody": {
        "additionalProperties": false,
        "properties": {
          "$schema": {
            "description": "URL of the JSON Schema for this object.",
            "examples": [
              "https://example.com/schemas/RemoteCancelInBody.json"
            ],
            "format": "uri",
            "readOnly": true,
            "type": "string"
          }
        },
        "type": "object"
      },
      "SessionPublicRemoteCancelResponse": {
        "additionalProperties": false,
        "properties": {
          "$schema": {
            "description": "URL of the JSON Schema for this object.",
            "examples": [
              "https://example.com/schemas/RemoteCancelResponse.json"
            ],
            "format": "uri",
            "readOnly": true,
            "type": "string"
          },
          "session_id": {
            "type": "string"
          },
          "status": {
            "description": "The command has been acknowledged; wait for the turn's terminal event to confirm it has stopped.",
            "enum": [
              "cancelling"
            ],
            "type": "string"
          }
        },
        "required": [
          "session_id",
          "status"
        ],
        "type": "object"
      },
      "SessionRelayError": {
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "error_description": {
            "type": "string"
          }
        },
        "required": [
          "error",
          "error_description",
          "error_code"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "OpenPlatformBearer": {
        "description": "Authorization: Bearer <access_token>; JSON Content-Type: application/json; charset=utf-8. The current CN Review temporarily allows access only for routing debugging.",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "openapi": "3.1.0",
  "paths": {
    "/v1/session/sessions/{session_id}/cancel": {
      "post": {
        "description": "Omitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; the open platform validates the corresponding Scope declared by each endpoint.\n\nCloud sessions:\nInterrupt the executing turn. The session remains alive; use `DELETE /sessions/{session_id}` to end it.\n\nThe response explains what was cancelled:\n\n- **202**, `status: cancelling`—a turn was executing and an interruption request has been sent. This does not mean the turn has stopped; confirm through `GET /sessions/{session_id}`.\n- **200**, `status: noop`—nothing was executing. `reason` specifies the situation: `no_active_turn` or `not_started`.\n- **409**—the session has ended.\n\nQueued prompts are unaffected. To withdraw one, use `DELETE /sessions/{session_id}/prompt-queue/{prompt_id}`.\n\nRemote-control sessions:\nShares public gateway authentication with cloud sessions; this endpoint requires the business Scope stated below. No controller device ID or pairing is required. The target remote-control master switch must be enabled. If explicitly disabled, returns 403 FORBIDDEN with detail.reason=ACP_HOST_DISABLED; rejected write requests return detail.acceptance=not_accepted. An explicitly nonexistent session returns 404 NOT_FOUND with detail.reason=SESSION_NOT_FOUND. Commands route only to target connections signed in to the currently authenticated account. Offline targets, unknown targets, and targets belonging to other accounts all return device unavailable. Unknown request body fields are rejected. All write operations require Idempotency-Key. Do not retry automatically after a timeout or disconnection, even with the same key: acceptance may be unknown, desktop deduplication is bounded, and persistence across restarts is not guaranteed. Errors include detail.acceptance (not_accepted or unknown). No queuing, offline execution, or automatic fallback to cloud is provided. Send an empty JSON object. A validated cancellation acknowledgment returns 202 and status=cancelling, which does not mean execution has stopped; confirm the terminal event separately. Conditional cancellation of a specified turn is unsupported.\nCall through the open platform, retaining the existing oauth_app Token, identity resolution, application IP restrictions, and resource ownership checks. Cloud and remote-control parameters retain their actual contract semantics.",
        "operationId": "publishedCancel-turn",
        "parameters": [
          {
            "description": "Session identifier: a UUID for cloud sessions; an opaque identifier on the selected device for remote-control sessions.",
            "in": "path",
            "name": "session_id",
            "required": true,
            "schema": {
              "maxLength": 256,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Omitting session_type selects a cloud session. Every remote-control request must use session_type=remote and provide a nonempty device_id. Providing device_id for a cloud session, an empty or unknown type, or duplicate target parameters returns 422 VALIDATION_ERROR. Cross-device aggregated lists and automatic fallback to cloud are not provided. Both types use the same authentication chain; The upstream does not validate OAuth session scope; the open platform validates the corresponding Scope according to the manifest.",
            "in": "query",
            "name": "session_type",
            "schema": {
              "default": "cloud",
              "enum": [
                "cloud",
                "remote"
              ],
              "type": "string"
            }
          },
          {
            "description": "Required only for remote control. An opaque target device identifier from device discovery; it must be URL-encoded. The target connection must be signed in to the currently authenticated account.",
            "in": "query",
            "name": "device_id",
            "schema": {
              "maxLength": 256,
              "minLength": 1,
              "type": "string"
            }
          },
          {
            "description": "Remote-control sessions only: a stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.",
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "description": "A stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.",
              "maxLength": 128,
              "minLength": 1,
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "examples": {
                "remote-empty": {
                  "value": {}
                }
              },
              "schema": {
                "$ref": "#/components/schemas/SessionPublicRemoteCancelInBody"
              }
            }
          },
          "description": "Remote control requires a JSON object; cloud sessions allow no request body."
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SessionPublicCancelResponse"
                }
              }
            },
            "description": "Nothing was cancelled. `status` is `noop`; `reason` explains why: `no_active_turn` (the session is idle) or `not_started` (the runtime is still preparing). **This is not an error**—the request was understood, but there was no running turn to interrupt.",
            "headers": {
              "X-Request-ID": {
                "description": "Request ID generated by the open platform for each HTTP request, for log correlation and troubleshooting. Retries generate new IDs; this is not an idempotency key or distributed Trace ID.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              },
              "X-Trace-ID": {
                "description": "OpenTelemetry TraceID for the current open-platform request, correlated with X-Request-ID through request logs. A complete trace may be unavailable if the sample was not retained.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              }
            }
          },
          "202": {
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/SessionPublicCancelResponse"
                    },
                    {
                      "$ref": "#/components/schemas/SessionPublicRemoteCancelResponse"
                    }
                  ]
                }
              }
            },
            "description": "Accepted",
            "headers": {
              "X-Request-ID": {
                "description": "Request ID generated by the open platform for each HTTP request, for log correlation and troubleshooting. Retries generate new IDs; this is not an idempotency key or distributed Trace ID.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              },
              "X-Trace-ID": {
                "description": "OpenTelemetry TraceID for the current open-platform request, correlated with X-Request-ID through request logs. A complete trace may be unavailable if the sample was not retained.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "content": {
              "application/json": {
                "schema": {
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/SessionPublicErrorBody"
                    },
                    {
                      "$ref": "#/components/schemas/SessionRelayError"
                    }
                  ]
                }
              }
            },
            "description": "Error. Branch on `code`, not just the HTTP status code—multiple conditions can share the same status code.",
            "headers": {
              "X-Request-ID": {
                "description": "Request ID generated by the open platform for each HTTP request, for log correlation and troubleshooting. Retries generate new IDs; this is not an idempotency key or distributed Trace ID.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              },
              "X-Trace-ID": {
                "description": "OpenTelemetry TraceID for the current open-platform request, correlated with X-Request-ID through request logs. A complete trace may be unavailable if the sample was not retained.",
                "schema": {
                  "pattern": "^[0-9a-f]{32}$",
                  "type": "string"
                }
              }
            }
          }
        },
        "security": [
          {
            "OpenPlatformBearer": []
          }
        ],
        "summary": "Cancel the current turn",
        "tags": [
          "会话管理"
        ],
        "x-session-variants": {
          "cloud": {
            "summary": "Cancel the current turn",
            "description": "Interrupt the executing turn. The session remains alive; use `DELETE /sessions/{session_id}` to end it.\n\nThe response explains what was cancelled:\n\n- **202**, `status: cancelling`—a turn was executing and an interruption request has been sent. This does not mean the turn has stopped; confirm through `GET /sessions/{session_id}`.\n- **200**, `status: noop`—nothing was executing. `reason` specifies the situation: `no_active_turn` or `not_started`.\n- **409**—the session has ended.\n\nQueued prompts are unaffected. To withdraw one, use `DELETE /sessions/{session_id}/prompt-queue/{prompt_id}`.",
            "parameters": [
              {
                "description": "Session ID returned by POST /sessions.",
                "in": "path",
                "name": "session_id",
                "required": true,
                "schema": {
                  "description": "Session ID returned by POST /sessions.",
                  "format": "uuid",
                  "type": "string"
                }
              }
            ],
            "requestBody": null,
            "responses": {
              "200": {
                "content": {
                  "application/json": {
                    "schema": {
                      "$ref": "#/components/schemas/SessionPublicCancelResponse"
                    }
                  }
                },
                "description": "Nothing was cancelled. `status` is `noop`; `reason` explains why: `no_active_turn` (the session is idle) or `not_started` (the runtime is still preparing). **This is not an error**—the request was understood, but there was no running turn to interrupt."
              },
              "202": {
                "content": {
                  "application/json": {
                    "schema": {
                      "$ref": "#/components/schemas/SessionPublicCancelResponse"
                    }
                  }
                },
                "description": "Accepted"
              }
            }
          },
          "remote": {
            "summary": "Request cancellation of the current turn in a remote-control session",
            "description": "Shares public gateway authentication with cloud sessions; this endpoint requires the business Scope stated below. No controller device ID or pairing is required. The target remote-control master switch must be enabled. If explicitly disabled, returns 403 FORBIDDEN with detail.reason=ACP_HOST_DISABLED; rejected write requests return detail.acceptance=not_accepted. An explicitly nonexistent session returns 404 NOT_FOUND with detail.reason=SESSION_NOT_FOUND. Commands route only to target connections signed in to the currently authenticated account. Offline targets, unknown targets, and targets belonging to other accounts all return device unavailable. Unknown request body fields are rejected. All write operations require Idempotency-Key. Do not retry automatically after a timeout or disconnection, even with the same key: acceptance may be unknown, desktop deduplication is bounded, and persistence across restarts is not guaranteed. Errors include detail.acceptance (not_accepted or unknown). No queuing, offline execution, or automatic fallback to cloud is provided. Send an empty JSON object. A validated cancellation acknowledgment returns 202 and status=cancelling, which does not mean execution has stopped; confirm the terminal event separately. Conditional cancellation of a specified turn is unsupported.",
            "parameters": [
              {
                "description": "Opaque target device identifier, possibly including suffixes such as :dev. The target connection must belong to the currently authenticated account.",
                "explode": false,
                "in": "query",
                "name": "device_id",
                "required": true,
                "schema": {
                  "description": "Opaque target device identifier, possibly including suffixes such as :dev. The target connection must belong to the currently authenticated account.",
                  "maxLength": 256,
                  "type": "string"
                }
              },
              {
                "description": "Session identifier on the target device.",
                "in": "path",
                "name": "session_id",
                "required": true,
                "schema": {
                  "description": "Session identifier on the target device.",
                  "maxLength": 256,
                  "type": "string"
                }
              },
              {
                "description": "A stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.",
                "in": "header",
                "name": "Idempotency-Key",
                "required": true,
                "schema": {
                  "description": "A stable key scoped to the account, device, session, and operation. Slashes, backslashes, whitespace, and control characters are not allowed. Credentials and controller IDs are not part of the key.",
                  "maxLength": 128,
                  "minLength": 1,
                  "type": "string"
                }
              }
            ],
            "requestBody": {
              "content": {
                "application/json": {
                  "examples": {
                    "remote-empty": {
                      "value": {}
                    }
                  },
                  "schema": {
                    "$ref": "#/components/schemas/SessionPublicRemoteCancelInBody"
                  }
                }
              },
              "required": true
            },
            "responses": {
              "202": {
                "content": {
                  "application/json": {
                    "schema": {
                      "$ref": "#/components/schemas/SessionPublicRemoteCancelResponse"
                    }
                  }
                },
                "description": "Accepted"
              }
            }
          }
        },
        "x-supported-session-types": [
          "cloud",
          "remote"
        ]
      }
    }
  },
  "info": {
    "title": "Cancel the current turn",
    "version": "2026-11-24"
  },
  "servers": [
    {
      "url": "https://openapi.qwenwork.ai"
    }
  ]
}
Back to the OpenAPI overview.