> ## 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.

# 获取 worker

> 通过 OMA API 获取 worker。

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


## OpenAPI

````yaml /openapi/oma.zh.json get /v1/environments/{environment_id}/work/{work_id}
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}:
    get:
      summary: 获取 worker
      description: 通过 OMA API 获取 worker。
      operationId: beta_get_work_v1_environments__environment_id__work__work_id__get
      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: 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 版本。

            在此处阅读更多关于版本控制和我们版本历史的信息。
      responses:
        '200':
          description: 成功的响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaSelfHostedWork'
        4XX:
          description: |-
            错误响应。

            详见我们的错误文档。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaErrorResponse'
components:
  schemas:
    BetaSelfHostedWork:
      properties:
        acknowledged_at:
          anyOf:
            - type: string
            - type: 'null'
          title: 确认时间
          description: 该 worker 被确认接收并分配给自托管 sandbox 时的 RFC 3339 时间戳
        created_at:
          type: string
          title: 创建时间
          description: 创建 worker 时的 RFC 3339 时间戳
        data:
          $ref: '#/components/schemas/BetaSessionWorkData'
          description: 实际要执行的 worker
        environment_id:
          type: string
          title: 环境 ID
          description: 此 worker 所属的环境标识符（例如 `env_...`）
        id:
          type: string
          title: ID
          description: worker 标识符（例如 'work_...'）
        latest_heartbeat_at:
          anyOf:
            - type: string
            - type: 'null'
          title: 最近心跳时间
          description: 最近一次心跳的 RFC 3339 时间戳
        metadata:
          additionalProperties:
            type: string
          type: object
          title: 元数据
          description: 与此 worker 关联的用户提供的元数据键值对
        secret:
          anyOf:
            - type: string
            - type: 'null'
          title: 密钥
          description: 环境 worker 用于执行此 worker 的凭据载荷。轮询 worker 时可能填充该字段；其他所有获取路径上均为 null。
        started_at:
          anyOf:
            - type: string
            - type: 'null'
          title: 开始时间
          description: worker 执行开始的 RFC 3339 时间戳
        state:
          type: string
          enum:
            - queued
            - starting
            - active
            - stopping
            - stopped
          title: 状态
          description: worker 的当前状态
        stop_requested_at:
          anyOf:
            - type: string
            - type: 'null'
          title: 请求停止时间
          description: 请求停止时的 RFC 3339 时间戳
        stopped_at:
          anyOf:
            - type: string
            - type: 'null'
          title: 停止时间
          description: worker 执行停止的 RFC 3339 时间戳
        type:
          type: string
          const: work
          title: 类型
          description: 对象类型（始终为 'work'）
          default: work
      type: object
      required:
        - acknowledged_at
        - created_at
        - data
        - environment_id
        - id
        - latest_heartbeat_at
        - metadata
        - secret
        - started_at
        - state
        - stop_requested_at
        - stopped_at
        - type
      title: SelfHostedWork
      description: |-
        表示自托管环境中一个工作单元的 worker。

        woker 在创建会话时，或长期休眠的会话
        收到新消息时进入队列。环境 worker 会轮询待执行的 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
    BetaSessionWorkData:
      properties:
        id:
          type: string
          title: ID
          description: 会话标识符（例如 'session_...'）
        type:
          type: string
          const: session
          title: 类型
          description: worker 数据的类型
      type: object
      required:
        - id
        - type
      title: SessionWorkData
      description: |-
        会话 worker 的 worker 数据。

        当 worker 表示需要在自托管环境中执行的会话时，
        使用此资源类型。
    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 密钥。

````