> ## 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 且希望获得更高分辨率输出而无需编写文本提示时，请使用该 API。

| 功能 | 值 |
| - | - |
| 模型 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/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`

包含超分后图像 URL 的 JSON 字符串，位于 `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/api-reference/webhooks.md)。

## 计费

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

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、模式、图像 URL 形状、分辨率或输出格式无效 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `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/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/models.md)
* [图像模型](https://apixo.ai/docs/zh/models/image)
* [提交生成任务](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)
* [在 APIXO Playground 尝试 Image Upscaler](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.