> ## 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-hant/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` 所需。必須提供 exactly 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-hant/api-reference/webhooks.md)。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/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-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、參數、提示或影像 URL 形狀無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `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-hant/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-hant/models.md)
* [影片模型](https://apixo.ai/docs/zh-hant/models/video)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/concepts/routing-strategies.md)
* [在 APIXO Playground 試用後，可依本頁範例呼叫 Sora 2 Pro 模型。](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.