JSPM

pixelapi

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q26114F
  • License MIT

Official JavaScript/TypeScript SDK for PixelAPI โ€” AI image generation, background removal, upscaling, and audio generation API

Package Exports

  • pixelapi

Readme

PixelAPI JavaScript SDK

Official JavaScript/TypeScript client for PixelAPI โ€” the cheapest AI image generation, background removal, upscaling, and audio generation API.

10 AI models, one API key, from $0.002/image.

npm TypeScript License: MIT

Installation

npm install pixelapi

Quick Start

import { PixelAPI } from "pixelapi";

const client = new PixelAPI("pk_live_your_key");

// Generate an image ($0.003)
const result = await client.image.generate({ prompt: "a cat astronaut, digital art" });
const completed = await client.generation.wait(result.id);
console.log(completed.outputUrl);

Features

๐Ÿ–ผ๏ธ Image Generation

// FLUX Schnell โ€” fast, photorealistic (~3s)
const result = await client.image.generate({
  prompt: "product on marble table, studio lighting",
  model: "flux-schnell",
});

// SDXL โ€” versatile, great for illustrations
const result = await client.image.generate({
  prompt: "watercolor painting of mountains",
  model: "sdxl",
});

const completed = await client.generation.wait(result.id);
console.log(completed.outputUrl);

โœ‚๏ธ Background Removal โ€” $0.002/image

const result = await client.image.removeBackground({
  imageUrl: "https://example.com/product.jpg",
});
const completed = await client.generation.wait(result.id);
console.log(completed.outputUrl); // Transparent PNG

๐ŸŽจ Background Replacement โ€” $0.005/image

const result = await client.image.replaceBackground({
  imageUrl: "https://example.com/product.jpg",
  prompt: "product on marble countertop, soft studio lighting",
});

๐Ÿ” 4x Upscaling โ€” $0.02/image

const result = await client.image.upscale({
  imageUrl: "https://example.com/low-res.jpg",
});

๐Ÿ‘ค Face Restoration โ€” $0.003/image

const result = await client.image.restoreFace({
  imageUrl: "https://example.com/blurry-portrait.jpg",
});

๐Ÿงน Object Removal โ€” $0.005/image

const result = await client.image.removeObject({
  imageUrl: "https://example.com/photo.jpg",
  maskUrl: "https://example.com/mask.png",
});

๐ŸŽต AI Music Generation โ€” $0.005/track

const result = await client.audio.generate({
  prompt: "upbeat electronic music for a product video",
  duration: 15,
});
const completed = await client.generation.wait(result.id);
console.log(completed.outputUrl); // Audio URL

๐Ÿ”„ Polling for Results

// One-shot check
const status = await client.generation.get("gen_abc123");
console.log(status.status); // "pending" | "processing" | "completed" | "failed"

// Wait until done (timeout in ms)
const completed = await client.generation.wait("gen_abc123", {
  timeout: 120000,
  pollInterval: 2000,
});

Error Handling

import { PixelAPI, AuthenticationError, RateLimitError, InsufficientCreditsError } from "pixelapi";

const client = new PixelAPI("pk_live_your_key");

try {
  const result = await client.image.generate({ prompt: "hello world" });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error("Invalid API key");
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited. Retry after ${error.retryAfter}s`);
  } else if (error instanceof InsufficientCreditsError) {
    console.error("Not enough credits โ€” top up at pixelapi.dev/app");
  }
}

TypeScript

Full TypeScript support with exported types:

import type { Generation, GenerateImageOptions, WaitOptions } from "pixelapi";

API Reference

Method Endpoint Credits
client.image.generate() POST /v1/image/generate 3
client.image.removeBackground() POST /v1/image/remove-background 2
client.image.upscale() POST /v1/image/upscale 20
client.image.restoreFace() POST /v1/image/restore-face 3
client.image.removeObject() POST /v1/image/remove-object 5
client.image.replaceBackground() POST /v1/image/replace-background 5
client.audio.generate() POST /v1/audio/generate 5
client.generation.get() GET /v1/image/{id} 0
client.generation.wait() Polls GET /v1/image/{id} 0

Requirements

  • Node.js 18+ (uses native fetch)
  • No external dependencies

License

MIT