SDKs

Programmatic interaction with the PichaFlow API via our SDK.

The @pichaflow/sdk provides a programmatic way to interact with the PichaFlow API.

Initialization

import { PichaFlowClient } from '@pichaflow/sdk';

const client = new PichaFlowClient({
  apiKey: 'sk_live_your_secret_key',
  baseUrl: 'https://api.pichaflow.com' // Optional
});

Built-in Auto-Optimization

By default, the @pichaflow/sdk and all framework UI plugins (@pichaflow/react, @pichaflow/vue, etc.) automatically perform Client-Side Pre-Optimization.

If a user uploads a massive 24 Megapixel master image, the SDK intercepts the file, uses the browser's native HTML5 Canvas API to strictly scale the longest edge down to 2048px (maintaining aspect ratio), and natively exports it as a highly compressed image/webp file. This happens instantly in the browser before the network request begins, ensuring blazing-fast uploads and zero API limits exceeded.

Uploading Images (Server-Side)

When operating from a trusted backend environment (e.g., Node.js, Cloudflare Workers), use your sk_live_ secret key for direct, zero-friction uploads.

const file = // ... from a file input
const response = await client.upload(file, {
  tags: ['ecommerce', 'boots'],
  onProgress: (p) => console.log(`Upload progress: ${p}%`)
});

console.log('Asset ID:', response.id);

Secure Client Uploads (HMAC Handshake)

When uploading directly from a user's browser, you must never expose your sk_live_ key. Instead, initialize the SDK with your pk_live_ public key and use the secureUpload() method.

This initiates an HMAC-SHA256 handshake. The SDK will first request a temporary, 60-second signature from your backend before transmitting the file directly to the PichaFlow Engine. This prevents malicious actors from spamming your API key and draining your wallet.

// 1. Initialize with Public Key
const client = new PichaFlowClient({
  apiKey: 'pk_live_your_public_key'
});

// 2. Use secureUpload
const file = // ... from an input
const response = await client.secureUpload(
  file, 
  {
    // Point this to your backend endpoint that signs the request
    signatureUrl: '/api/my-backend/sign-upload', 
    tags: ['ugc', 'avatar']
  }
);

Delivery URLs

Generate optimized CDN URLs on the fly.

const url = client.getDeliveryUrl('path/to/image.jpg', {
  w: 800,
  q: 80,
  f: 'webp'
});