Claude Platform Docs

ハートビートを記録

$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

注: これらのエンドポイントは、セルフホスト型サンドボックス環境でセッションをオーケストレーションするために、SDKおよびCLIで提供される事前構築済みの環境ワーカーによって自動的に呼び出されます。参考としてここに記載していますが、直接呼び出す必要はありません。

リースを維持するために、ワークアイテムのハートビートを記録します。

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

ハートビートを記録
<?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"
}