> ## Documentation Index
> Fetch the complete documentation index at: https://apixo.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Face Swap LoRA API：使用目標圖和人臉參考圖換臉

> 一張目標影像和一張臉部參考的臉部替換 API，並保留姿勢和光照以獲得自然的合成結果。

## 概覽

Face Swap LoRA 是一種異步圖生圖模型，用於使用一張人臉參考影像取代目標影像中的人臉。

| 功能 | 值 |
| - | - |
| 模型 ID | `face-swap-LoRA` |
| 模式 | `image-to-image` |
| 目標影像 | `image_urls` 中必須且僅有 1 個公開的影像 URL |
| 人臉參考 | 確切地 1 公眾形象 URL 在 `face_urls` |
| 可選種子 | 非負整數 |
| 結果交付 | 非同步輪詢 |

## 端點與身分驗證

API 基底網址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/face-swap-LoRA` | 提交換臉任務 |
| `GET` | `/statusTask/face-swap-LoRA?taskId={taskId}` | 查詢任務狀態並取得結果 |

每個請求都必須附上 APIXO API 金鑰：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

送出任務時，還需設定以下請求標頭：

```http theme={null}
Content-Type: application/json
```

## 非同步請求範例

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/face-swap-LoRA" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "image-to-image",
      "image_urls": [
        "https://example.com/target-image.png"
      ],
      "face_urls": [
        "https://example.com/face-reference.png"
      ],
      "seed": 12345
    }
  }'
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

## 輪詢結果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/face-swap-LoRA?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/face-swap-result.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const imageUrls = payload.resultUrls;
```

## 請求體

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "image_urls": [
      "https://example.com/target-image.jpg"
    ],
    "face_urls": [
      "https://example.com/face-reference.jpg"
    ],
    "seed": 42
  }
}
```

## 參數

**request\_type** `string` *required* (default: async)

結果交付方式。使用 `async` 並使用 `statusTask` 進行輪詢。

**input** `object` *required*

Face Swap LoRA 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式。此模型僅支援 `image-to-image`。

**image\_urls** `string[]` *required*

目標影像 URL。必須恰好包含 1 非空且可公開存取的影像 URL。

**face\_urls** `string[]` *required*

人臉參考影像 URL。必須恰好包含 1 非空且可公開存取的影像 URL。

**seed** `integer`

選填的隨機種子。若要讓實驗結果更容易重現，請指定固定的非負整數。

## 回應格式

當任務被接受時，`POST /generateTask/face-swap-LoRA` 會傳回任務 ID。輪詢狀態端點，直到 `state` 為 `success` 或 `failed`。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

JSON 字串，包含 `resultUrls` 中的輸出影像 URL。當 `state` 為 `success` 時會出現。

**failCode** `string`

供程式判讀的錯誤碼，僅在 `state` 為 `failed` 時傳回。

**failMsg** `string`

失敗原因說明，僅在 `state` 為 `failed` 時傳回。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/pricing.md#credit-conversion-and-rounding)。

Face Swap LoRA 依產生的影像數量計費。

| 單位 | APIXO 價格 |
| - | - |
| 一張輸出影像 | `$0.016 / image` |

有關當前公開價格，請參閱 [API 定價](https://apixo.ai/pricing/api)。

## 耗時與輪詢

| 使用案例 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - |
| 標準換臉 | 任務建立 10 秒後 | 5s-10s |

## 錯誤與排查

| 條件 | 處理方式 |
| - | - |
| 無效或缺失 `mode` | 將 `input.mode` 設定為 `image-to-image` |
| `image_urls` 無效 | 準確發送 1 公共目標影像 URL |
| `face_urls` 無效 | 準確發送 1 公眾面孔參考 URL |
| `seed` 無效 | 使用非負整數 |
| 任務停留在 `processing` | 繼續輪詢並進行退避 |
| 任務傳回`failed` | 檢查`failCode`和`failMsg`，然後調整輸入或重試 |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/face-swap-lora.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `image_urls`, `face_urls`。請保留使用者指定的檔案順序。模型參數由 API 驗證。

## 相關連結

* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [API定價](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.