Claude Platform Docs

Heartbeat aufzeichnen

$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

Hinweis: Diese Endpunkte werden automatisch vom vorgefertigten Environment-Worker aufgerufen, der in den SDKs und der CLI bereitgestellt wird, um Sessions mit selbst gehosteten Sandbox-Umgebungen zu orchestrieren. Sie sind hier als Referenz aufgeführt; du musst sie nicht direkt aufrufen.

Zeichne einen Heartbeat für ein Arbeitselement auf, um die Lease aufrechtzuerhalten.

Parameters
environmentID: string⁠Path parameter
workID: string⁠Path parameter
desiredTTLSeconds?: optional int⁠Query parameter

Desired TTL in seconds

expectedLastHeartbeat?: optional string⁠Query parameter

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>⁠Header parameter

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 most recent heartbeat recorded for this work item, or an empty string if none has been recorded

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

Heartbeat aufzeichnen
<?php

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

use Anthropic\Client;
use Anthropic\Beta\AnthropicBeta;

$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"
}