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

# Image Upscaler API：將影像放大至 2K、4K 或 8K

> APIXO 影像放大 API，將單一影像增強至 2K、4K 或 8K 分辨率，並保留細節的超解析度

## 概覽

Image Upscaler 是非同步圖生圖 API，用於放大和增強一個來源影像。當您已經擁有影像 URL 並且想要更高解析度的輸出而無需編寫文字提示時，請使用它。

| 功能 | 值 |
| - | - |
| 模型 ID | `image-upscaler` |
| 模式 | 僅 `image-to-image` |
| 輸入影像 | 正是1公共影像URL |
| 提示詞 | 不支援 |
| 解析度級距 | `2k`, `4k`, `8k` |
| 輸出格式 | `jpg`, `png`, `webp` |

## 端點與身分驗證

API 基底網址：

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

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/image-upscaler` | 提交升級任務 |
| `GET` | `/statusTask/image-upscaler?taskId={taskId}` | 查詢任務狀態並取得結果 |

每個請求都必須附上 APIXO API 金鑰：

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

送出任務時，還需設定以下請求標頭：

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

## 非同步請求範例

此最小請求提交 4K JPG 升級任務並傳回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/image-upscaler" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "image-to-image",
      "image_urls": [
        "https://example.com/input.jpg"
      ],
      "resolution": "4k",
      "output_format": "jpg"
    }
  }'
```

成功回應：

```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/image-upscaler?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/upscaled-image.jpg\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任務失敗時的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "Unknown error",
    "failMsg": "Unknown error.",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

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

> [!NOTE]
>
> 解析 `resultJson` 僅在 `state` 變為 `success` 後進行。

## 請求體

### 預設 4k JPG

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "image_urls": [
      "https://example.com/input.jpg"
    ],
    "resolution": "4k",
    "output_format": "jpg"
  }
}
```

### 8k WebP

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "image_urls": [
      "https://example.com/product-shot.png"
    ],
    "resolution": "8k",
    "output_format": "webp"
  }
}
```

## 參數

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

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當 `request_type` 為 `callback` 時必填。請提供可從網際網路存取的 HTTPS 網址，以接收任務的最終結果。詳見 [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

Image Upscaler 的輸入參數。

**屬性**

**mode** `string` (default: image-to-image)

升級模式。唯一支援的值為 `image-to-image`。如果省略，則後端預設為 `image-to-image`。

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

來源影像 URL。必須恰好包含 1 非空公映像 URL，格式為 JPG、JPEG、PNG 或 WEBP。

**resolution** `string` (default: 4k)

目標解析度層。支援的值：`2k`、`4k`、`8k`。值不區分大小寫並標準化為小寫。

**output\_format** `string` (default: jpg)

輸出影像格式。支援的值：`jpg`、`png`、`webp`。`jpeg` 被接受為 `jpg` 的輸入別名。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/image-upscaler` 會傳回任務 ID：

**code** `integer`

API 狀態碼。`200` 表示任務已受理。

**message** `string`

狀態說明。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

### 狀態回應欄位

**taskId** `string`

任務的唯一識別碼。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

JSON 字串中包含放大影像的 URL，位於 `resultUrls` 欄位中，僅在 `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/image-upscaler" \
  -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-image",
      "image_urls": [
        "https://example.com/input.jpg"
      ],
      "resolution": "4k",
      "output_format": "jpg"
    }
  }'
```

成功回呼負載：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/upscaled-image.jpg\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

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)。

Image Upscaler 按提交的影像按 `$0.01 / image` 計費。價格不會因 `resolution` 或 `output_format` 而變動。

| 計費維度 | 值 |
| - | - |
| 單位 | `PER_IMAGE` |
| APIXO 價格 | `$0.01 / image` |
| 基於參數的層 | 無 |
| 受`resolution`影響 | 否 |
| 受`output_format`影響 | 否 |

最新的美元費率請見 [API 價目表](https://apixo.ai/pricing/api)。

## 耗時與輪詢

Image Upscaler 任務非同步運行。實際延遲因來源影像大小、所選目標解析度、佇列負載和結果儲存時間而異。

| 階段 | 您可能會看到的狀態 | 客戶行為 |
| - | - | - |
| 生成正在進行中 | `processing` | 繼續輪詢 |
| 完成 | `success` | 解析`resultJson` |
| 失敗 | `failed` | 讀取`failCode`和`failMsg` |

建議的輪詢模式：

| 使用案例 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - |
| 正常工作負載 | 任務建立 10 至 15 秒後 | 5s-10s |
| 8k 或高並行度工作負載 | 偏好回呼模式 | 如果輪詢，請使用 10s 或更長時間 |

> [!TIP]
>
> 對於生產佇列或大批次，使用回呼模式可避免頻繁輪詢，並更乾淨地處理較長的 8k 作業。

請求頻率與並行數上限會依帳戶、API 金鑰和路由而異。收到 `429` 時，請降低請求頻率，並逐步拉長重試間隔。帳戶層級的限制請見[系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體、模式、影像 URL 形狀、解析度或輸出格式無效 | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 金鑰或路由無權訪問該模型 | 檢查權限和路由策略 |
| `404` | 未找到任務 | 驗證 `taskId` 和模型 ID |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤或未知任務失敗 | 逐步拉長間隔後重試 |
| `502` | 服務錯誤 | 逐步拉長間隔後重試 |
| `504` | 服務超時 | 重新嘗試；耗時較長的任務可改用回呼模式 |

### 請求驗證

| 條件 | 後端行為 |
| - | - |
| 缺少 `input` | 傳回`The required parameter {{input}} is missing.` |
| `mode` 無效 | 傳回`Invalid mode type. Supported: image-to-image` |
| 缺少 `image_urls` | 傳回`The required parameter {{image_urls}} is missing.` |
| `image_urls` 不是陣列 | 傳回`The parameter {{image_urls}} must be Array type.` |
| `image_urls`長度不是1 | 傳回`The parameter {{image_urls}} must contain exactly 1 image.` |
| `image_urls[0]` 不是字串 | 傳回`The parameter {{image_urls}} Array elements must be String type.` |
| `image_urls[0]` 為空 | 傳回`The parameter {{image_urls}} cannot contain empty string.` |
| `resolution` 無效 | 傳回`The parameter {{resolution}} must be either '2k', '4k' or '8k'.` |
| `output_format` 無效 | 傳回`The parameter {{output_format}} must be either 'jpg', 'png' or 'webp'.` |

### 任務失敗代碼

| 錯誤碼 | 含義 | 處理方式 |
| - | - | - |
| `ImageFormatIncorrect` | 該服務拒絕輸入影像格式 | 使用直接公共 JPG、PNG 或 WebP 影像 URL |
| `SensitiveContent` | 輸入或產生的內容被安全檢查拒絕 | 使用不同的影像 |
| `RateLimited` | 請求頻率已達上限 | 逐步拉長間隔後重試 |
| `Timeout` | 任務逾時 | 重試或使用回呼模式 |
| `Unknown error` | 任務因不明原因失敗 | 逐步拉長間隔後重試，或聯絡支援團隊並提供 `taskId` |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/image-upscaler.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `image_urls`。請保留使用者指定的檔案順序。模型參數由 API 驗證。

## 相關連結

* [生成 API 總覽](https://apixo.ai/docs/zh-hant/models.md)
* [影像模型](https://apixo.ai/docs/zh-hant/models/image)
* [送出生成任務](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)
* [嘗試 Image Upscaler 在 APIXO Playground](https://apixo.ai/models/image-upscaler)
* [API定價](https://apixo.ai/pricing/api)


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