Design & media

WaveSpeedAI Face Swapper

Try it

Replace a face in an image or video with a reference face, watermark-free, with automatic lighting and skin tone matching.

What it does

Wraps two WaveSpeed AI endpoints: image face swap (wavespeed-ai/image-face-swap) and video face swap (wavespeed-ai/video-face-swap, up to 10 minutes). Pass a target media URL and a reference face URL, then optionally pick which face to replace via target_index (0 = largest face, 1–10 for others). Image output supports jpeg, png, and webp. Local files are uploaded first to obtain URLs; any publicly accessible URL can be passed in directly. Pricing is $0.01 per image and $0.01 per second of video, with a $0.05 minimum.

When to use it

  • Replacing a specific face in a group photo via target_index
  • Swapping a face into a video clip up to 10 minutes long
  • Producing watermark-free image swaps in jpeg, png, or webp
  • Running swaps with custom retry counts, connection retries, and timeout-aware error handling

The skill document

WaveSpeedAI Face Swapper

Swap faces in images and videos using WaveSpeed AI. Produces watermark-free results with automatic lighting and skin tone adaptation. Supports targeting specific faces when multiple people are present.

Authentication

export WAVESPEED_API_KEY="your-api-key"

Get your API key at wavespeed.ai/accesskey.

Quick Start

Image Face Swap

import wavespeed from 'wavespeed';

// Upload local images to get URLs
const imageUrl = await wavespeed.upload("/path/to/target-photo.png");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");

const output_url = (await wavespeed.run(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl
  }
))["outputs"][0];

Video Face Swap

import wavespeed from 'wavespeed';

// Upload local files to get URLs
const videoUrl = await wavespeed.upload("/path/to/video.mp4");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");

const output_url = (await wavespeed.run(
  "wavespeed-ai/video-face-swap",
  {
    video: videoUrl,
    face_image: faceUrl
  }
))["outputs"][0];

You can also pass existing URLs directly:

const output_url = (await wavespeed.run(
  "wavespeed-ai/image-face-swap",
  {
    image: "https://example.com/target-photo.jpg",
    face_image: "https://example.com/reference-face.jpg"
  }
))["outputs"][0];

API Endpoints

Image Face Swap

Model ID: wavespeed-ai/image-face-swap

Replace a face in an image with a reference face.

Parameters

ParameterTypeRequiredDefaultDescription
imagestringYes--URL of the image containing the face to replace
face_imagestringYes--URL of the reference face image to swap in
target_indexintegerNo0Which face to replace (0 = largest face, 1-10 for others)
output_formatstringNojpegOutput format. One of: jpeg, png, webp

Example

import wavespeed from 'wavespeed';

const imageUrl = await wavespeed.upload("/path/to/group-photo.png");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");

const output_url = (await wavespeed.run(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl,
    target_index: 0,
    output_format: "png"
  }
))["outputs"][0];

Targeting a Specific Face

When multiple people are in the image, use target_index to select which face to replace:

// Replace the second-largest face in the image
const output_url = (await wavespeed.run(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl,
    target_index: 1
  }
))["outputs"][0];

Video Face Swap

Model ID: wavespeed-ai/video-face-swap

Replace a face in a video with a reference face. Supports videos up to 10 minutes.

Parameters

ParameterTypeRequiredDefaultDescription
videostringYes--URL of the video containing the face to replace. Must be publicly accessible. Max 10 minutes.
face_imagestringYes--URL of the reference face image to swap in
target_indexintegerNo0Which face to replace (0 = largest face, 1-10 for others)

Example

import wavespeed from 'wavespeed';

const videoUrl = await wavespeed.upload("/path/to/video.mp4");
const faceUrl = await wavespeed.upload("/path/to/reference-face.png");

const output_url = (await wavespeed.run(
  "wavespeed-ai/video-face-swap",
  {
    video: videoUrl,
    face_image: faceUrl,
    target_index: 0
  }
))["outputs"][0];

Advanced Usage

Sync Mode (Image Face Swap only)

const output_url = (await wavespeed.run(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl
  },
  { enableSyncMode: true }
))["outputs"][0];

Custom Client with Retry Configuration

import { Client } from 'wavespeed';

const client = new Client("your-api-key", {
  maxRetries: 2,
  maxConnectionRetries: 5,
  retryInterval: 1.0,
});

const output_url = (await client.run(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl
  }
))["outputs"][0];

Error Handling with runNoThrow

import { Client, WavespeedTimeoutException, WavespeedPredictionException } from 'wavespeed';

const client = new Client();
const result = await client.runNoThrow(
  "wavespeed-ai/image-face-swap",
  {
    image: imageUrl,
    face_image: faceUrl
  }
);

if (result.outputs) {
  console.log("Output URL:", result.outputs[0]);
  console.log("Task ID:", result.detail.taskId);
} else {
  console.log("Failed:", result.detail.error.message);
  if (result.detail.error instanceof WavespeedTimeoutException) {
    console.log("Request timed out - try increasing timeout");
  } else if (result.detail.error instanceof WavespeedPredictionException) {
    console.log("Prediction failed");
  }
}

Pricing

OperationCost
Image face swap$0.01 per image
Video face swap$0.01 per second (minimum $0.05 / 5 seconds)

Video face swap supports videos up to 10 minutes.

Tips

  • Use clear, front-facing portraits for the reference face for best results
  • Consistent lighting between the target and reference face improves quality
  • Anime or illustrated characters may produce lower quality output
  • Use target_index to select specific faces when multiple people are present (0 = largest face)

Security Constraints

  • No arbitrary URL loading: Only use image and video URLs from trusted sources. Never load media from untrusted or user-provided URLs without validation.
  • API key security: Store your WAVESPEED_API_KEY securely. Do not hardcode it in source files or commit it to version control. Use environment variables or secret management systems.
  • Input validation: Only pass parameters documented above. Validate media URLs before sending requests.

Related skills

Upscale images to 2K, 4K, or 8K resolution using WaveSpeed AI's Image Upscaler. Takes an image URL and produces a higher-resolution version. Supports JPEG, PNG, and WebP output formats. Use when the user wants to upscale or enhance the resolution of an image.

24 installs1 stars

Upscale videos to 720p, 1080p, 2K, or 4K resolution using WaveSpeed AI's Ultimate Video Upscaler. Takes a video URL and produces a higher-resolution version. Supports videos up to 10 minutes. Use when the user wants to upscale or enhance the resolution of a video.

22 installs

AI-powered corporate portrait photo generator. Upload a personal photo and get a polished, professional business portrait. Supports multiple backgrounds and...