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

# Sora 2 Pro API：OpenAI 高品质视频生成模型

> OpenAI 优质视频生成 API 用于文生视频和图生视频工作流程

## 概览

Sora 2 Pro 是 OpenAI 的高品质视频生成模型，可根据文字或图片生成视频。在 APIXO Playground 试用后，可以按本页示例调用 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `sora-2-pro` |
| 模式 | `text-to-video`, `image-to-video` |
| 提示词长度 | 1 至 5000 个字符 |
| 时长 | `4`、`8` 或 `12` 秒 |
| 文生视频的大小 | `720*1280`, `1280*720`, `1024*1792`, `1792*1024` |
| 图生视频的分辨率 | `720p`, `1080p` |
| 参考图片 | 1 个 URL 用于 `image-to-video` |
| 输出格式 | MP4 视频 URL 位于 `resultJson.resultUrls` 中 |

## 接口与身份验证

API 基础地址：

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

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/sora-2-pro` | 提交生成任务 |
| `GET` | `/statusTask/sora-2-pro?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

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

提交任务时，还需要设置以下请求头：

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

## 异步请求示例

以下示例提交一个最简单的文生视频任务，响应中会返回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/sora-2-pro" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a cinematic tracking shot of a futuristic city with flying cars",
      "duration": 4,
      "size": "1280*720"
    }
  }'
```

成功响应：

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

保存 `taskId`；您需要它来轮询最终视频

## 轮询结果

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

任务处理中的响应示例：

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

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965790929,
    "costTime": 180000
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "PromptInvalid",
    "failMsg": "Prompt is invalid or rejected",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

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

## 请求体

### 文生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-video",
    "prompt": "a cinematic tracking shot of a futuristic city with flying cars",
    "duration": 8,
    "size": "1280*720"
  }
}
```

### 图生视频

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "make this image come alive with subtle camera motion",
    "duration": 4,
    "resolution": "1080p",
    "image_urls": [
      "https://example.com/reference-image.jpg"
    ]
  }
}
```

## 参数

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

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必需。必须是能够接收最终任务负载的公共 URL。请参阅 [Webhooks](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Sora 2 Pro 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-video`、`image-to-video`。

**prompt** `string` *required*

用文字描述要生成的视频。长度须为 1 至 5000 个字符。

**duration** `integer` *required*

视频时长（以秒为单位）。支持的值：`4`、`8`、`12`。

**size** `string`

使用 `text-to-video` 时必填。可选值为 `720*1280`、`1280*720`、`1024*1792`、`1792*1024`。

**resolution** `string`

使用 `image-to-video` 时必填。可选值为 `720p`、`1080p`。

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

`image-to-video` 所需。必须提供恰好 1 个可公开访问的参考图像 URL。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/sora-2-pro` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

包含生成视频 URL 的 JSON 字符串。当 `state` 为 `success` 时返回。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理耗时，单位为毫秒。任务成功后返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/sora-2-pro" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "image-to-video",
      "prompt": "animate the scene with slow cinematic camera movement",
      "duration": 4,
      "resolution": "1080p",
      "image_urls": [
        "https://example.com/reference-image.jpg"
      ]
    }
  }'
```

Webhook 接收要求和重试规则见 [Webhook 文档](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

Sora 2 Pro 按秒计费。所选输出层级决定每秒单价，最终任务费用为：

```text theme={null}
unit price x duration
```

| 输出层 | APIXO 价格 |
| - | - |
| `720p` | `$0.30 / second` |
| `1080p` | `$0.50 / second` |

对于`text-to-video`、`720*1280`和`1280*720`使用`720p`层级，而`1024*1792`和`1792*1024`使用`1080p`层级。对于`image-to-video`，`resolution`值直接确定层级。

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

视频生成通常比图像生成耗时更长。实际延迟可能因提示复杂度、所选时长、输出层级、路由健康状况和当前队列负载而异。

| 时长 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `4`秒 | 2-5 分钟 | 任务创建 120 秒后 | 5-10s |
| `8`秒 | 2-5 分钟 | 任务创建 120 秒后 | 5-10s |
| `12`秒 | 3-6 分钟 | 任务创建 120 秒后 | 5-10s |

> [!TIP]
>
> 对于生产级工作负载，请使用回调模式以避免在长视频生成过程中频繁轮询。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、参数、提示或图像 URL 形状无效 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无法访问模型，或者内容被拒绝 | 检查权限并修改提示或输入 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 任务失败

| 问题表现 | 常见原因 | 处理方式 |
| - | - | - |
| 提示被拒 | 提示或图像内容被安全检查标记 | 修改提示或使用不同的输入图像 |
| 缺少参数 | 所选 `mode` 缺少必填字段 | 检查`duration`、`size`、`resolution`和`image_urls` |
| 图片无效 | 服务无法获取或解码图像 URL | 使用公共直接图像 URL |
| 超时或无进展 | 任务超时 | 通过退避继续轮询、稍后重试或使用回调模式 |
| 余额不足 | 该帐户没有足够的余额来支持所选的期限和级别 | 重试前需添加余额 |

### 实际检查

* `prompt` 必须是非空字符串，且不得超过 5000 个字符。
* `duration` 是必需的，并且必须是 `4`、`8` 或 `12`。
* `size` 仅需要在 `text-to-video` 模式下提供。
* `resolution` 和 `image_urls` 仅在 `image-to-video` 模式下需要。
* `image_urls` 必须恰好包含 1 个图像 URL。尽可能使用 JPG、PNG 或 WebP 格式，并确保图像大小不超过 10 MB，以减少验证失败。

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

## MCP 集成

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

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [尝试 Sora 2 Pro 在 APIXO Playground](https://apixo.ai/models/sora-2-pro)
* [API定价](https://apixo.ai/pricing/api)


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