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

# 查询任务

> 读取任务最终结果和总扣费。

## 任务响应

status 为 processing、succeeded 或 failed。排队、fallback 和核对统一为 processing；全部执行结束后，只要至少一个成功就是 succeeded，零个成功才为 failed，不单设部分成功状态。

duration 是从创建到结束的整数毫秒。任务未结束时 completed\_at、duration、charged\_credits 为 null；失败扣 0，成功只显示最终实扣总额。

失败任务的 message 透传供应商错误；所有渠道失败时取最后一次供应商错误。成功/处理中为空字符串；查询本身成功时外层 msg 仍为 success。

```json theme={null}
{
  "code": 200,
  "msg": "success",
  "data": {
    "task_id": "task_example",
    "model": "prism-image-2",
    "status": "succeeded",
    "message": "",
    "created_at": "2026-11-01T08:30:00Z",
    "completed_at": "2026-11-01T08:31:20Z",
    "duration": 80000,
    "charged_credits": 80,
    "input": "{\"prompt\":\"A red fox in a snowy forest\",\"output_count\":3,\"fallback\":true}",
    "result": {
      "urls": [
        "https://cdn.example.com/a.png",
        "https://cdn.example.com/b.png"
      ]
    }
  }
}
```


## OpenAPI

````yaml openapi.json GET /api/v1/tasks/{task_id}
openapi: 3.1.0
info:
  title: APIstable API
  version: 1.0.0-preview
  description: >-
    Public /api/v1 protocol. Valid API keys have the same account-scoped access.
    Read the selected model documentation for its ID, supported inputs, result
    format and availability before submitting. No client submission idempotency
    or max_credits. Availability, pricing, file retention and callback formats
    follow the selected model contract. Unconfigured operations return 503.
servers:
  - url: https://apistable.ai
    description: APIstable API
security: []
paths:
  /api/v1/tasks/{task_id}:
    get:
      summary: Query task result
      description: >-
        Reads only tasks belonging to the key account. Partial success is
        succeeded. Queue/fallback/reconciliation map to processing. Only final
        total credits are exposed. Only input requires JSON.parse; result is an
        object or null. No supplier attempts or reservation fields.
      operationId: getTask
      parameters:
        - name: task_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Task query succeeded; generation can still have failed.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - msg
                  - data
                additionalProperties: false
                properties:
                  code:
                    const: 200
                  msg:
                    const: success
                  data:
                    $ref: '#/components/schemas/Task'
              example:
                code: 200
                msg: success
                data:
                  task_id: task_example
                  model: prism-image-2
                  status: succeeded
                  message: ''
                  created_at: '2026-11-01T08:30:00Z'
                  completed_at: '2026-11-01T08:31:20Z'
                  duration: 80000
                  charged_credits: 80
                  input: '{"prompt":"A red fox","output_count":3,"fallback":true}'
                  result:
                    urls:
                      - https://cdn.example.com/a.png
                      - https://cdn.example.com/b.png
        '401':
          description: Invalid or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '40402: Task not found in this account.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '50301: Service/provider unavailable. No live submission or charge.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  schemas:
    Task:
      type: object
      additionalProperties: false
      required:
        - task_id
        - model
        - status
        - created_at
        - completed_at
        - duration
        - charged_credits
        - message
        - input
        - result
      properties:
        task_id:
          type: string
        model:
          type: string
        status:
          type: string
          enum:
            - processing
            - succeeded
            - failed
        created_at:
          type: string
          format: date-time
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
        duration:
          type:
            - integer
            - 'null'
          minimum: 0
          description: Total elapsed milliseconds; null while processing.
        charged_credits:
          type:
            - number
            - 'null'
          minimum: 0
          description: Final charged Credits; null until completion.
        message:
          type: string
          description: Supplier error text for a failed task; empty on success/processing.
        input:
          type: string
          contentMediaType: application/json
          description: JSON-serialized accepted model input.
        result:
          type:
            - object
            - 'null'
          additionalProperties: true
          description: Structured model-specific result; null while processing or failed.
    Error:
      type: object
      required:
        - code
        - msg
        - data
      properties:
        code:
          type: integer
        msg:
          type: string
        data:
          type: 'null'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Every valid key can submit and query its own account. Revoked keys are
        rejected.

````

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