curl --request POST \
--url http://127.0.0.1:8400/v1/environments/{id}/work/claim \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "<string>",
"block_ms": 0,
"reclaim_older_than_ms": 1
}
'import requests
url = "http://127.0.0.1:8400/v1/environments/{id}/work/claim"
payload = {
"worker_id": "<string>",
"block_ms": 0,
"reclaim_older_than_ms": 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: '<string>', block_ms: 0, reclaim_older_than_ms: 1})
};
fetch('http://127.0.0.1:8400/v1/environments/{id}/work/claim', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8400",
CURLOPT_URL => "http://127.0.0.1:8400/v1/environments/{id}/work/claim",
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' => '<string>',
'block_ms' => 0,
'reclaim_older_than_ms' => 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 := "http://127.0.0.1:8400/v1/environments/{id}/work/claim"
payload := strings.NewReader("{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 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("http://127.0.0.1:8400/v1/environments/{id}/work/claim")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://127.0.0.1:8400/v1/environments/{id}/work/claim")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 1\n}"
response = http.request(request)
puts response.read_body{
"work_id": "<string>",
"session_id": "<string>",
"session_secret": "<string>",
"lease_generation": 123,
"lease_expires_at": "2023-11-07T05:31:56Z",
"environment": {
"network": "none",
"allowed_hosts": [
"<string>"
],
"git": {
"allowed_hostnames": [
"<string>"
],
"allowed_push_refs": [
"<string>"
]
},
"mcp": {
"allowed_hostnames": [
"<string>"
]
},
"image": "<string>",
"packages": {
"apt": [
"<string>"
],
"pip": [
"<string>"
],
"npm": [
"<string>"
]
}
}
}{
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "model_not_mapped",
"tool": "<string>",
"clashes_with": "<string>"
}
}Claim a work item
Worker side. Claims the oldest claimable work item for this environment and
starts a 60 second lease. Waits up to block_ms for work to appear and
answers as soon as an item is queued. Returns 204 when there is nothing.
Claimable: an item that is ready, or one whose lease ran out (a worker that
died). With reclaim_older_than_ms, also an item whose lease is still live
but was last renewed at least that long ago. Values below 30000 are raised
to 30000, because a healthy worker renews every 20 s. Values of 60000 or
more add nothing. Each claim raises the item’s lease_generation, so the old
worker gets 409 lease_stale on its next call. Tool calls the old worker
took but did not answer are handed out again.
The server also returns expired leases to the queue every 5 seconds.
Each session has at most one open work item, queued the first time a turn
needs a sandbox tool; the database enforces this. Soft affinity: for up to
10 seconds after a worker completes or releases a session’s item, a claim from
that same worker is preferred over a claim from another worker (only while that
worker was seen in the last 60 seconds). A ready item of a session that has
ended (archived, deleted or idle past sessions.idle_timeout) is cancelled when
a worker would claim it, and the claim looks for the next item. Auth: environment key of this environment.
curl --request POST \
--url http://127.0.0.1:8400/v1/environments/{id}/work/claim \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"worker_id": "<string>",
"block_ms": 0,
"reclaim_older_than_ms": 1
}
'import requests
url = "http://127.0.0.1:8400/v1/environments/{id}/work/claim"
payload = {
"worker_id": "<string>",
"block_ms": 0,
"reclaim_older_than_ms": 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: '<string>', block_ms: 0, reclaim_older_than_ms: 1})
};
fetch('http://127.0.0.1:8400/v1/environments/{id}/work/claim', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "8400",
CURLOPT_URL => "http://127.0.0.1:8400/v1/environments/{id}/work/claim",
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' => '<string>',
'block_ms' => 0,
'reclaim_older_than_ms' => 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 := "http://127.0.0.1:8400/v1/environments/{id}/work/claim"
payload := strings.NewReader("{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 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("http://127.0.0.1:8400/v1/environments/{id}/work/claim")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 1\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://127.0.0.1:8400/v1/environments/{id}/work/claim")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"worker_id\": \"<string>\",\n \"block_ms\": 0,\n \"reclaim_older_than_ms\": 1\n}"
response = http.request(request)
puts response.read_body{
"work_id": "<string>",
"session_id": "<string>",
"session_secret": "<string>",
"lease_generation": 123,
"lease_expires_at": "2023-11-07T05:31:56Z",
"environment": {
"network": "none",
"allowed_hosts": [
"<string>"
],
"git": {
"allowed_hostnames": [
"<string>"
],
"allowed_push_refs": [
"<string>"
]
},
"mcp": {
"allowed_hostnames": [
"<string>"
]
},
"image": "<string>",
"packages": {
"apt": [
"<string>"
],
"pip": [
"<string>"
],
"npm": [
"<string>"
]
}
}
}{
"error": {
"type": "invalid_request_error",
"message": "<string>",
"code": "model_not_mapped",
"tool": "<string>",
"clashes_with": "<string>"
}
}Authorizations
Headers
Body
Response
A work item, with a 60 second lease.