{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cloro-dev/json-schema/cloro-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/cloro-dev-async-api-openapi.yml#/components/schemas/BatchTaskResponse",
  "type": "object",
  "required": [
    "success",
    "summary",
    "results"
  ],
  "properties": {
    "success": {
      "type": "boolean",
      "description": "Always true for a successfully processed batch (individual tasks may still fail)."
    },
    "summary": {
      "type": "object",
      "required": [
        "total",
        "succeeded",
        "failed"
      ],
      "description": "Aggregate counts for the batch.",
      "properties": {
        "total": {
          "type": "integer",
          "description": "Total number of tasks submitted in the batch."
        },
        "succeeded": {
          "type": "integer",
          "description": "Number of tasks successfully created."
        },
        "failed": {
          "type": "integer",
          "description": "Number of tasks that failed validation or processing."
        }
      }
    },
    "results": {
      "type": "array",
      "description": "Per-task results preserving the original input order by index.",
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/BatchTaskSuccessResult"
          },
          {
            "$ref": "#/$defs/BatchTaskFailureResult"
          }
        ]
      }
    }
  },
  "$defs": {
    "AsyncTaskCredits": {
      "type": "object",
      "required": [
        "creditsToCharge",
        "creditsCharged"
      ],
      "description": "Credit information for an async task.",
      "properties": {
        "creditsToCharge": {
          "type": "number",
          "description": "Estimated cost, computed when the task is submitted. Nothing is reserved or deducted then; credits are deducted only when the task completes."
        },
        "creditsCharged": {
          "type": [
            "number",
            "null"
          ],
          "description": "Credits actually charged: null until the task finishes, then the amount billed for `COMPLETED`, or `0` for `FAILED` (failed tasks are never charged). Equals `creditsToCharge`, except that AI Mode with `include.expandProducts` adds +1 credit per product cluster returned."
        }
      }
    },
    "AsyncTaskSummary": {
      "type": "object",
      "required": [
        "id",
        "taskType",
        "status",
        "priority",
        "createdAt"
      ],
      "description": "Common task summary fields shared across async task responses.",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "description": "Unique task identifier."
        },
        "taskType": {
          "type": "string",
          "enum": [
            "AIMODE",
            "GOOGLE",
            "GOOGLE_NEWS",
            "GEMINI",
            "CHATGPT",
            "COPILOT",
            "PERPLEXITY",
            "GROK"
          ],
          "description": "The AI provider for this task."
        },
        "status": {
          "type": "string",
          "enum": [
            "QUEUED",
            "PROCESSING",
            "COMPLETED",
            "FAILED"
          ],
          "description": "Current task status."
        },
        "priority": {
          "type": "integer",
          "description": "Task priority level (1-10). Higher numbers are processed first. Defaults to 1.",
          "minimum": 1,
          "maximum": 10
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "description": "Timestamp when the task was created."
        },
        "latencyMs": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Processing time in milliseconds, from first pickup to the final outcome. Excludes the initial queue wait, but on a retried task covers every attempt including the backoff between them. Null while the task is `QUEUED` or `PROCESSING`, and on a task that failed before processing started."
        },
        "idempotencyKey": {
          "type": [
            "string",
            "null"
          ],
          "description": "The idempotency key if one was provided."
        }
      }
    },
    "BatchTaskFailureResult": {
      "type": "object",
      "required": [
        "success",
        "index",
        "error"
      ],
      "properties": {
        "success": {
          "type": "boolean",
          "enum": [
            false
          ],
          "description": "Indicates this task failed."
        },
        "index": {
          "type": "integer",
          "description": "The zero-based position of this task in the original request array."
        },
        "error": {
          "type": "object",
          "required": [
            "code",
            "message",
            "timestamp"
          ],
          "properties": {
            "code": {
              "type": "string",
              "description": "Error code identifying the failure reason.",
              "enum": [
                "VALIDATION_ERROR",
                "RESOURCE_ALREADY_EXISTS",
                "INSUFFICIENT_CREDITS"
              ]
            },
            "message": {
              "type": "string",
              "description": "Human-readable error message."
            },
            "details": {
              "type": "object",
              "description": "Additional context about the error, such as field-level validation failures."
            },
            "timestamp": {
              "type": "string",
              "format": "date-time",
              "description": "Timestamp when the error occurred."
            }
          }
        }
      }
    },
    "BatchTaskSuccessResult": {
      "type": "object",
      "required": [
        "success",
        "index",
        "task",
        "credits"
      ],
      "properties": {
        "success": {
          "type": "boolean",
          "enum": [
            true
          ],
          "description": "Indicates this task was created successfully."
        },
        "index": {
          "type": "integer",
          "description": "The zero-based position of this task in the original request array."
        },
        "task": {
          "allOf": [
            {
              "$ref": "#/$defs/AsyncTaskSummary"
            },
            {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string",
                  "enum": [
                    "QUEUED"
                  ],
                  "description": "Initial status of a newly created task."
                }
              }
            }
          ]
        },
        "credits": {
          "$ref": "#/$defs/AsyncTaskCredits"
        }
      }
    }
  }
}