Skip to main content
Every configuration update triggers a CVM restart. The CVM will be stopped, updated, and restarted automatically. Plan updates accordingly to minimize downtime.
Each updateXxxx method targets a single aspect of the CVM and calls a dedicated API endpoint. patchCvm is the unified method that can update multiple fields in a single request. Use patchCvm when you need to change several settings atomically; use the individual updateXxxx methods when you only need to change one thing.

updateCvmResources

PATCH /cvms/{cvmId}/resources Updates CVM compute resources (vCPU, memory, disk). Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
vcpunumberNoNumber of vCPUs
memorynumberNoMemory in MB
disk_sizenumberNoDisk size in GB
Returns: Updated CVM details. Example:
await client.updateCvmResources({
  id: "my-app",
  vcpu: 4,
  memory: 8192,
  disk_size: 100,
});

updateCvmVisibility

PATCH /cvms/{cvmId}/visibility Updates CVM visibility settings (public listing, public TCB info). Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
listedbooleanNoList in public directory
Returns: Updated CVM details.

updatePreLaunchScript

PATCH /cvms/{cvmId}/pre-launch-script Updates the pre-launch script for a CVM. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
pre_launch_scriptstringYesScript content
compose_hashstringNoFor on-chain KMS (Phase 2)
transaction_hashstringNoFor on-chain KMS (Phase 2)
Returns: Union type:
  • { status: "in_progress", message, correlation_id } — update accepted
  • { status: "precondition_required", message, compose_hash, app_id, device_id, kms_info } — on-chain KMS requires compose hash registration first
For CVMs using on-chain KMS, this function may return precondition_required. You must register the compose_hash on-chain using addComposeHash before retrying with the compose_hash and transaction_hash parameters.

updateOsImage

PATCH /cvms/{cvmId}/os-image Updates the OS image for a CVM. The CVM will restart with the new image. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
imagestringYesOS image name
Returns: Updated CVM details.

getAvailableOsImages

GET /os-images Returns the list of available OS images. Parameters: None (optional filters). Returns: GetAvailableOSImagesResponse — array of OS image variants with version info. Example:
const images = await client.getAvailableOsImages();
images.forEach(img => console.log(img.name, img.version));

refreshCvmInstanceId is unreleased — added after @phala/cloud v0.2.4. It will be available in a future release.

refreshCvmInstanceId

POST /cvms/{cvmId}/refresh-instance-id Generates a new instance ID for a CVM. This invalidates the old instance ID. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
Returns: InstanceIdRefreshResult with the new instance_id.
refreshCvmInstanceIds is unreleased — added after @phala/cloud v0.2.4. It will be available in a future release.

refreshCvmInstanceIds

POST /cvms/refresh-instance-ids Generates new instance IDs for multiple CVMs in a single request. Parameters:
FieldTypeRequiredDescription
idsstring[]YesArray of CVM identifiers
Returns: RefreshCvmInstanceIdsResponse — batch results.

provisionCvmComposeFileUpdate

POST /cvms/{cvmId}/compose_file/provision Provisions a compose file update — the first phase of a two-phase compose file change. Returns a compose_hash needed for the commit step. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier (also accepts uuid)
app_composeobjectYesUpdated compose file object
Returns: ProvisionCvmComposeFileUpdateResult with compose_hash. Example:
const compose = await client.getCvmComposeFile({ id: "my-app" });
compose.docker_compose_file = newYaml;

const provision = await client.provisionCvmComposeFileUpdate({
  uuid: "my-app",
  app_compose: compose,
});
console.log(provision.compose_hash);

commitCvmComposeFileUpdate

POST /cvms/{cvmId}/compose_file/commit Commits a compose file update — the second phase. For on-chain KMS, the compose_hash must be registered on-chain before calling this. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
compose_hashstringYesFrom provisionCvmComposeFileUpdate
encrypted_envstringNoHex-encoded encrypted env vars
env_keysstring[]NoAllowed env variable keys
transaction_hashstringNoOn-chain transaction hash
Returns: CommitCvmComposeFileUpdate — update details.

patchCvm

