# PPT Task API

建立 PPT 生成任務、列出主題，並輪詢共享任務 endpoints。

[非同步任務](https://openapi.felo.ai/zh-TW/docs/guides/async-tasks.md)

本頁說明既有的 `/v2` Felo APIs，使用 **Felo 帳戶權益與 Pro 點數規則**。是否扣除點數取決於 [操作](https://openapi.felo.ai/zh-TW/docs/faq/billing-and-credits.md#依-v2-能力區分的點數規則)。若要使用平台餘額呼叫，請選擇支援的 [Felo OpenAPI 端點](https://openapi.felo.ai/zh-TW/docs/api-reference/openapi/overview.md)；請求與回應格式可能不同。


已生成的簡報也可能作為相關 LiveDoc 中的 `ai_ppt` 資源出現。若要在你的應用程式中顯示投影片文字與中繼資料，請讀取資源內容並解碼其 `slides` 陣列；每張投影片的 `content` 可能又是另一個 JSON 字串。請參閱 [LiveDoc 資源內容格式](https://openapi.felo.ai/zh-TW/docs/api-reference/livedocs.md#資源內容格式)。投影片預覽連結與匯出的 PPTX 下載連結有各自不同的過期規則。

PPT Task API 提供非同步 PPT 生成能力。你可以建立任務，然後透過 `task_id` 輪詢任務狀態。你也可以瀏覽可用的 PPT 主題，並在建立任務時套用它們。

## 與 AI 代理人一起使用

若要從 Agent 建立投影片，請安裝完整的 `felo-ai` 套件，而不是固定子集合。其安裝程式會動態探索每個包含 `SKILL.md` 的套件目錄，包括 PPT Skill 與未來新增項目。請將所有探索到的 Skills 安裝到你的 Agent 原生目錄：Codex `~/.codex/skills`、Claude Code `~/.claude/skills`、OpenClaw `~/.agents/skills`，或 Hermes Agent `~/.hermes/skills`。請遵循 [手動 AI Agent 設定指南](https://openapi.felo.ai/zh-TW/docs/felo-skills.md) 進行各平台專屬的 API 金鑰設定與驗證。


## 驗證

所有請求都需要在 `Authorization` 標頭中提供 API Key：

```
Authorization: Bearer YOUR_API_KEY
```

## 1. 列出 PPT 主題

使用分頁、關鍵字搜尋、語言與類型篩選來查詢可用的 PPT 主題。

### 端點

```
GET https://openapi.felo.ai/v2/ppt-themes
```

### 查詢參數

| 參數 | 類型 | 必填 | 說明 |
|-----------|------|----------|-------------|
| `lang` | string | 否 | 本地化內容的語言代碼（例如 `en`、`zh-Hans`）。預設：`en` |
| `type` | string | 否 | 依主題類型篩選（例如 `default`、`custom`） |
| `keyword` | string | 否 | 搜尋關鍵字，會比對主題標題 |
| `page` | integer | 否 | 頁碼，從 1 開始。預設：`1` |
| `size` | integer | 否 | 每頁大小，最大 100。預設：`20` |

### 範例

```bash
curl -X GET 'https://openapi.felo.ai/v2/ppt-themes?lang=en&page=1&size=10' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### 成功回應（200）

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "total": 8,
    "page": 1,
    "size": 10,
    "items": [
      {
        "id": "43122897-0d3c-4c9e-ae19-20527ad36c04",
        "title": "Inspiration Themes",
        "subtitle": "AI-tailored visual solutions",
        "description": "Style and layout, both crafted by AI from your content in real time"
      }
    ]
  }
}
```

### 主題回應欄位

| 欄位 | 類型 | 說明 |
|-------|------|-------------|
| `total` | integer | 符合篩選條件的主題總數 |
| `page` | integer | 目前頁碼 |
| `size` | integer | 每頁大小 |
| `items` | array | 主題物件清單 |
| `items[].id` | string | 主題 ID，建立 PPT 時將此值用作 `ai_theme_id` |
| `items[].title` | string | 主題標題（已本地化） |
| `items[].subtitle` | string | 主題副標題（已本地化） |
| `items[].description` | string | 主題描述（已本地化） |

## 2. 建立 PPT 任務

### 端點

```
POST https://openapi.felo.ai/v2/ppts
```

### 請求標頭

| 標頭 | 必填 | 說明 |
|--------|----------|-------------|
| `Authorization` | 是 | 你的 API Key，格式為 `Bearer YOUR_API_KEY` |
| `Content-Type` | 是 | `application/json` 或 `multipart/form-data` |

### 請求主體

| 參數 | 類型 | 必填 | 說明 |
|-----------|------|----------|-------------|
| `query` | string | 是 | PPT 生成請求提示詞 |
| `livedoc_short_id` | string | 否 | 要與 PPT 工作階段關聯的既有 LiveDoc short ID。若省略，會自動建立新的 LiveDoc。 |
| `resource_ids` | array of strings | 否 | 要作為 PPT 生成上下文的 LiveDoc 資源 ID 清單 |
| `ppt_config` | object | 否 | PPT 設定選項 |
| `ppt_config.ai_theme_id` | string | 否 | 來自 [列出 PPT 主題](#1-列出-ppt-主題) 端點的主題 ID |

### 範例

```bash
curl -X POST 'https://openapi.felo.ai/v2/ppts' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "query": "Felo, 2 pages",
    "ppt_config": {
      "ai_theme_id": "02968979-a69f-42c4-b136-de02c40ab2d7"
    }
  }'
```

### 從上傳檔案建立

使用 `multipart/form-data` 上傳一個檔案，並在單一請求中建立 PPT 任務。平台會先將檔案上傳為 LiveDoc 資源，然後再將其資源 ID 傳遞給 PPT 任務。

| 部分 | 類型 | 必填 | 說明 |
|------|------|----------|-------------|
| `query` | string | 是 | PPT 生成請求提示詞 |
| `file` | file | 是 | 作為 PPT 上下文的來源檔案 |
| `stream_protocol` | string | 否 | 串流協定；預設為 `message_center_v1` |
| `livedoc_short_id` | string | 否 | 接收檔案的既有 LiveDoc。若省略，會建立新的 LiveDoc。 |
| `ppt_config` | JSON | 否 | 與 JSON 請求主體相同結構的 PPT 設定。請將此部分以 `application/json` 傳送。 |

```bash
curl -X POST 'https://openapi.felo.ai/v2/ppts' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F 'query=Create a 10-page presentation based on this report' \
  -F 'ppt_config={"ai_theme_id":"02968979-a69f-42c4-b136-de02c40ab2d7"};type=application/json' \
  -F 'file=@report.pdf'
```

回應會使用與 JSON 請求相同的 schema。回傳的 `livedoc_short_id` 會識別包含上傳資源的 LiveDoc。

### 成功回應（200）

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "livedoc_short_id": "PvyKouzJirXjFdst4uKRK3",
    "ppt_business_id": "BfLPuQKmChk9SPmyQawxgr",
    "task_id": "019cad6d-e874-55ef-d577-686344b5a7e9"
  }
}
```

## 3. 查詢任務狀態

### 端點

```
GET https://openapi.felo.ai/v2/tasks/{task_id}/status
```

### 範例

```bash
curl -X GET 'https://openapi.felo.ai/v2/tasks/019cad6d-e874-55ef-d577-686344b5a7e9/status' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### 成功回應（200）

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "status": "RUNNING"
  }
}
```

## 4. 查詢任務歷史資訊

### 端點

```
GET https://openapi.felo.ai/v2/tasks/{task_id}/historical
```

### 範例

```bash
curl -X GET 'https://openapi.felo.ai/v2/tasks/019cb17e-9e23-3d40-4447-48a651249460/historical' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY'
```

### RUNNING 回應

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "task_id": "019cb17e-9e23-3d40-4447-48a651249460",
    "task_status": "RUNNING",
    "ppt_biz_id": "oM8A9iJHg8dT4ZKgHThQTx",
    "ppt_url": "https://felo.ai/slides/oM8A9iJHg8dT4ZKgHThQTx"
  }
}
```

### COMPLETED 回應

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "task_id": "019cb17e-9e23-3d40-4447-48a651249460",
    "task_status": "COMPLETED",
    "ppt_biz_id": "oM8A9iJHg8dT4ZKgHThQTx",
    "ppt_url": "https://felo.ai/slides/oM8A9iJHg8dT4ZKgHThQTx",
    "live_doc_short_id": "oM8A9iJHg8dT4ZKgHThQTx",
    "live_doc_url": "https://felo.ai/livedoc/oM8A9iJHg8dT4ZKgHThQTx"
  }
}
```

### COMPLETED 回應（AI_PAGE）

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "task_id": "019d7a4d-6ab5-a96d-0f98-43ca434ab621",
    "task_status": "COMPLETED",
    "ppt_biz_id": "9qiLTmT77fA3aVurrMHvRJ",
    "ppt_url": "https://felo.ai/slides/9qiLTmT77fA3aVurrMHvRJ",
    "ai_page_html": "https://api-ext-index-file.felo.ai/html/address?message_id=9qiLTmT77fA3aVurrMHvRJ"
  }
}
```

