Claude Platform Docs

Registrar heartbeat

$client->beta->environments->work->heartbeat(string workID, string environmentID, ?int desiredTTLSeconds, ?string expectedLastHeartbeat, ?list<AnthropicBeta> betas): SelfHostedWorkHeartbeatResponse
POST/v1/environments/{environment_id}/work/{work_id}/heartbeat

Observação: esses endpoints são chamados automaticamente pelo worker de ambiente pré-construído fornecido nos SDKs e na CLI, para orquestrar sessões com ambientes sandbox auto-hospedados. Eles estão incluídos aqui como referência; você não precisa invocá-los diretamente.

Registre um heartbeat para um item de trabalho para manter a concessão (lease).

Parameters
environmentID: string
workID: string
desiredTTLSeconds?:optional int

Desired TTL in seconds

expectedLastHeartbeat?:optional string

Expected last_heartbeat for conditional update (optimistic concurrency). Use literal 'NO_HEARTBEAT' to claim an unclaimed lease (first heartbeat). For subsequent heartbeats, echo the server's previous last_heartbeat value exactly. Returns 412 Precondition Failed if the actual value doesn't match.

betas?:optional list<AnthropicBeta>

Optional header to specify the beta version(s) you want to use.

Returns
class SelfHostedWorkHeartbeatResponse { $type = 'work_heartbeat'; $lastHeartbeat; $leaseExtended; /* 2 more */ }
"work_heartbeat" type

The type of response

string lastHeartbeat

RFC 3339 timestamp of the actual heartbeat from DB

bool leaseExtended

Whether the heartbeat succeeded in extending the lease

State state

Current state of the work item (active/stopping/stopped)

int ttlSeconds

Effective TTL applied to the lease

Registrar heartbeat
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

$client = new Client(apiKey: 'my-anthropic-api-key');

$betaSelfHostedWorkHeartbeatResponse = $client
  ->beta
  ->environments
  ->work
  ->heartbeat(
  'work_id',
  environmentID: 'env_011CZkZ9X2dpNyB7HsEFoRfW',
  desiredTTLSeconds: 0,
  expectedLastHeartbeat: 'expected_last_heartbeat',
  betas: [AnthropicBeta::MESSAGE_BATCHES_2024_09_24],
);

var_dump($betaSelfHostedWorkHeartbeatResponse);
Returns Examples
Response 200
{
  "last_heartbeat": "last_heartbeat",
  "lease_extended": true,
  "state": "queued",
  "ttl_seconds": 0,
  "type": "work_heartbeat"
}