Skip to main content
The @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 a safe variant that returns a SafeResult instead of throwing:
The SafeResult type:

Custom Schema Validation

Every action accepts an optional schema parameter for custom response validation. For actions without required request parameters, pass schema as the first argument:
For actions with required request parameters, pass 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 bundling node:crypto into browser builds:
See Webhooks for full payload format and delivery behavior.