{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cloro-dev/json-schema/cloro-dev-task-status-response-schema.json",
  "title": "TaskStatusResponse",
  "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/TaskStatusResponse",
  "type": "object",
  "required": [
    "task",
    "credits"
  ],
  "properties": {
    "task": {
      "$ref": "#/$defs/AsyncTaskSummary"
    },
    "credits": {
      "$ref": "#/$defs/AsyncTaskCredits"
    },
    "webhook": {
      "type": "object",
      "description": "Webhook delivery status. Present on `COMPLETED` and `FAILED` tasks created with a `webhook.url`.",
      "required": [
        "url",
        "deliveredAt",
        "delivered"
      ],
      "properties": {
        "url": {
          "type": "string",
          "format": "uri",
          "description": "The `webhook.url` you set when creating the task."
        },
        "deliveredAt": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "When your endpoint acknowledged the webhook with a `2xx`. Null until then."
        },
        "delivered": {
          "type": "boolean",
          "description": "Whether your endpoint has acknowledged the webhook with a `2xx`."
        }
      }
    },
    "response": {
      "type": "object",
      "description": "Present only when the task is `COMPLETED` or `FAILED`. For a `COMPLETED` task it is the provider's result; for a `FAILED` task it is the error, `{ \"error\": { \"code\", \"message\", \"details\" } }`, with `details` only when there is extra context."
    }
  },
  "$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."
        }
      }
    }
  }
}