{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/answerline-dev/json-schema/answerline-dev-batch-task-response-schema.json",
  "title": "BatchTaskResponse",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/answerline-dev-async-api-openapi.yml#/components/schemas/BatchTaskResponse",
  "type": "object",
  "required": [
    "success",
    "summary",
    "results"
  ],
  "properties": {
    "success": {
      "type": "boolean",
      "description": "Set to true for every batch that was processed successfully; individual tasks inside it can still have failed."
    },
    "summary": {
      "type": "object",
      "required": [
        "total",
        "succeeded",
        "failed"
      ],
      "description": "Totals across the whole batch.",
      "properties": {
        "total": {
          "type": "integer",
          "description": "How many tasks the batch submission contained."
        },
        "succeeded": {
          "type": "integer",
          "description": "How many tasks were created without error."
        },
        "failed": {
          "type": "integer",
          "description": "How many tasks were not created."
        }
      }
    },
    "results": {
      "type": "array",
      "description": "Result for each task, listed by index in the same order as the input.",
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/BatchTaskSuccessResult"
          },
          {
            "$ref": "#/$defs/BatchTaskFailureResult"
          }
        ]
      }
    }
  },
  "$defs": {
    "AsyncTaskCredits": {
      "type": "object",
      "required": [
        "creditsToCharge",
        "creditsCharged"
      ],
      "description": "Charge details for one async task, in USD.",
      "properties": {
        "creditsToCharge": {
          "type": "number",
          "description": "USD amount held back from the balance for this task."
        },
        "creditsCharged": {
          "type": [
            "number",
            "null"
          ],
          "description": "USD amount charged for the task (0 when a free request covered it); null while it has not finished."
        }
      }
    },
    "AsyncTaskSummary": {
      "type": "object",
      "required": [
        "id",
        "taskType",
        "status",
        "priority",
        "createdAt"
      ],
      "description": "Summary fields that every async task response includes.",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Identifier unique to the task."
        },
        "taskType": {
          "type": "string",
          "enum": [
            "AIMODE",
            "GOOGLE",
            "GOOGLE_NEWS",
            "GEMINI",
            "CHATGPT",
            "COPILOT",
            "PERPLEXITY",
            "GROK"
          ],
          "description": "Engine that handles this task."
        },
        "status": {
          "type": "string",
          "enum": [
            "QUEUED",
            "PROCESSING",
            "COMPLETED",
            "FAILED"
          ],
          "description": "Status of the task right now."
        },
        "priority": {
          "type": "integer",
          "description": "Priority of the task, from 1 to 10; tasks with higher numbers run first. Default: 1.",
          "minimum": 1,
          "maximum": 10
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "description": "Creation time of the task."
        },
        "latencyMs": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Time spent processing, in milliseconds, measured from the first pickup until the final outcome. The initial wait in the queue is not counted, but for a retried task it spans all attempts plus the backoff in between. Null for tasks in `QUEUED` or `PROCESSING` state, and for tasks that failed before processing began."
        },
        "idempotencyKey": {
          "type": [
            "string",
            "null"
          ],
          "description": "Idempotency key supplied with the request, if any."
        }
      }
    },
    "BatchTaskFailureResult": {
      "type": "object",
      "required": [
        "success",
        "index",
        "error"
      ],
      "properties": {
        "success": {
          "type": "boolean",
          "enum": [
            false
          ],
          "description": "Signals that the task did not succeed."
        },
        "index": {
          "type": "integer",
          "description": "Index of this task within the submitted request array, starting at 0."
        },
        "error": {
          "type": "object",
          "required": [
            "code",
            "message",
            "timestamp"
          ],
          "properties": {
            "code": {
              "type": "string",
              "description": "Code naming why the request failed.",
              "enum": [
                "VALIDATION_ERROR",
                "RESOURCE_ALREADY_EXISTS",
                "INSUFFICIENT_CREDITS"
              ]
            },
            "message": {
              "type": "string",
              "description": "Error description meant for people to read."
            },
            "details": {
              "type": "object",
              "description": "Extra information about the error, for example which fields failed validation."
            },
            "timestamp": {
              "type": "string",
              "format": "date-time",
              "description": "Time at which the error happened."
            }
          }
        }
      }
    },
    "BatchTaskSuccessResult": {
      "type": "object",
      "required": [
        "success",
        "index",
        "task",
        "credits"
      ],
      "properties": {
        "success": {
          "type": "boolean",
          "enum": [
            true
          ],
          "description": "Signals that the task was created."
        },
        "index": {
          "type": "integer",
          "description": "Index of this task within the submitted request array, starting at 0."
        },
        "task": {
          "allOf": [
            {
              "$ref": "#/$defs/AsyncTaskSummary"
            },
            {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string",
                  "enum": [
                    "QUEUED"
                  ],
                  "description": "Status a task starts with when it is created."
                }
              }
            }
          ]
        },
        "credits": {
          "$ref": "#/$defs/AsyncTaskCredits"
        }
      }
    }
  }
}