ハートビートを記録
注: これらのエンドポイントは、セルフホスト型サンドボックス環境でセッションをオーケストレーションするために、SDKおよびCLIで提供される事前構築済みの環境ワーカーによって自動的に呼び出されます。参考としてここに記載していますが、直接呼び出す必要はありません。
リースを維持するために、ワークアイテムのハートビートを記録します。
Parameters
params BetaEnvironmentWorkHeartbeatParams
Desired TTL in seconds
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. The server does not compare the value when the work item is 'stopping' or 'stopped'.
Betas []AnthropicBeta OptionalHeader parameterOptional header to specify the beta version(s) you want to use.
Optional header to specify the beta version(s) you want to use.
const AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24"Deprecated
const AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31"Deprecated
const AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25"Deprecated
const AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01"Deprecated
const AnthropicBetaTokenEfficientTools2025_02_19 AnthropicBeta = "token-efficient-tools-2025-02-19"Deprecated
const AnthropicBetaFilesAPI2025_04_14 AnthropicBeta = "files-api-2025-04-14"Deprecated
const AnthropicBetaExtendedCacheTTL2025_04_11 AnthropicBeta = "extended-cache-ttl-2025-04-11"Deprecated
const AnthropicBetaSkills2025_10_02 AnthropicBeta = "skills-2025-10-02"Deprecated
const AnthropicBetaCacheDiagnosis2026_04_07 AnthropicBeta = "cache-diagnosis-2026-04-07"Deprecated
const AnthropicBetaCEUserManagement2026_07_13 AnthropicBeta = "ce-user-management-2026-07-13"Deprecated
Returns
type BetaSelfHostedWorkHeartbeatResponse struct { Type: "work_heartbeat"; LastHeartbeat; LeaseExtended; /* 2 more */ }Response after recording a heartbeat for a work item.
Response after recording a heartbeat for a work item.
Type WorkHeartbeatThe type of response
The type of response
RFC 3339 timestamp of the most recent heartbeat recorded for this work item, or an empty string if none has been recorded
Whether the heartbeat succeeded in extending the lease
State BetaSelfHostedWorkHeartbeatResponseStateCurrent state of the work item (active/stopping/stopped)
Current state of the work item (active/stopping/stopped)
Effective TTL applied to the lease
Errors
Any method can also return the general HTTP errors.
expected_last_heartbeat does not match the stored heartbeat, so another worker may hold the lease.
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go/v2"
"github.com/anthropics/anthropic-sdk-go/v2/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("my-anthropic-api-key"),
)
betaSelfHostedWorkHeartbeatResponse, err := client.Beta.Environments.Work.Heartbeat(
context.TODO(),
"work_id",
anthropic.BetaEnvironmentWorkHeartbeatParams{
EnvironmentID: "env_011CZkZ9X2dpNyB7HsEFoRfW",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", betaSelfHostedWorkHeartbeatResponse.LastHeartbeat)
}{
"last_heartbeat": "last_heartbeat",
"lease_extended": true,
"state": "queued",
"ttl_seconds": 0,
"type": "work_heartbeat"
}Returns Examples
{
"last_heartbeat": "last_heartbeat",
"lease_extended": true,
"state": "queued",
"ttl_seconds": 0,
"type": "work_heartbeat"
}