> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch(查询任务)

> GET /mj/task/{id}/fetch —— 轮询 Midjourney 任务状态

获取 Midjourney 任务的当前状态、进度与结果图链接。

## 请求

```bash theme={null}
curl https://openp.ai/mj/task/1737200000000000/fetch \
  -H "Authorization: Bearer $OPENPAI_API_KEY"
```

## 响应

```json theme={null}
{
  "id": "1737200000000000",
  "action": "IMAGINE",
  "status": "SUCCESS",
  "progress": "100%",
  "prompt": "A futuristic cyberpunk city at night",
  "promptEn": "A futuristic cyberpunk city at night, neon lights, --ar 16:9 --v 6",
  "description": "Submit success",
  "submitTime": 1715750400000,
  "startTime": 1715750405000,
  "finishTime": 1715750460000,
  "imageUrl": "https://...",
  "failReason": null,
  "properties": {
    "finalPrompt": "A futuristic cyberpunk city...",
    "messageId": "...",
    "discordChannelId": "..."
  },
  "buttons": [
    {"customId": "MJ::JOB::upsample::1::...", "emoji": "", "label": "U1", "style": 2, "type": 2},
    {"customId": "MJ::JOB::variation::1::...", "emoji": "", "label": "V1", "style": 2, "type": 2}
  ]
}
```

### status 取值

| 值             | 含义                   |
| ------------- | -------------------- |
| `NOT_START`   | 尚未开始                 |
| `SUBMITTED`   | 已提交,等待上游             |
| `IN_PROGRESS` | 生成中(看 `progress` 字段) |
| `SUCCESS`     | 成功                   |
| `FAILURE`     | 失败                   |

### buttons

Midjourney 任务完成后,Discord 上可点击的按钮(U1-U4、V1-V4、🔄)以 `buttons` 数组形式回传。
若需要执行某个按钮对应的操作,可用 [change](/api-reference/midjourney/change) + `customId`。

## 批量查询

```bash theme={null}
curl -X POST https://openp.ai/mj/task/list-by-condition \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "ids": ["task1", "task2", "task3"] }'
```

返回任务对象数组,可减少轮询请求次数。

## 回调 vs 轮询

* **回调(notifyHook)**:任务状态变更时 OpenPAI 主动 POST 到你的服务,生产推荐。
* **轮询(fetch)**:简单,但有延迟,适合本地脚本。

回调请求示例(POST 到 notifyHook):

```json theme={null}
{
  "id": "1737200000000000",
  "action": "IMAGINE",
  "status": "SUCCESS",
  "imageUrl": "https://...",
  "state": "<提交时传入的 state 透传>"
}
```
