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

# Retrieve image task

> 查询图片生成任务的状态和结果。

提交异步图片任务后，用 `task_id` 查询任务状态。新接入请优先使用 `/v1/tasks/{task_id}`。

## 请求

```bash theme={null}
curl "https://dimilinks.com/v1/tasks/img_xxx" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY"
```

## 进行中响应

```json theme={null}
{
  "id": "img_xxx",
  "task_id": "img_xxx",
  "object": "image.task",
  "status": "in_progress",
  "progress": 50,
  "created_at": 1777080000
}
```

## 成功响应

```json theme={null}
{
  "id": "img_xxx",
  "task_id": "img_xxx",
  "object": "image.task",
  "status": "succeeded",
  "progress": 100,
  "created_at": 1777080000,
  "completed_at": 1777080060,
  "result": {
    "created": 1777080000,
    "data": [
      {
        "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
        "file_id": "file_xxx"
      }
    ]
  }
}
```

## 图片地址格式

任务成功后读取 `result.data[].url`。该字段可能是相对路径、完整 HTTP(S) 链接，或 `data:image/...;base64,...` Data URL。

Data URL 不是错误，也不是日志内容；它就是图片本体。网页可直接展示，脚本保存为文件时需要先解码 base64。

## 失败响应

```json theme={null}
{
  "id": "img_xxx",
  "task_id": "img_xxx",
  "object": "image.task",
  "status": "failed",
  "progress": 100,
  "created_at": 1777080000,
  "completed_at": 1777080060,
  "error": {
    "code": "upstream_error",
    "message": "上游返回错误"
  }
}
```

## 状态

| 状态            | 含义   | 调用方建议                   |
| ------------- | ---- | ----------------------- |
| `queued`      | 等待处理 | 继续轮询。                   |
| `in_progress` | 生成中  | 继续轮询。                   |
| `succeeded`   | 已完成  | 展示 `result.data[].url`。 |
| `failed`      | 已失败  | 展示错误信息，并允许用户重试。         |

## 历史路径

`GET /v1/images/tasks/{task_id}` 保留给旧客户端。新接入不要混用两个查询结构。

历史路径响应示例：

```json theme={null}
{
  "task_id": "img_xxx",
  "status": "success",
  "conversation_id": "conv_xxx",
  "created": 1777080000,
  "finished_at": 1777080060,
  "error": "",
  "credit_cost": 123,
  "data": [
    {
      "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
      "file_id": "file_xxx"
    }
  ]
}
```


## OpenAPI

````yaml GET /tasks/{task_id}
openapi: 3.1.0
info:
  title: DimiLinks API
  description: >-
    DimiLinks unified API for chat (OpenAI-compatible and Anthropic native),
    image generation/editing, and video generation.
  version: 1.1.0
servers:
  - url: https://dimilinks.com/v1
    description: OpenAI 兼容入口：chat completions / images / videos / models / tasks
security:
  - bearerAuth: []
tags:
  - name: Models
  - name: Chat
  - name: Images
  - name: Videos
  - name: Tasks
paths:
  /tasks/{task_id}:
    get:
      tags:
        - Tasks
      summary: Retrieve task
      description: Retrieve image or video generation task by id.
      operationId: retrieveTask
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Image or video task
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ImageTask'
                  - $ref: '#/components/schemas/VideoTask'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    ImageTask:
      type: object
      properties:
        id:
          type: string
          example: img_xxx
        task_id:
          type: string
          example: img_xxx
        object:
          type: string
          example: image.task
        status:
          type: string
          enum:
            - queued
            - in_progress
            - succeeded
            - failed
        progress:
          type: integer
          minimum: 0
          maximum: 100
        created_at:
          type: integer
        completed_at:
          type: integer
        result:
          $ref: '#/components/schemas/ImageResponse'
        error:
          $ref: '#/components/schemas/ErrorObject'
    VideoTask:
      type: object
      properties:
        data:
          type: object
          properties:
            id:
              type: string
            task_id:
              type: string
            status:
              type: string
              enum:
                - queued
                - pending
                - submitted
                - processing
                - in_progress
                - running
                - completed
                - success
                - failed
                - error
                - cancelled
            progress:
              type: integer
              minimum: 0
              maximum: 100
            created_at:
              type: integer
            completed_at:
              type: integer
            error:
              $ref: '#/components/schemas/ErrorObject'
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          example: 1777080000
        task_id:
          type: string
          example: img_xxx
        data:
          type: array
          items:
            $ref: '#/components/schemas/ImageData'
    ErrorObject:
      type: object
      properties:
        message:
          type: string
        type:
          type: string
          example: invalid_request_error
        code:
          oneOf:
            - type: string
            - type: integer
    ErrorResponse:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/ErrorObject'
    ImageData:
      type: object
      properties:
        url:
          type: string
          example: /p/img/img_xxx/0?exp=1777166400000&sig=...
        file_id:
          type: string
          example: file_xxx
  responses:
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Task not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````