npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

magic-hour

v0.43.1

Published

Node SDK for Magic Hour API

Readme

Magic Hour Node SDK

NPM Version

The Magic Hour Node SDK provides convenient access to the Magic Hour API via server-side TypeScript or JavaScript.

Documentation

For full documentation of all APIs, please visit https://docs.magichour.ai

If you have any questions, please reach out to us via discord.

Install

npm install magic-hour

Usage

import Client from "magic-hour";
// generate your API Key at https://magichour.ai/developer
const client = new Client({ token: process.env["API_TOKEN"]!! });
const res = await client.v1.faceSwapPhoto.generate(
  {
    assets: {
      faceSwapMode: "all-faces",
      sourceFilePath: "/path/to/source/image.png",
      targetFilePath: "/path/to/target/image.png",
    },
    name: "Face Swap image",
  },
  {
    waitForCompletion: true,
    downloadOutputs: true,
    downloadDirectory: "outputs",
  },
);

console.log(`Project ID: ${response.id}`)
console.log(`Status: ${response.status}`)
console.log(`Downloaded files: ${response.downloaded_paths}`)

Client Functions

Most resources that generate media content support two methods:

  • generate() - A high-level convenience method that handles the entire workflow
  • create() - A low-level method that only initiates the generation process

Generate Function

The generate() function provides a complete end-to-end solution:

  • Uploads local files to Magic Hour storage
  • Calls the API to start generation
  • Automatically polls for completion
  • Downloads generated files to your local machine
  • Returns both API response data and local file paths

Additional Parameters:

  • waitForCompletion (boolean, default true): Whether to wait for the project to complete
  • downloadOutputs (boolean, default true): Whether to download the generated files
  • downloadDirectory (string, optional): Directory to save downloaded files (defaults to current directory)
const response = await client.v1.faceSwapPhoto.generate(
  {
    assets: {
      faceSwapMode: "all-faces",
      sourceFilePath: "/path/to/source/image.png",
      targetFilePath: "/path/to/target/image.png",
    },
    name: "Face Swap image",
  },
  {
    waitForCompletion: true,       // Wait for status to be complete/error/canceled
    downloadOutputs: true,         // Download files automatically
    downloadDirectory: "./outputs/" // Where to save files
  }
);

// You get both the API response AND downloaded file paths
console.log(`Project ID: ${response.id}`);
console.log(`Status: ${response.status}`);
console.log(`Downloaded files: ${response.downloadedPaths}`);

Create Function

The create() function provides granular control:

  • Only calls the API to start the generation process
  • Returns immediately with a project ID and amount of credits used
  • Requires manual status checking and file downloading
// upload the files to Magic Hour's storage or you can use direct URLs
const sourceFilePath = await client.v1.files.uploadFile("/path/to/source/image.png")
const targetFilePath = await client.v1.files.uploadFile("/path/to/target/image.png")

// Create function - only starts the process
const createResponse = await client.v1.faceSwapPhoto.create({
  assets: {
    faceSwapMode: "all-faces",
    sourceFilePath: sourceFilePath,
    targetFilePath: targetFilePath,
  },
  name: "Face Swap image"
});

// You get just the project ID and initial response
const projectId = createResponse.id;
console.log(`Started project: ${projectId}`);

// You must handle the rest:
// 1. Poll for completion using the image/video projects API
const result = await client.v1.imageProjects.checkResults(projectId, {
  waitForCompletion: true,
  downloadOutputs: false,
});

// 2. Download files using the download URLs
const downloadUrls = result.downloads;
// Download the files using your preferred method

Choosing Between Which Function to Use

Use generate() when:

  • You want a simple, one-call solution
  • You're building a straightforward application
  • You don't need custom polling or download logic

Use create() when:

  • You need custom status checking logic
  • You're integrating with existing job processing systems
  • You want to separate generation initiation from completion handling
  • You need fine-grained control over the entire workflow

Error Handling

The Magic Hour SDK includes the ApiError class, which includes the request and response data.

Basic Error Handling

try {
  await client.v1.imageToVideo.generate(
    {
      assets: {
        imageFilePath: "/Users/dhu/Desktop/test-files/suit.jpg",
      },
      endSeconds: 0,
    },
  );
} catch (error) {
  if (error instanceof ApiError) {
    console.error(`API Error: ${error.message}`); // API Error: 400 was returned from post /v1/image-to-video

    try {
      const errorData = await error.response.json();
      console.error(`Error Message: ${errorData.message}`); // Error Message: end_seconds must be at least 5
    } catch (parseError) {
      console.error("Could not parse error response");
    }
  } else {
    console.error("Unexpected error:", error);
  }
}

Logging

Logging Levels

  • none - Disable all logging
  • error - Only error messages
  • warn - Warnings and errors
  • info - Info, warnings, and errors
  • debug - All messages including request/response details

Environment Variable Configuration

You can also configure the logging level using the MAGIC_HOUR_LOG_LEVEL environment variable:

export MAGIC_HOUR_LOG_LEVEL=debug  # Enable debug logging
# or
export MAGIC_HOUR_LOG_LEVEL=error  # Only show errors

Valid values are: none, error, warn, info, debug (case insensitive). If not set, defaults to info.

Module Documentation and Snippets

v1

v1.aiClothesChanger

  • create - AI Clothes Changer
  • generate - AI Clothes Changer Generate Workflow

v1.aiFaceEditor

v1.aiGifGenerator

v1.aiHeadshotGenerator

  • create - AI Headshots
  • generate - AI Headshot Generator Generate Workflow

v1.aiImageEditor

v1.aiImageGenerator

v1.aiImageUpscaler

  • create - AI Image Upscaler
  • generate - AI Image Upscaler Generate Workflow

v1.aiMemeGenerator

  • create - AI Meme Generator
  • generate - AI Meme Generator Generate Workflow

v1.aiPhotoEditor

v1.aiQrCodeGenerator

v1.aiTalkingPhoto

  • create - AI Talking Photo
  • generate - AI Talking Photo Generate Workflow

v1.aiVoiceGenerator

  • create - AI Voice Generator
  • generate - AI Voice Generator Generate Workflow

v1.animation

v1.audioProjects

v1.autoSubtitleGenerator

  • create - Auto Subtitle Generator
  • generate - Auto Subtitle Generator Generate Workflow

v1.faceDetection

  • create - Face Detection
  • generate - Face Detection Generate Workflow
  • get - Get face detection details

v1.faceSwap

v1.faceSwapPhoto

v1.files

v1.files.uploadUrls

  • create - Generate asset upload urls

v1.imageBackgroundRemover

  • create - Image Background Remover
  • generate - Image Background Remover Generate Workflow

v1.imageProjects

v1.imageToVideo

v1.lipSync

v1.photoColorizer

v1.textToVideo

v1.videoProjects

v1.videoToVideo