> ## Documentation Index
> Fetch the complete documentation index at: https://oma-codex-339-workspace-permissions.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 记录心跳

> 通过 OMA API 记录心跳。

<Info>每个请求都必须发送 `?beta=true`。</Info>


## OpenAPI

````yaml /openapi/oma.zh.json post /v1/environments/{environment_id}/work/{work_id}/heartbeat
openapi: 3.1.0
info:
  title: OMA API 参考
  version: 1.0.0
  description: Open Managed Agents 应用 API 参考。
servers:
  - url: http://localhost:38080
    description: 本地 OMA 服务器
security:
  - omaApiKey: []
  - omaBearer: []
paths:
  /v1/environments/{environment_id}/work/{work_id}/heartbeat:
    post:
      summary: 记录心跳
      description: 通过 OMA API 记录心跳。
      operationId: >-
        beta_record_heartbeat_v1_environments__environment_id__work__work_id__heartbeat_post
      parameters:
        - name: beta
          in: query
          required: true
          description: 为此接口启用 Beta API 合同，必须为 `true`。
          schema:
            type: boolean
            enum:
              - true
        - name: environment_id
          in: path
          required: true
          schema:
            type: string
            title: 环境 ID
          example: env_011CZkZ9X2dpNyB7HsEFoRfW
        - name: work_id
          in: path
          required: true
          schema:
            type: string
            title: worker ID
        - name: desired_ttl_seconds
          in: query
          required: false
          schema:
            anyOf:
              - type: integer
              - type: 'null'
            description: 期望的 TTL（秒）
            title: 期望 TTL（秒）
          description: 期望的 TTL（秒）
        - name: expected_last_heartbeat
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              用于条件更新（乐观并发）的预期 last_heartbeat。使用字面量 'NO_HEARTBEAT'
              来认领尚未被认领的租约（首次心跳）。对于后续心跳，请原样回显服务端先前的 last_heartbeat 值。如果实际值不匹配，返回
              412 Precondition Failed。
            title: 预期上次心跳
          description: >-
            用于条件更新（乐观并发）的预期 last_heartbeat。使用字面量 'NO_HEARTBEAT'
            来认领尚未被认领的租约（首次心跳）。对于后续心跳，请原样回显服务端先前的 last_heartbeat 值。如果实际值不匹配，返回
            412 Precondition Failed。
          examples:
            first_claim:
              summary: 首次心跳（认领未认领的租约）
              value: NO_HEARTBEAT
            subsequent:
              summary: 后续心跳（回显服务器的值）
              value: '2026-05-14T10:30:45.123456Z'
        - name: anthropic-beta
          in: header
          required: false
          schema:
            type: string
            items:
              type: string
            description: |-
              用于指定要使用的 beta 版本的可选请求头。

              要使用多个 beta，请使用逗号分隔的列表（如 `beta1,beta2`），或为每个 beta 分别指定该请求头。
            title: Anthropic-Beta
            x-stainless-override-schema:
              x-stainless-param: betas
              x-stainless-extend-default: true
              type: array
              description: 用于指定一个或多个 Beta 版本的可选请求头。
              items:
                $ref: '#/components/schemas/AnthropicBeta'
            x-default: managed-agents-2026-04-01
          description: |-
            用于指定要使用的 beta 版本的可选请求头。

            要使用多个 beta，请使用逗号分隔的列表（如 `beta1,beta2`），或为每个 beta 分别指定该请求头。
        - name: anthropic-version
          in: header
          required: false
          schema:
            type: string
            description: |-
              你想使用的 OMA API 版本。

              在此处阅读更多关于版本控制和我们版本历史的信息。
            title: Anthropic-Version
          description: |-
            你想使用的 OMA API 版本。

            在此处阅读更多关于版本控制和我们版本历史的信息。
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: 授权
      responses:
        '200':
          description: 成功的响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaSelfHostedWorkHeartbeatResponse'
        4XX:
          description: |-
            错误响应。

            详见我们的错误文档。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaErrorResponse'
