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

# 查询任务状态

> 轮询已提交的图片任务，并获取最终结果地址。

使用生成接口返回的 `task_id` 查询任务进度。

<Tip>
  当任务状态变成 `completed` 时，最终图片地址位于 `data.result.images[0].url[0]`。
</Tip>


## OpenAPI

````yaml GET /v1/tasks/{task_id}
openapi: 3.1.0
info:
  title: SmewAI Images API
  description: OpenAI-compatible image generation and editing endpoints for SmewAI.
  version: 1.0.0
servers:
  - url: https://smew.ai
    description: Production API
security:
  - bearerAuth: []
paths:
  /v1/tasks/{task_id}:
    get:
      tags:
        - Tasks
      summary: 查询任务状态
      description: >-
        Check task progress and fetch the final image URLs after generation
        completes.
      operationId: getTaskStatus
      parameters:
        - name: task_id
          in: path
          required: true
          description: Task ID returned by `/v1/images/generations`.
          schema:
            type: string
      responses:
        '200':
          description: Task status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TaskStatusResponse'
              examples:
                pending:
                  summary: 任务进行中
                  value:
                    code: 200
                    data:
                      id: task_xxx
                      status: pending
                      progress: 45
                completed:
                  summary: 任务已完成
                  value:
                    code: 200
                    data:
                      id: task_xxx
                      status: completed
                      progress: 100
                      result:
                        images:
                          - url:
                              - https://smew.ai/media/task_xxx/0?token=example
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Task not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    TaskStatusResponse:
      type: object
      properties:
        code:
          type: integer
          example: 200
        data:
          $ref: '#/components/schemas/TaskStatus'
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          example: error
        error:
          $ref: '#/components/schemas/ErrorDetail'
    TaskStatus:
      type: object
      properties:
        id:
          type: string
        status:
          type: string
          enum:
            - pending
            - submitted
            - processing
            - completed
            - failed
        progress:
          type: integer
          minimum: 0
          maximum: 100
        result:
          $ref: '#/components/schemas/TaskResult'
        error:
          $ref: '#/components/schemas/ErrorDetail'
    ErrorDetail:
      type: object
      properties:
        type:
          type: string
          example: invalid_request_error
        message:
          type: string
          example: Invalid request body.
    TaskResult:
      type: object
      properties:
        images:
          type: array
          items:
            $ref: '#/components/schemas/GeneratedImage'
    GeneratedImage:
      type: object
      properties:
        url:
          type: array
          items:
            type: string
            format: uri
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: Paste your SmewAI API key as a Bearer token.

````