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

# Stage CVM changes

> Adds an update to the CVM's staged changes without restarting it. The body is the PATCH /cvms/{cvm_id} body. Applying runs the staged compose changes in order on the CVM's compose; other fields take the last staged value. Scripts this change sends are reviewed as the draft would leave them. The first staged change records the CVM's compose hash.



## OpenAPI

````yaml /openapi.json patch /api/v1/cvms/{cvm_id}/draft
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:
    patch:
      tags:
        - CVMs
        - cvms-draft
      summary: Stage CVM changes
      description: >-
        Adds an update to the CVM's staged changes without restarting it. The
        body is the PATCH /cvms/{cvm_id} body. Applying runs the staged compose
        changes in order on the CVM's compose; other fields take the last staged
        value. Scripts this change sends are reviewed as the draft would leave
        them. The first staged change records the CVM's compose hash.
      operationId: stage_cvm_draft_api_v1_cvms__cvm_id__draft_patch
      parameters:
        - name: cvm_id
          in: path
          required: true
          schema:
            type: string
            title: Cvm Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCvmRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CvmDraftResponse'
        '409':
          description: >-
            ERR-03-054: another request changed the staged changes at the same
            time
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StructuredErrorResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    UpdateCvmRequest:
      properties:
        docker_compose_file:
          anyOf:
            - type: string
            - type: 'null'
          title: Docker Compose File
          description: Docker Compose YAML content
        pre_launch_script:
          anyOf:
            - type: string
            - type: 'null'
          title: Pre Launch Script
          description: Shell script executed before containers start
        allowed_envs:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Allowed Envs
          description: Allowed environment variable names (env_keys)
        public_logs:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Public Logs
          description: Expose container logs publicly
        public_sysinfo:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Public Sysinfo
          description: Expose system info publicly
        public_tcbinfo:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Public Tcbinfo
          description: Expose TCB attestation info publicly
        compose:
          anyOf:
            - $ref: '#/components/schemas/ComposePatch'
            - type: 'null'
          description: JSON Merge Patch of the app compose
        init_scripts:
          anyOf:
            - items:
                type: string
                enum:
                  - docker_cleanup
                  - env_merge
              type: array
            - type: 'null'
          title: Init Scripts
          description: >-
            Platform init scripts this CVM runs, replacing the current set.
            Enabling docker_cleanup requires confirm_data_wipe.
        confirm_data_wipe:
          type: boolean
          title: Confirm Data Wipe
          description: >-
            Confirms turning on docker_cleanup or
            requirements.ephemeral_data_disk, which erase data on every boot.
          default: false
        encrypted_env:
          anyOf:
            - type: string
            - type: 'null'
          title: Encrypted Env
          description: Encrypted environment variables as hex string
        user_config:
          anyOf:
            - type: string
            - type: 'null'
          title: User Config
          description: User configuration string
        gpus:
          anyOf:
            - $ref: '#/components/schemas/GpuConfig'
            - type: 'null'
          description: GPU configuration
        vcpu:
          anyOf:
            - type: integer
            - type: 'null'
          title: Vcpu
          description: Number of vCPUs
        memory:
          anyOf:
            - type: integer
            - type: 'null'
          title: Memory
          description: Memory in MB
        disk_size:
          anyOf:
            - type: integer
            - type: 'null'
          title: Disk Size
          description: Disk size in GB
        instance_type:
          anyOf:
            - type: string
            - type: 'null'
          title: Instance Type
          description: Instance type identifier (e.g. tdx.medium)
        image:
          anyOf:
            - type: string
            - type: 'null'
          title: Image
          description: OS image name or slug from available-os-images
        shutdown_timeout:
          anyOf:
            - type: integer
              maximum: 1200
              minimum: 10
            - type: 'null'
          title: Shutdown Timeout
          description: >-
            Timeout in seconds for graceful shutdown. null uses the platform
            default.
        allow_force_stop:
          type: boolean
          title: Allow Force Stop
          description: >-
            When true, skips graceful shutdown and force stops the CVM
            immediately.
          default: false
      type: object
      title: UpdateCvmRequest
      description: PATCH request body — all fields optional, only set fields are applied.
    CvmDraftResponse:
      properties:
        base_compose_hash:
          anyOf:
            - type: string
            - type: 'null'
          title: Base Compose Hash
          description: The CVM's compose hash when the first change was staged
        current_compose_hash:
          anyOf:
            - type: string
            - type: 'null'
          title: Current Compose Hash
          description: >-
            The CVM's compose hash now; apply is rejected while it differs from
            the base
        preview_compose_hash:
          type: string
          title: Preview Compose Hash
          description: >-
            The compose hash the CVM runs after apply. For contract-owned KMS,
            register it on-chain before applying.
        patch:
          additionalProperties: true
          type: object
          title: Patch
          description: >-
            The one PATCH /cvms/{cvm_id} body the apply sends: the entries
            applied in order to the CVM's current compose
        entries:
          items:
            $ref: '#/components/schemas/CvmDraftEntry'
          type: array
          title: Entries
          description: The staged patches, oldest first
      type: object
      required:
        - base_compose_hash
        - current_compose_hash
        - preview_compose_hash
        - patch
        - entries
      title: CvmDraftResponse
      description: The CVM's staged changes and the compose hash applying them produces.
    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
    ComposePatch:
      properties:
        secure_time:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Secure Time
        swap_size:
          anyOf:
            - type: string
            - type: 'null'
          title: Swap Size
          description: Swap size, e.g. "2G"
        storage_discard:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Storage Discard
        snapshotter:
          anyOf:
            - type: string
              enum:
                - overlayfs
                - stargz
            - type: 'null'
          title: Snapshotter
          description: Only with the nerdctl-compose runner
        gateway_enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Gateway Enabled
          description: >-
            Route the CVM through dstack-gateway. Enabling needs a gateway for
            the CVM's node; disabling removes the instance from the gateway
            after the update.
        port_policy:
          anyOf:
            - $ref: '#/components/schemas/PortPolicy'
            - type: 'null'
        event_log_version:
          anyOf:
            - type: integer
              enum:
                - 1
                - 2
            - type: 'null'
          title: Event Log Version
        requirements:
          anyOf:
            - $ref: '#/components/schemas/RequirementsPatch'
            - type: 'null'
        bash_script:
          anyOf:
            - type: string
            - type: 'null'
          title: Bash Script
          description: Script run by the bash runner
        kms_enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Kms Enabled
        key_provider:
          anyOf:
            - type: string
              enum:
                - none
                - kms
                - local
                - tpm
            - type: 'null'
          title: Key Provider
        key_provider_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Key Provider Id
        local_key_provider_enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Local Key Provider Enabled
        manifest_version:
          anyOf:
            - type: integer
            - type: string
            - type: 'null'
          title: Manifest Version
        no_instance_id:
          anyOf:
            - type: boolean
            - type: 'null'
          title: No Instance Id
        runner:
          anyOf:
            - type: string
            - type: 'null'
          title: Runner
        storage_fs:
          anyOf:
            - type: string
              enum:
                - ext4
                - zfs
            - type: 'null'
          title: Storage Fs
        verity_volumes:
          anyOf:
            - items:
                $ref: '#/components/schemas/VerityVolume'
              type: array
            - type: 'null'
          title: Verity Volumes
        tproxy_enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Tproxy Enabled
        features:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Features
      additionalProperties: false
      type: object
      title: ComposePatch
      description: |-
        JSON Merge Patch of the CVM's app compose.

        A sent key sets the value, a sent null removes the key, an unsent key is
        unchanged. ``requirements`` merges per key.
    GpuConfig:
      properties:
        gpus:
          items:
            $ref: '#/components/schemas/GpuSpec'
          type: array
          title: Gpus
        attach_mode:
          anyOf:
            - type: string
              enum:
                - listed
                - all
            - type: string
          title: Attach Mode
          default: listed
      type: object
      required:
        - gpus
      title: GpuConfig
    CvmDraftEntry:
      properties:
        user_id:
          type: string
          pattern: ^usr_.+
          format: hashid
          title: HashedId[users]
          description: A hashed identifier that maps to an internal database ID
          examples:
            - usr_0123abcd
        username:
          type: string
          title: Username
        staged_at:
          type: string
          format: date-time
          title: Staged At
        patch:
          additionalProperties: true
          type: object
          title: Patch
      type: object
      required:
        - user_id
        - username
        - staged_at
        - patch
      title: CvmDraftEntry
      description: 'One staged patch: who sent it, when, and what it was.'
    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
    PortPolicy:
      properties:
        ports:
          items:
            $ref: '#/components/schemas/PortAttrs'
          type: array
          title: Ports
        restrict_mode:
          type: boolean
          title: Restrict Mode
          default: false
      type: object
      title: PortPolicy
      description: |-
        Per-instance port policy declared in app-compose. >= v0.5.9.

        ``restrict_mode=True`` with an empty ``ports`` list is a valid lockdown.
        Field order is alphabetical for compose_hash stability.
    RequirementsPatch:
      properties:
        ephemeral_data_disk:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Ephemeral Data Disk
          description: >-
            Format the data disk on every boot (OS 0.6.3 or newer). Turning it
            on requires confirm_data_wipe.
        health_check:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Health Check
        health_status_file:
          anyOf:
            - type: string
            - type: 'null'
          title: Health Status File
        launch_token_hash:
          anyOf:
            - type: string
            - type: 'null'
          title: Launch Token Hash
          description: Must be the hash of the app's launch token
        platforms:
          anyOf:
            - items:
                type: string
              type: array
            - type: 'null'
          title: Platforms
        tdx_measure_acpi_tables:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Tdx Measure Acpi Tables
      additionalProperties: false
      type: object
      title: RequirementsPatch
      description: |-
        ``requirements`` keys a PATCH may set; null removes the key.

        ``gpu_policy`` is not patchable: the stored value is kept as it is.
    VerityVolume:
      properties:
        source:
          type: string
          minLength: 1
          pattern: ^[^/]+$
          title: Source
        target:
          type: string
          title: Target
        verity_root:
          type: string
          title: Verity Root
      additionalProperties: false
      type: object
      required:
        - source
        - target
        - verity_root
      title: VerityVolume
      description: |-
        Read-only dm-verity volume pre-seeded into the CVM (dstack >= 0.6.0).

        Fields are declared alphabetically to match the canonical JSON layout.
    GpuSpec:
      properties:
        slot:
          type: string
          title: Slot
        product_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Product Id
      type: object
      required:
        - slot
      title: GpuSpec
    PortAttrs:
      properties:
        port:
          type: integer
          title: Port
        pp:
          type: boolean
          title: Pp
          default: false
      type: object
      required:
        - port
      title: PortAttrs
      description: |-
        Per-port gateway attribute. Matches dstack_types::PortAttrs.

        Field order is alphabetical to match the normalized-compose JSON layout
        the gateway and KMS use for compose_hash.

````

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