轮询认领工作行
为调用方认领环境中最早的待处理工作行。返回的工作行处于租约状态:通过 ack 确认、心跳续租和 stop 释放,期间始终携带 poll 返回的 generation。block_ms 大于零时,调用将长轮询直到有工作到达或预算耗尽(届时返回空响应)。成功的 poll 即一次认领:不要对它做幂等重试。
GET
/
v1
/
environments
/
{environment_id}
/
work
/
poll
轮询认领工作行
curl --request GET \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/poll \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/poll"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/poll', 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/poll",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/poll"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.moonshot.cn/v1/environments/{environment_id}/work/poll")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/poll")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "work_01h455vb4pex5vsknk084sn02q",
"session_id": "sesn_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"status": "queued",
"generation": 1,
"worker_id": "worker-1",
"lease_ttl_ms": 300000,
"created_at": "2026-09-20T12:00:00Z",
"claimed_at": "2026-09-20T12:00:00Z",
"secret": "eyJzZXNzaW9uc190b2tlbiI6InN3dC1hYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODlBQkNERUZHIn0"
}{
"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>"
}
}请求头
查询参数
响应
已投递的工作行;若预算耗尽仍无待处理工作,则返回 204。
自托管工作队列中的一行:其沙箱工具调用在环境属主的 worker 上执行的会话。GET /v1/environments/{environment_id}/work/poll 投递工作行(ack 前仍为 queued);其携带的 generation 是 fencing token,后续每次 ack、心跳、stop 都必须携带。user.tool_result 回写无需显式携带:secret 中的会话级 work token 已绑定签发代次,平台由它派生 fencing。
此页面对您有帮助吗?
⌘I
轮询认领工作行
curl --request GET \
--url https://api.moonshot.cn/v1/environments/{environment_id}/work/poll \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.moonshot.cn/v1/environments/{environment_id}/work/poll"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.moonshot.cn/v1/environments/{environment_id}/work/poll', 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/poll",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/environments/{environment_id}/work/poll"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.moonshot.cn/v1/environments/{environment_id}/work/poll")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/environments/{environment_id}/work/poll")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "work_01h455vb4pex5vsknk084sn02q",
"session_id": "sesn_01h455vb4pex5vsknk084sn02q",
"environment_id": "env_01h455vb4pex5vsknk084sn02q",
"status": "queued",
"generation": 1,
"worker_id": "worker-1",
"lease_ttl_ms": 300000,
"created_at": "2026-09-20T12:00:00Z",
"claimed_at": "2026-09-20T12:00:00Z",
"secret": "eyJzZXNzaW9uc190b2tlbiI6InN3dC1hYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODlBQkNERUZHIn0"
}{
"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>"
}
}