@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
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
CVM Query
CVM Lifecycle
CVM Configuration
Apps
Workspace
Nodes, Instance Types & OS Images
KMS (Key Management)
SSH Keys
On-Chain Contract Actions
These functions interact directly with the blockchain, not the Phala Cloud API. They require ETH for gas (write operations) or a public client (read operations).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
Webhook Signature Verification
The SDK provides utilities for verifying webhook signatures, exported from a separate subpath to avoid bundlingnode:crypto into browser builds:
Related
- API Versioning — version management and migration
- Schema Reference — response schema details per version
- Error Handling — error classes and safe methods
- Webhooks — webhook events, signatures, and delivery
- Cloud API Reference — full REST API docs

