确认收到已投递的工作项
确认收到已投递的工作项,并将其状态从 queued 改为 starting。调用会记录 acknowledged_at。如果 worker 未在固定的 5000ms 确认窗口内完成确认,后台任务会将该项退回队列。收到工作项后应立即确认,再启动较慢的执行器。代次过期时返回 412 failed_precondition_error。如果路径中的环境与工作项所属环境不同,则返回 404,且响应不包含租约状态。
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack \
--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}/ack"
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}/ack', 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}/ack",
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}/ack"
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}/ack")
.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}/ack")
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{
"id": "work_01h455vb4pex5vsknk084sn02q",
"session_id": "sesn_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"status": "starting",
"generation": 1,
"worker_id": "worker-1",
"lease_ttl_ms": 300000,
"created_at": "2026-09-20T12:00:00Z",
"claimed_at": "2026-09-20T12:00:00Z",
"acknowledged_at": "2026-09-20T12:01:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "failed_precondition_error",
"message": "The resource state does not permit this operation.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}请求头
请求体
WorkItem 返回的 worker ID 和 generation。
响应
已确认的工作项,状态转为 starting。
自托管工作队列中的一个工作项,对应一个会话;该会话的沙箱工具调用由环境所有者的 worker 执行。GET /v1/environments/{environment_id}/work/poll 投递工作项,确认收到前状态仍为 queued。响应中的 generation 是 fencing token,后续确认、心跳续租和停止请求都必须携带。回写 user.tool_result 时无需单独提供 token:secret 中的会话级 work token 已绑定签发代次,平台会据此执行 fencing 检查。
此工作项所属会话的凭据包,仅在认领该项的轮询响应中返回。凭据包是 base64url 编码的 JSON 对象。解码后,将 sessions_token 作为 Authorization: Bearer 用于会话写操作(例如 POST /v1/sessions/{id}/events),以及该项的确认、心跳续租和停止请求。token 仅适用于此会话。其他成员为保留字段,请保持原样。工作项完成或被回收时,凭据会失效。回收会将该项交给其他 worker,并签发新凭据。其他端点不会返回此凭据包。请按机密处理,不要记录日志或持久化。
"eyJzZXNzaW9uc190b2tlbiI6InN3dC1hYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODlBQkNERUZHIn0"
此页面对您有帮助吗?
curl --request POST \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/{id}/ack \
--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}/ack"
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}/ack', 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}/ack",
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}/ack"
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}/ack")
.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}/ack")
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{
"id": "work_01h455vb4pex5vsknk084sn02q",
"session_id": "sesn_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"status": "starting",
"generation": 1,
"worker_id": "worker-1",
"lease_ttl_ms": 300000,
"created_at": "2026-09-20T12:00:00Z",
"claimed_at": "2026-09-20T12:00:00Z",
"acknowledged_at": "2026-09-20T12:01:00Z"
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "failed_precondition_error",
"message": "The resource state does not permit this operation.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}