### FAILED / PENDING / EXPIRED / CANCELED 回應

```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "task_id": "019cb17e-9e23-3d40-4447-48a651249460",
    "task_status": "FAILED",
    "ppt_biz_id": "oM8A9iJHg8dT4ZKgHThQTx",
    "ppt_url": "https://felo.ai/slides/oM8A9iJHg8dT4ZKgHThQTx",
    "error_message": "PPT generation failed",
    "live_doc_short_id": "oM8A9iJHg8dT4ZKgHThQTx",
    "live_doc_url": "https://felo.ai/livedoc/oM8A9iJHg8dT4ZKgHThQTx"
  }
}
```

### 歷史回應欄位

| 欄位 | 類型 | 說明 |
|------|------|-------------|
| `task_id` | string | 任務 ID |
| `task_status` | string | 目前任務狀態 |
| `ppt_biz_id` | string | PPT business ID（由後端 `thread_short_id` 對應而來） |
| `ppt_url` | string | PPT URL，格式：`https://felo.ai/slides/{ppt_biz_id}` |
| `error_message` | string | 當狀態為 `FAILED` / `PENDING` / `EXPIRED` / `CANCELED` 時存在；若下游未提供錯誤詳細資訊，則為空字串 `""` |
| `ai_page_html` | string | 當任務以 AI_PAGE 模式執行，且下游歷史資訊回傳 HTML 結果 URL 時存在 |
| `live_doc_short_id` | string | LiveDoc short ID。對於 `COMPLETED`，它來自下游 `live_doc_short_id`；對於終端失敗狀態，若可用則會回傳 |
| `live_doc_url` | string | 與 `live_doc_short_id` 對應的 LiveDoc URL |

