> For the complete documentation index, see [llms.txt](https://docs.aimlapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aimlapi.com/api-references/video-models/pixverse/swap.md). Agents can also search and read this documentation through its [MCP server](https://docs.aimlapi.com/~gitbook/mcp).

# Pixverse Swap

## Pixverse Swap

### description: "Model id: pixverse/swap. HeyGen Avatar 6 Turbo is the lower-cost Turbo variant of HeyGen Avatar 6, with the same inputs: a photo of a person and an audio track become a talking-avatar video at up to 2K. No HeyGen account or avatar needed. Does not support tools/function calling."

## HeyGen Avatar 6 Turbo

{% columns %}
{% column width="66.66666666666666%" %}
{% hint style="info" %}
This documentation is valid for the following list of our models:

* `pixverse/swap`
  {% endhint %}
  {% endcolumn %}

{% column width="33.33333333333334%" %} <a href="https://aimlapi.com/app/pixverse/swap" class="button primary">Try in Playground</a>
{% endcolumn %}
{% endcolumns %}

### Model Overview

PixVerse Swap replaces a person, an object or the background in a video with the one from a photo, keeping the original motion and sound.

### Setup your API Key

If you don't have an API key yet, use our [Quickstart guide](https://docs.aimlapi.com/quickstart/setting-up).

### How to Make a Call

<details>

<summary>Step-by-Step Instructions</summary>

Generating a video involves sequentially calling two endpoints:

* Create and submit a video generation task. The response contains a generation ID.
* Poll the retrieval endpoint with that generation ID until the status is `completed`.

</details>

### API Schemas

#### Create a video generation task and send it to the server

## POST /v2/video/generations

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"paths":{"/v2/video/generations":{"post":{"operationId":"_v2_video_generations","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"model":{"type":"string","enum":["pixverse/swap"]},"video_url":{"type":"string","format":"uri","description":"The source video: up to 30 seconds and 100 MB, the longer side up to 1920 px, H.264 or H.265."},"image_url":{"type":"string","format":"uri","description":"Photo of the person or object that takes the place of the subject."},"resolution":{"type":"string","enum":["360p","540p","720p"],"default":"720p","description":"Output resolution. PixVerse Swap renders up to 720p."},"keyframe_time":{"type":"number","nullable":true,"minimum":0,"maximum":30,"default":0,"description":"Second of the source video whose frame is used to find the subject. Defaults to the first frame."},"target_point":{"type":"object","properties":{"x":{"type":"number","minimum":0,"maximum":1},"y":{"type":"number","minimum":0,"maximum":1}},"required":["x","y"],"description":"A point on the subject to replace, as fractions of the frame from its top-left corner. POST /v2/video/masks returns one for each person, object and the background on that frame. Without it, the largest person is replaced. A swap refused after the frame was analysed — the point lies on no subject, nobody is on the frame, moderation rejects the photo or the video, or the resolution does not suit this input — fails and is charged for the frame analysis, at the price of one POST /v2/video/masks call."},"webhook_url":{"type":"string","maxLength":2048,"format":"uri","description":"A public https address on port 443 or 8443 that gets a signed POST when the job ends. Needs a signing secret: POST /v1/webhooks/secret. On /v1/responses it needs `background: true` and does not work with `store: false`. On /v1/images/generations it runs the generation as a task on the models that support it (the others answer 400 webhook_url_not_supported): the answer is { id, status } and the result is read with GET /v1/images/generations/{id}."}},"required":["model","video_url","image_url"],"title":"pixverse/swap"}}}},"responses":{"200":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"The ID of the generated video."},"status":{"type":"string","enum":["queued","generating","completed","error"],"description":"The current status of the generation task."},"video":{"anyOf":[{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"The URL where the file can be downloaded from."}},"required":["url"]},{"type":"array","items":{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"The URL where the file can be downloaded from."}},"required":["url"]}},{"nullable":true}]},"error":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"message":{"type":"string"}},"required":["name","message"],"description":"Description of the error, if any."},"meta":{"type":"object","nullable":true,"properties":{"usage":{"type":"object","nullable":true,"properties":{"credits_used":{"type":"number","description":"The number of tokens consumed during generation."},"usd_spent":{"type":"number","description":"The total amount of money spent by the user in USD."}},"required":["credits_used","usd_spent"]}},"description":"Additional details about the generation."}},"required":["id","status"]}}},"description":"Successful response."}}}}}}
```

#### Retrieve the generated video from the server

Poll this endpoint with the `generation_id` returned by the submit request. When the status is `completed`, the response includes the generated video URL.

## GET /v2/video/generations

>

```json
{"openapi":"3.0.0","info":{"title":"AIML API","version":"1.0.0"},"servers":[{"url":"https://api.aimlapi.com"}],"security":[{"access-token":[]}],"components":{"securitySchemes":{"access-token":{"scheme":"bearer","bearerFormat":"<YOUR_AIMLAPI_KEY>","type":"http","description":"Bearer key","in":"header"}}},"paths":{"/v2/video/generations":{"get":{"operationId":"_v2_video_generations","parameters":[{"name":"generation_id","required":true,"in":"query","schema":{"type":"string"}}],"responses":{"200":{"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"The ID of the generated video."},"status":{"type":"string","enum":["queued","generating","completed","error"],"description":"The current status of the generation task."},"video":{"type":"object","nullable":true,"properties":{"url":{"type":"string","format":"uri","description":"The URL where the file can be downloaded from."}},"required":["url"]},"error":{"type":"object","nullable":true,"properties":{"name":{"type":"string"},"message":{"type":"string"}},"required":["name","message"],"description":"Description of the error, if any."},"meta":{"type":"object","nullable":true,"properties":{"usage":{"type":"object","nullable":true,"properties":{"credits_used":{"type":"number","description":"The number of tokens consumed during generation."}},"required":["credits_used"]}},"description":"Additional details about the generation."}},"required":["id","status"]}}}}}}}}}
```

### Code Example

The examples submit a generation task and poll every **15 seconds** until the final result is available. Replace `<PHOTO_URL>` and `<AUDIO_URL>` with public URLs of your photo and audio.

{% tabs %}
{% tab title="Python" %}
{% code overflow="wrap" %}

```python
import requests
import time

api_key = "<YOUR_AIMLAPI_KEY>"
url = "https://api.aimlapi.com/v2/video/generations"
headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

generation = requests.post(
    url,
    headers=headers,
    json={
        "model": "pixverse/swap",
        "image_url": "<PHOTO_URL>",
        "audio_url": "<AUDIO_URL>",
        "resolution": "1080p",
        "motion_prompt": "Friendly, nods while speaking, small hand gestures.",
    },
)
generation.raise_for_status()
generation_id = generation.json()["id"]

while True:
    result = requests.get(
        url,
        headers=headers,
        params={"generation_id": generation_id},
    )
    result.raise_for_status()
    data = result.json()
    if data.get("status") not in ("queued", "generating"):
        print(data)
        break
    time.sleep(15)
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code overflow="wrap" %}

```javascript
const apiKey = "<YOUR_AIMLAPI_KEY>";
const url = "https://api.aimlapi.com/v2/video/generations";
const headers = {
  "Authorization": `Bearer ${apiKey}`,
  "Content-Type": "application/json",
};

const generation = await fetch(url, {
  method: "POST",
  headers,
  body: JSON.stringify({
    model: "pixverse/swap",
    image_url: "<PHOTO_URL>",
    audio_url: "<AUDIO_URL>",
    resolution: "1080p",
    motion_prompt: "Friendly, nods while speaking, small hand gestures.",
  }),
});
const { id: generationId } = await generation.json();

while (true) {
  const response = await fetch(
    `${url}?generation_id=${encodeURIComponent(generationId)}`,
    { headers },
  );
  const data = await response.json();
  if (!["queued", "generating"].includes(data.status)) {
    console.log(data);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 15000));
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

<details>

<summary>Response</summary>

The shape of a finished generation; `video.url` is the MP4 to download, and `meta.usage` is what the request cost.

{% code overflow="wrap" %}

```json
{
  "id": "<generation_id>",
  "status": "completed",
  "video": {
    "url": "<video_url>"
  },
  "meta": {
    "usage": {
      "credits_used": "<credits>",
      "usd_spent": "<usd>"
    }
  },
  "model": "pixverse/swap"
}
```

{% endcode %}

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aimlapi.com/api-references/video-models/pixverse/swap.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
