> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phala.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Apply staged CVM changes

> Applies every staged change as one PATCH /cvms/{cvm_id}: one VMM update and at most one restart; a stopped CVM stays stopped. Rejected with ERR-03-053 when the CVM's compose changed since the first change was staged. Accepts the same X-Compose-Hash, X-Transaction-Hash and X-Prepare-Only headers and returns the same responses as PATCH /cvms/{cvm_id}; the staged changes are kept until an apply dispatches them. A phase 2 apply is rejected with ERR-03-054 when changes were staged after its phase 1; apply again without the headers to prepare them. An update committed through a commit token (POST /cvms/{cvm_id}/commit-update) does not clear them: the next apply is then rejected with ERR-03-053, and the staged changes must be discarded.



## OpenAPI

````yaml /openapi.json post /api/v1/cvms/{cvm_id}/draft/apply
openapi: 3.1.0
info:
  title: Phala Cloud API
  version: 0.1.0
servers:
  - url: https://cloud-api.phala.com
security: []
tags:
  - name: CVMs
    description: Confidential Virtual Machine (CVM) lifecycle management on Phala Network
    x-mint:
      href: https://cloud.phala.network/api-reference/cvms
  - name: Apps
    description: App template management and CVM deployment from app blueprints
    x-mint:
      href: https://cloud.phala.network/api-reference/apps
  - name: Webhooks
    description: Manage webhook endpoints and monitor delivery history
    x-mint:
      href: https://cloud.phala.network/api-reference/webhooks
  - name: SSH Keys
    description: SSH public key management for CVM access
    x-mint:
      href: https://cloud.phala.network/api-reference/ssh-keys
  - name: KMS
    description: >-
      Key Management Service — key derivation, on-chain anchoring, and
      inspection
    x-mint:
      href: https://cloud.phala.network/api-reference/kms
  - name: Instance Types
    description: Available hardware configurations for CVM deployment
    x-mint:
      href: https://cloud.phala.network/api-reference/instance-types
  - name: Attestations
    description: Remote attestation and TEE verification endpoints
    x-mint:
      href: https://cloud.phala.network/api-reference/attestations
paths:
  /api/v1/cvms/{cvm_id}/draft/apply:
    post:
      tags:
        - CVMs
        - cvms-draft
      summary: Apply staged CVM changes
      description: >-
        Applies every staged change as one PATCH /cvms/{cvm_id}: one VMM update
        and at most one restart; a stopped CVM stays stopped. Rejected with
        ERR-03-053 when the CVM's compose changed since the first change was
        staged. Accepts the same X-Compose-Hash, X-Transaction-Hash and
        X-Prepare-Only headers and returns the same responses as PATCH
        /cvms/{cvm_id}; the staged changes are kept until an apply dispatches
        them. A phase 2 apply is rejected with ERR-03-054 when changes were
        staged after its phase 1; apply again without the headers to prepare
        them. An update committed through a commit token (POST
        /cvms/{cvm_id}/commit-update) does not clear them: the next apply is
        then rejected with ERR-03-053, and the staged changes must be discarded.
      operationId: apply_cvm_draft_api_v1_cvms__cvm_id__draft_apply_post
      parameters:
        - name: cvm_id
          in: path
          required: true
          schema:
            type: string
            title: Cvm Id
        - name: X-Compose-Hash
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Compose-Hash
        - name: X-Transaction-Hash
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Transaction-Hash
        - name: X-Prepare-Only
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: X-Prepare-Only
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - $ref: '#/components/schemas/ApplyCvmDraftRequest'
                - type: 'null'
              title: Body
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '404':
          description: 'ERR-03-052: the CVM has no staged changes'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StructuredErrorResponse'
        '409':
          description: >-
            ERR-03-053: the CVM's compose changed since the changes were staged;
            ERR-03-054: changes were staged after the apply's phase 1; or
            another operation is in progress
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StructuredErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '465':
          description: Compose hash registration required (Phase 1)
components:
  schemas:
    ApplyCvmDraftRequest:
      properties:
        base_compose_hash:
          anyOf:
            - type: string
            - type: 'null'
          title: Base Compose Hash
          description: >-
            The CVM compose hash the caller reviewed the changes against.
            Defaults to the draft's base; after ERR-03-053, send its
            current_compose_hash to apply anyway.
      type: object
      title: ApplyCvmDraftRequest
    StructuredErrorResponse:
      properties:
        error_code:
          type: string
          title: Error Code
        message:
          type: string
          title: Message
        details:
          anyOf:
            - items:
                $ref: '#/components/schemas/ErrorDetail'
              type: array
            - type: 'null'
          title: Details
        suggestions:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Suggestions
        links:
          anyOf:
            - items:
                $ref: '#/components/schemas/ErrorLink'
              type: array
            - type: 'null'
          title: Links
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Request Id
      type: object
      required:
        - error_code
        - message
      title: StructuredErrorResponse
      description: OpenAPI shape for the global structured-error HTTP envelope.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ErrorDetail:
      properties:
        field:
          anyOf:
            - type: string
            - type: 'null'
          title: Field
        value:
          anyOf:
            - {}
            - type: 'null'
          title: Value
        message:
          anyOf:
            - type: string
            - type: 'null'
          title: Message
      type: object
      title: ErrorDetail
      description: Detailed information about a specific aspect of the error.
    ErrorLink:
      properties:
        url:
          type: string
          title: Url
        label:
          type: string
          title: Label
      type: object
      required:
        - url
        - label
      title: ErrorLink
      description: A helpful link related to the error.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.