@phala/cloud SDK provides a type-safe JavaScript/TypeScript client for the Phala Cloud API. It includes built-in API versioning, Zod schema validation, and comprehensive error handling.
Installation
Quick Start
Client Creation
createClient(config?)
Creates a full-featured client with all action methods.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | PHALA_CLOUD_API_KEY env var | API key for authentication |
baseURL | string | https://cloud-api.phala.com/api/v1 | API base URL (or PHALA_CLOUD_API_PREFIX env var) |
version | ApiVersion | "2026-01-21" | API version to use |
timeout | number | 30000 | Request timeout in milliseconds |
useCookieAuth | boolean | false | Use cookie-based auth instead of API key |
headers | Record<string, string> | — | Additional request headers |
onResponseError | function | — | Custom response error handler |
Tree-Shaking with createBaseClient
For smaller bundles, use createBaseClient with individual action imports:
Extending the Base Client
createClient already includes all built-in actions as methods. The .extend() method on createBaseClient is useful when you want to selectively include actions (for tree-shaking) or add your own custom actions:
Available Actions
Actions marked with V return different response types depending on the client’s API version.Authentication & User
| Method | Description |
|---|---|
getCurrentUser() V | Get current user, workspace, and credits info |
CVM Query
| Method | Description |
|---|---|
getCvmList(request?) V | List all CVMs (paginated) |
getCvmInfo(request) V | Get single CVM details |
getCvmStats(request) | Get CVM system stats |
getCvmNetwork(request) | Get CVM network info |
getCvmState(request) | Get CVM current state |
getCvmDockerCompose(request) | Get Docker Compose config |
getCvmComposeFile(request) | Get compose file content |
getCvmContainersStats(request) | Get container stats |
getCvmAttestation(request) | Get TEE attestation |
getCvmPreLaunchScript(request) | Get pre-launch script |
CVM Lifecycle
| Method | Description |
|---|---|
provisionCvm(request) | Create a new CVM |
commitCvmProvision(request) | Commit a CVM provision |
startCvm(request) | Start a CVM |
stopCvm(request) | Stop a CVM |
shutdownCvm(request) | Shutdown a CVM |
restartCvm(request) | Restart a CVM |
deleteCvm(request) | Delete a CVM |
CVM Configuration
| Method | Description |
|---|---|
updateCvmEnvs(request) | Update environment variables |
updateDockerCompose(request) | Update Docker Compose config |
updatePreLaunchScript(request) | Update pre-launch script |
updateCvmResources(request) | Update resource allocation |
updateCvmVisibility(request) | Update visibility settings |
updateOsImage(request) | Update OS image |
getAvailableOsImages(request?) | List available OS images |
provisionCvmComposeFileUpdate(request) | Provision a compose file update |
commitCvmComposeFileUpdate(request) | Commit a compose file update |
Apps
| Method | Description |
|---|---|
getAppList(request?) V | List apps |
getAppInfo(request) V | Get app details |
getAppCvms(request) V | List CVMs for an app |
getAppRevisions(request) | List app revision history |
getAppFilterOptions() | Get available filter options for app list |
Workspace
| Method | Description |
|---|---|
listWorkspaces(request?) | List workspaces |
getWorkspace(request) | Get workspace details |
Nodes & Instance Types
| Method | Description |
|---|---|
getAvailableNodes() | List available TEE nodes |
listAllInstanceTypeFamilies() | List all instance type families |
listFamilyInstanceTypes(request) | List instance types in a family |
KMS (Key Management)
| Method | Description |
|---|---|
getKmsInfo(request) | Get KMS info |
getKmsList(request?) | List KMS instances |
getAppEnvEncryptPubKey(request) | Get env encryption public key |
nextAppIds(request?) | Get next available app IDs |
SSH Keys
| Method | Description |
|---|---|
listSshKeys() | List SSH keys |
createSshKey(request) | Add an SSH key |
deleteSshKey(request) | Remove an SSH key |
importGithubProfileSshKeys(request) | Import SSH keys from GitHub profile |
syncGithubSshKeys() | Sync SSH keys from GitHub |
Safe Methods
Every action has asafe variant that returns a SafeResult instead of throwing:
SafeResult type:
Custom Schema Validation
Every action accepts an optionalschema parameter for custom response validation.
For actions without required request parameters, pass schema as the first argument:
schema as the second argument:
Event Handling
Listen for error events across all API calls:Debug Logging
Enable detailed cURL-format request/response logging:Environment Variables
| Variable | Description |
|---|---|
PHALA_CLOUD_API_KEY | API key for authentication |
PHALA_CLOUD_API_PREFIX | Base URL for the API |
Related
- API Versioning — version management and migration
- Schema Reference — response schema details per version
- Error Handling — error classes and safe methods
- Cloud API Reference — full REST API docs