PATCH /cvms/{cvmId} Applies partial updates to a CVM via the unified PATCH endpoint. Only fields present in the request body are applied, giving you true PATCH semantics. You can update compose files, environment variables, resources, visibility, and OS images all in a single call. For CVMs with on-chain KMS (ETHEREUM/BASE), any change that affects the compose hash triggers a two-phase flow. The first call returns { requiresOnChainHash: true, composeHash, ... } with the hash you need to register on-chain. After registration, call confirmCvmPatch with the transaction proof. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
docker_compose_filestringNoNew Docker Compose YAML
pre_launch_scriptstringNoNew pre-launch script
allowed_envsstring[]NoAllowed env variable keys
public_logsbooleanNoMake logs publicly accessible
public_sysinfobooleanNoMake system info public
public_tcbinfobooleanNoMake TCB info public
encrypted_envstringNoHex-encoded encrypted env vars
user_configstringNoUser configuration string
gpusobjectNoGPU config: { count, product_name? }
vcpunumberNoNumber of vCPUs
memorynumberNoMemory in MB
disk_sizenumberNoDisk size in GB
imagestringNoOS image name
shutdown_timeoutnumberNoShutdown timeout in seconds
allow_force_stopbooleanNoAllow force stop on timeout
prepareOnlybooleanNoPrepare-only mode for multisig workflows
Returns: Discriminated union on requiresOnChainHash: Accepted (requiresOnChainHash: false):
FieldTypeDescription
requiresOnChainHashfalseUpdate accepted directly
correlationIdstringTracking ID
Hash required (requiresOnChainHash: true):
FieldTypeDescription
requiresOnChainHashtrueOn-chain registration needed
composeHashstringHash to register on-chain
appIdstringApp ID for contract interaction
deviceIdstringDevice ID
kmsInfoKmsInfoKMS details for chain interaction
commitTokenstring?One-time token for multisig commit
commitUrlstring?Commit URL
onchainStatusobject?Current on-chain allowance status
Example — simple update (PHALA KMS):
const result = await client.patchCvm({
  id: "my-app",
  vcpu: 4,
  memory: 8192,
});
console.log(result.correlationId);
Example — on-chain KMS compose update (two-phase):
import { addComposeHash } from "@phala/cloud";

const result = await client.patchCvm({
  id: "my-app",
  docker_compose_file: newComposeYaml,
});

if (result.requiresOnChainHash) {
  const tx = await addComposeHash({
    chain: result.kmsInfo.chain,
    kmsContractAddress: result.kmsInfo.kms_contract_address,
    appId: result.appId as `0x${string}`,
    composeHash: result.composeHash,
    privateKey: privateKey,
  });

  await client.confirmCvmPatch({
    id: "my-app",
    composeHash: result.composeHash,
    transactionHash: tx.transactionHash,
  });
}

confirmCvmPatch

PATCH /cvms/{cvmId} (with X-Compose-Hash and X-Transaction-Hash headers) Completes the second phase of an on-chain KMS CVM update. Call this after patchCvm returns { requiresOnChainHash: true } and you have registered the compose hash on-chain via addComposeHash. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
composeHashstringYesCompose hash from patchCvm Phase 1 response
transactionHashstringYesTransaction hash proving on-chain registration
Returns: ConfirmCvmPatchResult
FieldTypeDescription
correlationIdstringTracking ID
Example:
const confirmed = await client.confirmCvmPatch({
  id: "my-app",
  composeHash: patchResult.composeHash,
  transactionHash: txReceipt.transactionHash,
});
console.log(`Update started: ${confirmed.correlationId}`);

commitCvmUpdate

POST /cvms/{cvmId}/commit-update Completes a two-phase CVM update using a one-time commit token. This enables multisig workflows where the on-chain signer is different from the original API caller. The token is generated when you call patchCvm with prepareOnly: true. Parameters:
FieldTypeRequiredDescription
idstringYesCVM identifier
tokenstringYesOne-time commit token from prepare-only flow
composeHashstringYesCompose hash from Phase 1 response
transactionHashstringYesTransaction hash proving on-chain registration
Returns: CommitCvmUpdateResult
FieldTypeDescription
correlationIdstringTracking ID
statusstringUpdate status
Example:
// Phase 1: prepare-only
const result = await client.patchCvm({
  id: "my-app",
  docker_compose_file: newComposeYaml,
  prepareOnly: true,
});

if (result.requiresOnChainHash && result.commitToken) {
  // ... multisig approval and on-chain registration happen externally ...

  // Phase 2: commit with token
  const committed = await client.commitCvmUpdate({
    id: "my-app",
    token: result.commitToken,
    composeHash: result.composeHash,
    transactionHash: "0x...",
  });
  console.log(`Update started: ${committed.correlationId}`);
}