components:
  schemas:
    BetaSelfHostedWorkHeartbeatResponse:
      properties:
        last_heartbeat:
          type: string
          title: 上次心跳
          description: 来自数据库的实际心跳的 RFC 3339 时间戳
        lease_extended:
          type: boolean
          title: 租约是否已延长
          description: 心跳是否成功延长了租约
        state:
          type: string
          enum:
            - queued
            - starting
            - active
            - stopping
            - stopped
          title: 状态
          description: worker 的当前状态（active/stopping/stopped）
        ttl_seconds:
          type: integer
          title: TTL（秒）
          description: 应用于租约的有效 TTL
        type:
          type: string
          const: work_heartbeat
          title: 类型
          description: 响应类型
          default: work_heartbeat
      type: object
      required:
        - last_heartbeat
        - lease_extended
        - state
        - ttl_seconds
        - type
      title: SelfHostedWorkHeartbeatResponse
      description: 为 worker 记录心跳后的响应。
    BetaErrorResponse:
      properties:
        error:
          discriminator:
            mapping:
              api_error:
                $ref: '#/components/schemas/BetaAPIError'
              authentication_error:
                $ref: '#/components/schemas/BetaAuthenticationError'
              billing_error:
                $ref: '#/components/schemas/BetaBillingError'
              invalid_request_error:
                $ref: '#/components/schemas/BetaInvalidRequestError'
              not_found_error:
                $ref: '#/components/schemas/BetaNotFoundError'
              overloaded_error:
                $ref: '#/components/schemas/BetaOverloadedError'
              permission_error:
                $ref: '#/components/schemas/BetaPermissionError'
              rate_limit_error:
                $ref: '#/components/schemas/BetaRateLimitError'
              timeout_error:
                $ref: '#/components/schemas/BetaGatewayTimeoutError'
            propertyName: type
          oneOf:
            - $ref: '#/components/schemas/BetaInvalidRequestError'
            - $ref: '#/components/schemas/BetaAuthenticationError'
            - $ref: '#/components/schemas/BetaBillingError'
            - $ref: '#/components/schemas/BetaPermissionError'
            - $ref: '#/components/schemas/BetaNotFoundError'
            - $ref: '#/components/schemas/BetaRateLimitError'
            - $ref: '#/components/schemas/BetaGatewayTimeoutError'
            - $ref: '#/components/schemas/BetaAPIError'
            - $ref: '#/components/schemas/BetaOverloadedError'
          title: 错误
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: 请求 ID
        type:
          const: error
          default: error
          title: 类型
          type: string
      required:
        - error
        - request_id
        - type
      title: ErrorResponse
      type: object
    BetaAPIError:
      properties:
        message:
          default: Internal server error
          title: 消息
          type: string
        type:
          const: api_error
          default: api_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: APIError
      type: object
    BetaAuthenticationError:
      properties:
        message:
          default: Authentication error
          title: 消息
          type: string
        type:
          const: authentication_error
          default: authentication_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: AuthenticationError
      type: object
    BetaBillingError:
      properties:
        message:
          default: Billing error
          title: 消息
          type: string
        type:
          const: billing_error
          default: billing_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: BillingError
      type: object
    BetaInvalidRequestError:
      properties:
        message:
          default: Invalid request
          title: 消息
          type: string
        type:
          const: invalid_request_error
          default: invalid_request_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: InvalidRequestError
      type: object
    BetaNotFoundError:
      properties:
        message:
          default: Not found
          title: 消息
          type: string
        type:
          const: not_found_error
          default: not_found_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: NotFoundError
      type: object
    BetaOverloadedError:
      properties:
        message:
          default: Overloaded
          title: 消息
          type: string
        type:
          const: overloaded_error
          default: overloaded_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: OverloadedError
      type: object
    BetaPermissionError:
      properties:
        message:
          default: Permission denied
          title: 消息
          type: string
        type:
          const: permission_error
          default: permission_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: PermissionError
      type: object
    BetaRateLimitError:
      properties:
        message:
          default: Rate limited
          title: 消息
          type: string
        type:
          const: rate_limit_error
          default: rate_limit_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: RateLimitError
      type: object
    BetaGatewayTimeoutError:
      properties:
        message:
          default: Request timeout
          title: 消息
          type: string
        type:
          const: timeout_error
          default: timeout_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: GatewayTimeoutError
      type: object
  securitySchemes:
    omaApiKey:
      type: apiKey
      in: header
      name: X-Api-Key
      description: OMA 工作区 API 密钥。
      x-default: sk-ant-local-default
    omaBearer:
      type: http
      scheme: bearer
      description: 以 Bearer 令牌形式发送的 OMA 工作区 API 密钥。

````