> ## 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.

# Head Swap LoRA API：单图换头

> 头部替换 API 用于一张目标图像和一张头部参考，保留身体姿势、照明和背景细节。

## 概览

Head Swap LoRA 是一种异步图生图模型，用于使用一个头部参考图像替换目标图像中的头部。

| 功能 | 值 |
| - | - |
| 模型 ID | `head-swap-LoRA` |
| 模式 | `image-to-image` |
| 目标图像 | `image_urls` 中必须恰好包含 1 个公开图像 URL。 |
| 头部参考 | Exactly 1 公众图像 URL 在 `head_urls` |
| 可选种子 | 非负整数 |
| 结果交付 | 异步轮询 |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/head-swap-LoRA` | 提交一个头互换任务 |
| `GET` | `/statusTask/head-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/head-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"
      ],
      "head_urls": [
        "https://example.com/head-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/head-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/head-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"
    ],
    "head_urls": [
      "https://example.com/head-reference.jpg"
    ],
    "seed": 42
  }
}
```

## 参数

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

结果交付模式：使用 `async` 并通过 `statusTask` 进行轮询

**input** `object` *required*

Head Swap LoRA 的输入参数。

**属性**

**mode** `string` *required*

生成模式。该模型仅支持`image-to-image`。

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

目标图像 URL。必须恰好包含 1 个非空且可公开访问的图像 URL。

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

头部参考图像 URL。必须恰好包含 1 个非空且可公开访问的图像 URL

**seed** `integer`

可选的随机种子。若要提高实验的可复现性，请指定一个固定的非负整数。

## 响应格式

当任务被接受时，`POST /generateTask/head-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/pricing.md#credit-conversion-and-rounding)。

Head 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 |
| `head_urls` 无效 | 准确发送 1 个公共头参考 URL |
| `seed` 无效 | 使用非负整数 |
| 任务停留在 `processing` | 继续轮询并进行退避 |
| 任务返回`failed` | 检查`failCode`和`failMsg`，然后调整输入或重试 |

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/head-swap-lora.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`, `head_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [错误码](https://apixo.ai/docs/zh/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.