## 匯出 PPTX

當 PPT 生成任務達到 `COMPLETED` 後，請使用建立回應中的 `ppt_business_id`（或歷史回應中的 `ppt_biz_id`）提交非同步匯出：

```bash
curl -X POST 'https://openapi.felo.ai/v2/ppts/YOUR_PPT_BUSINESS_ID/export' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

每 2–5 秒使用相同的 Bearer API Key 輪詢 `GET https://openapi.felo.ai/v2/ppts/{ppt_business_id}/export`。API Key 擁有者必須擁有該 PPT。兩個端點都會回傳 `data.status`：`NOT_STARTED`、`PROCESSING`、`COMPLETED` 或 `FAILED`。只有 `COMPLETED` 會包含 `download_url` 與 `expires_at`。

簽署後的下載 URL 會在**發出後 30 分鐘**過期。再次呼叫 GET 端點可取得新的 URL；這不會重新生成 PPTX。POST 使用 `application/json` 並接受 `{}`。當匯出正在處理時重複送出 POST 不會啟動另一個作業；在完成後再次呼叫則會重新生成 PPTX，並為新的匯出請求 10 個 Felo 點數。點數不足會回傳 HTTP 402。端點層級可能有速率限制；若遇到 HTTP 429，請稍後重試。失敗的匯出可以重新提交。


```json
{
  "status": 200,
  "code": "OK",
  "request_id": "req_example",
  "message": null,
  "data": {
    "status": "COMPLETED",
    "download_url": "https://example.com/presentation.pptx?signature=...",
    "expires_at": "2026-09-29T10:30:00Z"
  }
}
```

## 輪詢建議

請使用建立回應中的 `task_id`，每 2-5 秒輪詢一次狀態，直到狀態變為終端狀態。

常見狀態範例：

- `RUNNING`：任務仍在處理中
- `COMPLETED`：任務已成功完成
- `FAILED` / `PENDING` / `EXPIRED` / `CANCELED`：任務已達終端狀態並附帶 `error_message`；若可用，也會回傳 `live_doc_url`

隨著後端演進，可能會出現未知的狀態值；除非另有文件說明，請將它們視為非終端狀態。

## 錯誤代碼

| 代碼 | HTTP 狀態 | 說明 |
|------|-------------|-------------|
| `INVALID_API_KEY` | 401 | API Key 無效或已撤銷 |
| `PPT_TASK_CREATE_FAILED` | 502 | 建立任務的下游呼叫失敗 |
| `PPT_TASK_QUERY_FAILED` | 502 | 查詢任務狀態的下游呼叫失敗 |
