# Genjutsu 1.0 Object Swap

> 用参考图替换源视频中的物体

- 模型页: https://yir.ai/zh/models/genjutsu-1-object-swap
- 模型 ID: `higgsfield/genjutsu-1.0-object-swap`
- 计费：按实际执行渠道的上游计费收取；上游未计费的尝试不收费。

## 价格

同一输出规格下各渠道的当前公开价；官方价为参考。实际按执行渠道计费，故障转移时可能切换渠道。

| 输出规格 | 渠道 | 公开价 |
|---|---|---|
| 480p | Higgsfield (官方) | $0.154 / 秒 |
| 480p | NanoAPI | $0.117 / 秒 |
| 720p | Higgsfield (官方) | $0.3446 / 秒 |
| 720p | NanoAPI | $0.273 / 秒 |
| 1080p | Higgsfield (官方) | $0.8346 / 秒 |
| 1080p | NanoAPI | $0.78 / 秒 |

## 参数

- 操作: `generate_video`

| 参数 | 可选值 | 默认值 |
|---|---|---|
| `input` | reference | reference |
| `resolution` | 480p / 720p / 1080p | 720p |
| `aspect_ratio` | auto | auto |
| `duration` | 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 / 12 / 13 / 14 / 15 / 16 / 17 / 18 / 19 / 20 / 21 / 22 / 23 / 24 / 25 / 26 / 27 / 28 / 29 / 30 | 5 |

## 接入

两种方式任选：新项目用官方 SDK；已按 OpenAI 协议对接的项目换 Base URL 即可。

### 官方 SDK（TypeScript）

SDK 调用 Standard API（https://gateway.yir.ai），支持提交、等待和获取结果，另有 Go SDK。 https://yir.ai/zh/docs/integrations/sdk

```bash
pnpm add @yir-ai/sdk
```

```ts
import { createNodeYirClient } from "@yir-ai/sdk/server";

// Reads YIR_API_KEY from the environment by default: process.env.YIR_API_KEY
const client = createNodeYirClient();

// 1. Submit a video generation job
const job = await client.submitVideo({
  model: "higgsfield/genjutsu-1.0-object-swap",
  input: {
    type: "reference",
    prompt: "一只海龟缓缓游过珊瑚礁，镜头从侧面平稳跟随，阳光穿过清澈海水，在龟背上形成流动的光纹",
    references: [],
  },
  parameters: {
    duration: 5,
    resolution: "720p",
    aspect_ratio: "auto",
    generate_audio: false,
    n: 1,
  },
});

// 2. Wait for the job to finish and deliver its result
const result = await client.waitForJob(job.id);
console.log("Delivered files:", result.result);
if (result.result && "files" in result.result) {
  for (const file of result.result.files) {
    console.log("->", file.url);
  }
}
```

### OpenAI 兼容 API

OpenAI Images 与 Sora Videos 协议，适用于 OpenAI SDK 和 new-api 等网关；不支持对话。 https://yir.ai/zh/docs/integrations/openai-compatibility

- OpenAI SDK base_url: `https://gateway.yir.ai/openai/v1`
- new-api 渠道 Base URL（渠道类型 OpenAI）: `https://gateway.yir.ai/openai`
- 模型 ID: `higgsfield/genjutsu-1.0-object-swap`

```bash
curl https://gateway.yir.ai/openai/v1/videos \
  -H "Authorization: Bearer $YIR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "higgsfield/genjutsu-1.0-object-swap",
    "prompt": "一只海龟缓缓游过珊瑚礁，镜头从侧面平稳跟随，阳光穿过清澈海水，在龟背上形成流动的光纹",
    "resolution": "720p",
    "aspect_ratio": "auto",
    "seconds": "5"
  }'
```

## 常见问题

### Genjutsu 1.0 Object Swap 有官方 API 吗？

有。Higgsfield 通过自己的官方 API 提供 Genjutsu 1.0 Object Swap。同规格下，Yir 上第三方渠道的公开价最多比官方低 24%（见上表），用一个 Yir API Key 即可全部调用。

## 接入须知

- 使用 Authorization: Bearer $YIR_API_KEY 鉴权；Key 只放服务端环境变量，不进浏览器代码、仓库、提示词或日志。
- 任务是异步的：提交后保存 Job ID，等待终态再读取结果；处理失败与取消。
- 安全重试时复用同一个幂等键和请求，不要在结果未知时盲目重新提交。
- 结果链接是临时的，需要长期保存请自行转存。

## 链接

- [快速开始](https://yir.ai/zh/docs/getting-started/quickstart)
- [API 参考](https://yir.ai/zh/docs/reference)
- [llms.txt](https://yir.ai/llms.txt)
