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

# Prompt Optimizer AI 指南：保留用户意图和指定原文

> 准备 Prompt Optimizer 请求时，需提供精确文本提取、忠实的创意简报、有序的参考资料以及完整的 AI 调用示例。

使用与普通调用者相同的[Prompt Optimizer端点](https://apixo.ai/docs/zh/models/text/prompt-optimizer.md)。使用 `request_type` 选择轮询、回调传递或同步等待。 `protected_text` 和 `creative_brief` 是 AI 助手、MCP 客户端和调用插件的可选输入。它们不需要单独的身份或端点。普通用户可以在`prompt`和`reference_notes`中表达自己的需求。

## 准备请求

对于标签必须为 `SPRING TEA` 的产品图像，请在原始提示中包含标签文字，并在 `protected_text` 中保留该精确字符串。产品图片置于首位，背景参考置于其后。使用 `reference_notes` 指明哪个图像提供标签，哪个图像仅提供场景背景。[完整的编辑请求](#ai-assisted-editing-with-exact-text)展示了这些字段如何协同使用。在将返回的提示传递给图像模型前，需检查其拼写正确性。

1. 在 `prompt` 中保留用户的完整请求，包括约束、例外、数量和允许的编辑。禁止通过将需求移入高级字段来压缩请求内容。
2. 选择所需的`target_model`和`generation_mode`。接受未知的目标名称；为未知视频目标明确选择视频模式。优化返回文本，且不会启动媒体生成。
3. 仅通过有序 `image_urls`（最多 4 个公开 HTTPS URL）附加参考素材。使用从 1 开始的图像编号。仅在 `reference_notes` 中描述已知的参考用途；不得猜测图像内容或更改其权限。
4. 仅在适当时将用户所需的准确措辞提取到 `protected_text` 中。
5. 可选择在 `creative_brief` 中组织已规定的创意要求。缺失信息保持为空。
6. 提交一次。直接读取最终结果，轮询返回的任务 ID 或等待回调。在解析 `data.resultJson` 之前先读取 `data.state`。在单独请求媒体生成前需检查输出。

## 带有 protected\_text 的精确文本

使用此可选数组表示对话、歌词、可见字母、标签、标题或其他用户需要逐字还原的措辞。每个字符串最多 32 个，必须非空，长度不超过 1000 个字符，并且必须恰好出现在 `prompt` 中。

* 复制实际的子字符串及其原始大小写、间距、标点符号和语言。不要翻译或解释它。
* 不要发明缺失的名称或标签、锁定普通描述或保护整个提示以避免做出决定。
* 如果不存在精确文本要求，则省略该字段。提取后将完整的原始需求保留在`prompt`中。
* 对于`Keep the cup label SPRING TEA unchanged`，保护项目是`SPRING TEA`。

保留准确的措辞并不能保证整个输出在语义上是正确的；还要检查所有限制。

## creative\_brief 的现有要求

此可选对象仅接受以下字符串字段，每个字段最多 1000 个字符：

| 字段 | 提取什么 |
| - | - |
| `scene` | 规定的设置和环境。 |
| `camera` | 规定的取景、视点或摄像机移动。 |
| `style` | 规定的视觉风格。 |
| `action_details` | 规定的行动、顺序和资格细节。 |
| `audio` | 规定的声音或对话要求。 |

不要添加设置、镜头、风格、动作、声音或情节事件来填充未使用的字段。保持这些字段与`prompt`和`reference_notes`一致。不要把局部或有条件的限制变成全球性的：不对话并不意味着沉默；没有背景音乐不会消除环境声音；没有附加文本不会删除现有标签。

`creative_brief.style` 是受支持的子字段。普通风格、相机和拍摄要求属于`prompt`。

## 图像顺序和语言

图像1是`image-to-image`中的编辑基；后面的图片仅供参考。`image-to-video` 有一个起始帧。`first-and-last-frames` 需要恰好两个按开始/结束顺序排列的图像和显式模式。单独的两个图像意味着参考生成，而不是端点。Notes 不能逆转这些责任。重新排序图像需要在整个请求中更新图像编号。

解释每个参考素材的贡献，什么必须保持不变，什么不能复制。如果未提供图像，则仅附注不附加图像。未知的参考用途应保持未指定。

使用 `language` 明确指定所需的描述性输出语言。保留提供的对话、歌词、文字标注、坐标标签和数值约束。请参阅主要指南 [图像语言策略](https://apixo.ai/docs/zh/models/text/prompt-optimizer.md#image-language-selection-and-preservation) 和 [视频语言策略](https://apixo.ai/docs/zh/models/text/prompt-optimizer.md#video-language-selection-and-preservation) 中关于 `auto` 的说明。返回的提示是一个字符串；部分目标会使用其中的命名段落。

## 规划视频镜头

将用户的镜头数量、顺序和剪辑时间保留在 `prompt` 中。例如“连续一镜不切”的指令也应包含在内。如果用户委托制定镜头计划，则保留镜头数量和剪辑时间的设定。对于 Wan 3.0 LoRA，将 `target_model` 设置为 `wan-3-0-video-LoRA`。

## 完整的请求示例

将每个请求提交至 `POST https://api.apixo.ai/api/v1/generateTask/prompt-optimizer`，并附带 `Authorization: Bearer YOUR_API_KEY` 和 `Content-Type: application/json`。将占位符 URL 替换为可访问的文件和您自己的回调接收器。

### 最小图像提示

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "optimizer",
    "prompt": "A ceramic cup on a wooden table in soft window light."
  }
}
```

### AI辅助编辑，精确文本

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "optimizer",
    "prompt": "Use image 1 as the editing base. Replace only the background with the wooden table environment in image 2. Keep the cup shape, color and label SPRING TEA unchanged. Use natural photography, a fixed camera and a medium shot. Do not add people or text.",
    "target_model": "generic-image",
    "generation_mode": "image-to-image",
    "language": "en",
    "image_urls": [
      "https://images.example.com/cup.png",
      "https://images.example.com/table.png"
    ],
    "reference_notes": "Image 1 is the editing base; preserve the cup and its label. Image 2 supplies only the table background; do not copy its people or lettering.",
    "protected_text": [
      "SPRING TEA"
    ],
    "creative_brief": {
      "camera": "Fixed camera, medium shot",
      "style": "Natural photography"
    }
  }
}
```

### 带有范围音频说明的视频参考

```json theme={null}
{
  "request_type": "callback",
  "callback_url": "https://your-server.example.com/optimization-result",
  "input": {
    "mode": "optimizer",
    "prompt": "Use the cup in image 1 as the product reference. Show the cup on a wooden table for 6 seconds with one continuous fixed-camera shot. Keep the label SPRING TEA unchanged. No dialogue or background music; retain the ambient rain sound.",
    "target_model": "generic-video",
    "generation_mode": "reference-to-video",
    "language": "en",
    "duration": 6,
    "image_urls": [
      "https://images.example.com/cup.png"
    ],
    "reference_notes": "Image 1 supplies only the cup appearance and label; it is not a required starting frame.",
    "protected_text": [
      "SPRING TEA"
    ],
    "creative_brief": {
      "scene": "Cup on a wooden table",
      "camera": "One continuous fixed-camera shot",
      "audio": "No dialogue or background music; retain ambient rain sound"
    }
  }
}
```

### 显式的第一帧和最后一帧

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "optimizer",
    "prompt": "Start at image 1 and end at image 2. Show the door opening slowly while keeping the camera fixed.",
    "target_model": "generic-video",
    "generation_mode": "first-and-last-frames",
    "image_urls": [
      "https://images.example.com/door-closed.png",
      "https://images.example.com/door-open.png"
    ],
    "reference_notes": "Image 1 is the starting frame; image 2 is the ending frame."
  }
}
```

### 两次拍摄的同步 Wan LoRA

```json theme={null}
{
  "request_type": "sync",
  "input": {
    "mode": "optimizer",
    "prompt": "Use image 1 as the starting frame. Exactly two shots over 8 seconds: from 0 to 3 seconds, hold a fixed medium shot as the blue toy train rolls to the center. At 3 seconds, hard cut to an overhead close-up and keep the train still through 8 seconds. No subtitles or music.",
    "target_model": "wan-3-0-video-LoRA",
    "generation_mode": "image-to-video",
    "language": "en",
    "duration": 8,
    "image_urls": [
      "https://images.example.com/toy-train.png"
    ]
  }
}
```

如果任务在同步等待期间完成，响应将包含优化的提示。解析 `data.resultJson` 一次，并读取 `outputs[0]`。

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_video_example",
    "state": "success",
    "resultJson": "{\"outputs\":[\"8 seconds. Shot 1 (0–3s): Fixed medium shot from the supplied first frame. The blue toy train rolls to the center. Shot 2 (3–8s): Hard cut to an overhead close-up of the stationary train. No subtitles or music.\"]}"
  }
}
```

如果服务器停止等待时任务仍在运行，则使用返回的 `data.taskId` 查询该任务。将仅包含任务 ID 的响应视为接受，并查询该任务。

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

```bash theme={null}
curl 'https://api.apixo.ai/api/v1/statusTask/prompt-optimizer?taskId=task_video_example' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

## 读取结果

提交后保存 `data.taskId`。如果同步响应已包含 `data.state: "success"`，则直接读取结果；否则，使用同一账户的 API 密钥调用 `GET /api/v1/statusTask/prompt-optimizer?taskId={taskId}`，或根据需求等待回调。处理过程中不得重新提交。成功后，解析 `data.resultJson` 一次并读取 `outputs[0]`；若失败，则读取 `failCode` 和 `failMsg`；外层 `code=200` 不代表优化成功。

约 5 秒后轮询，间隔至少 5 秒。超时不能证明任务未被创建。提交替换任务前，请先检查是否存在已有任务。媒体生成仍为独立操作。


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