GPU API工具箱 API 文档Proxy Base URL(画布内部)图片类
FLUX.2 Klein 精准换头
FLUX.2 Klein 精准换头与 Pro 后处理 GPU API 完整调用说明
文档更新时间:2026年09月08日 12时53分18秒(UTC+8)
FLUX.2 Klein 精准换头
最后更新:2026-09-07
| 模式 | model | 输入 | 流程 |
|---|---|---|---|
| 标准 | head-swap | 图1目标底图;图2头部身份来源 | Klein 换头 → SeedVR2 |
| Pro | head-swap-pro | 图1目标底图;图2头部身份来源 | Klein 换头 → Krea2 局部融合 → SeedVR2 |
Pro 会在最终放大前修正换头后可能出现的肤色、颈部衔接和头身比例差异。两个模式都必须按目标底图、头部身份来源图的顺序重复提交 image 字段。
完整 Python 调用
保存为 call_klein_head_swap.py,安装 requests,设置 IC_SESSION 后执行。将 MODEL 改为 head-swap-pro 即启用 Pro 后处理。
import mimetypes
import os
import time
import uuid
from contextlib import ExitStack
from pathlib import Path
import requests
BASE_URL = os.environ.get("BASE_URL", "https://ic.xshow.live").rstrip("/")
MODEL = os.environ.get("MODEL", "head-swap")
session = requests.Session()
session.cookies.set("ic_session", os.environ["IC_SESSION"])
def checked(response):
if not response.ok:
raise RuntimeError(f"HTTP {response.status_code}: {response.text[:1000]}")
return response
with ExitStack() as stack:
files = []
for filename in ("target.png", "head-reference.png"):
handle = stack.enter_context(open(filename, "rb"))
files.append(("image", (Path(filename).name, handle, mimetypes.guess_type(filename)[0] or "image/png")))
created = checked(session.post(
f"{BASE_URL}/api/proxy/v1/images/edits/tasks",
headers={"X-IC-Operation-ID": str(uuid.uuid4())},
data={"model": MODEL, "prompt": "自然替换完整头部,保持目标身体、服装、姿势和背景"},
files=files,
timeout=300,
)).json()
task_id = created.get("id") or (created.get("data") or {}).get("id")
if not task_id:
raise RuntimeError(f"创建响应缺少任务 ID: {created}")
deadline = time.time() + 6 * 60 * 60
while time.time() < deadline:
state = checked(session.post(f"{BASE_URL}/api/proxy/v1/images/tasks/{task_id}", timeout=60)).json()
status = str(state.get("status") or (state.get("data") or {}).get("status") or "pending").lower()
print("status:", status)
if status == "completed":
result = checked(session.get(
f"{BASE_URL}/api/proxy/v1/images/tasks/{task_id}/content",
params={"index": 0},
timeout=600,
))
Path("head-swap-result.png").write_bytes(result.content)
break
if status in {"failed", "cancelled", "canceled", "expired"}:
raise RuntimeError(f"任务失败: {state}")
time.sleep(3)
else:
raise TimeoutError(f"任务 {task_id} 超时")错误说明
400:图片数量、顺序、格式或模型参数错误。409:任务尚未完成,或 operation ID 与另一请求冲突。502:GPU 工作流失败或结果没有通过图片解码校验。503:当前没有满足工作流显存要求的 GPU 路由。