停止或完成工作行
不传 final_status 时请求优雅停止:工作行进入 stopping,worker 在下次心跳中收到该状态,取消在飞工具,在续租期间完成结果回写,再提交 final_status: completed。确认时若会话仍忙碌则取消会话,并将工作行释放为 completed。
空闲 worker 直接提交 completed,保留会话。待处理输入、活跃 loop、尚未完成的取消或恢复会返回 409 failed_precondition_error,worker 应用同一租约继续服务。已终止或取消已完成的会话可保留排队输入。释放后的新输入或 continue 为会话创建新的工作行。
会话级 work token 只能停止绑定的工作行,worker 与代次必须匹配。过期租约返回 412 failed_precondition_error,worker 必须放弃该租约。停止请求在租约回收后仍然保留。
POST
/
v1
/
environments
/
{environment_id}
/
work
/
{id}
/
stop
停止或完成工作行
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "worker-1",
"generation": 1
}
'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop"
payload = {
"worker_id": "worker-1",
"generation": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({worker_id: 'worker-1', generation: 1})
};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'worker_id' => 'worker-1',
'generation' => 1
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop"
payload := strings.NewReader("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}"
response = http.request(request)
puts response.read_body{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}请求头
本次请求使用的 API 版本,格式为 YYYY-MM-DD。发送 2026-09-01-beta 即使用本文档所述版本。/v1/files* 之外必传:未携带请求头将被拒绝并返回 400 invalid_request_error;在 /v1/files* 上缺省时选择兼容行为。所有端点对未知取值均返回 400 invalid_request_error。
平台当前支持的 API 版本。新的日期版本发布时加入;版本在公告的 Sunset 日期后移除。
可用选项:
2026-09-01-beta 请求体
application/json
响应
已请求停止,或已确认 worker 完成。
此页面对您有帮助吗?
⌘I
停止或完成工作行
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "worker-1",
"generation": 1
}
'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop"
payload = {
"worker_id": "worker-1",
"generation": 1
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({worker_id: 'worker-1', generation: 1})
};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'worker_id' => 'worker-1',
'generation' => 1
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop"
payload := strings.NewReader("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/stop")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"worker-1\",\n \"generation\": 1\n}"
response = http.request(request)
puts response.read_body{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}