Skip to main content

Install the package

npm install @pi-api/sdk
@pi-api/sdk requires Node.js 18 or later. It uses the native fetch API available in Node 18+. No polyfills are required. If you need to run on an earlier Node version, pass a compatible fetch implementation via the fetchImpl option when creating the client.

Set environment variables

Store your credentials as environment variables. Never hard-code them in source files.
.env
PI_API_KEY=pi_live_...
PI_BASE_URL=https://api.example.com
Keep your API key server-side only. Do not expose PI_API_KEY in browser bundles, client-side code, or public repositories. Treat it like a password.

Initialize the client

1

Import createPiClient

Import the factory function from the package.
import { createPiClient } from '@pi-api/sdk';
2

Create the client

Pass your API key and base URL. Optionally provide BYOK provider keys for Gemini, Firecrawl, and LiveKit.
const pi = createPiClient({
  // Required
  apiKey: process.env.PI_API_KEY!,
  baseUrl: process.env.PI_BASE_URL ?? 'https://api.example.com',

  // Optional: BYOK third-party provider credentials
  providerKeys: {
    gemini: process.env.GEMINI_API_KEY,
    firecrawl: process.env.FIRECRAWL_API_KEY,
    livekit: process.env.LIVEKIT_API_KEY
      ? {
          apiKey: process.env.LIVEKIT_API_KEY,
          apiSecret: process.env.LIVEKIT_API_SECRET!,
        }
      : undefined,
  },

  // Optional: override the fetch implementation
  fetchImpl: globalThis.fetch,
});
3

Call any namespace

The client is ready. Call any namespace method directly.
const queued = await pi.brands.extract({ url: 'https://example.com' });
const job = await pi.jobs.waitForCompletion(queued.data.job_id);
console.log(job);

TypeScript types

@pi-api/sdk ships with full TypeScript definitions. The following types are exported directly from the package root and cover all request inputs and response shapes:
import type {
  CreatePiClientOptions,
  ProviderKeys,
  // Contract types (inputs and responses for every namespace)
  // Brand
  // ImageConfig
  // Run, Avatar, Ads, Campaign, Voice, Webhooks,
  // Surveillance, Robotics, Health, Neuro …
} from '@pi-api/sdk';
All request and response contract types are re-exported from the package entry point. Import them by name — your IDE will autocomplete the available exports.
You do not need to install Zod separately. The SDK validates all inputs internally before sending requests. If a required field is missing or a value has the wrong type, you receive a descriptive Zod validation error before any network call is made.