{
  "openapi": "3.0.3",
  "info": {
    "title": "Priostack API",
    "version": "1.0.0",
    "description": "REST reference for the routes a developer calls with a Priostack API key: the workflow engine (BPMN deploy, instances, jobs, incidents), DMN decisions and CMMN cases, the task list, the worker registry, webhooks, dead letters, platform apps and the account and credit routes.\n\n**One origin, no aliases.** Every route lives on https://priostack.com. Engine routes are under /api/v1/, account and billing routes under /api/ with no version. No other host name serves the API, and /v1/..., /api/v1/deployments, /api/v1/definitions, /api/v1/instances, /api/v1/messages, /api/v1/case-instances and /graphql are not routes.\n\n**Authentication.** Send the API key as `X-API-Key: <key>`, as `Authorization: Bearer <key>` (a signed-in session token is accepted there too) or as `?api_key=<key>`. Exceptions are stated on the operations: /api/v1/webhooks accepts only the X-API-Key header, /api/v1/tasks accepts X-API-Key or ?api_key but not Bearer. Treat the key as an opaque string: a key issued at signup or by rotation is `ps_` followed by 64 hex characters, an account the site made on first use of the wallet, billing or the dashboard (for someone who signed in without a developer account, with Google for example) has `ps_` followed by 32, and a key reissued by support is `prio_` followed by 48.\n\n**Keys and identifiers are opaque strings.** Job keys are 20 lowercase hex characters, process instance and case keys are currently `run_` followed by 20 hex characters, definition and model keys are 20 hex characters. None of them is ever a JSON number.\n\n**Errors** are `application/json` bodies of the form `{\"error\": \"<message>\"}` with no machine code. The 402 on instance start adds `balance` and `buy`. The firewall's 429 is `text/plain` \"Too Many Requests\" (300 requests per 60 s per client IP), and an IP banned after 3 strikes gets 403 with an empty body. Every response carries X-Request-ID.\n\n**Credits.** In the default mode, starting a process instance, starting a case, evaluating a decision, deploying through /api/v1/models, completing a task through /api/v1/tasks/{id}/complete and an agent query each cost 1 credit, returned with 402 when the balance is too low. Deploying BPMN through /api/v1/process-definitions, job activation, completion and failure, and every read are free.\n\n**Not in this reference.** The agent network at /mcp (JSON-RPC, agent tokens), the mailbox (/api/acn/mailbox, agent bearer token), dashboard routes (/api/dashboard/*, /api/acn/me/*, signed-in session), signup, /api/token, /api/keys and operator routes. Other API-key routes (/api/v1/notifications, /api/v1/iot, /api/v1/butterfly, /api/v1/workspaces, /api/workspaces, /api/connectors, /api/v1/marketplace, /api/bizapps, /api/simulate) are not documented here yet.",
    "contact": {
      "email": "support@priostack.com",
      "url": "https://priostack.com/docs"
    },
    "license": {
      "name": "Commercial",
      "url": "https://priostack.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://priostack.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKeyHeader": []
    },
    {
      "bearerAuth": []
    },
    {
      "apiKeyQuery": []
    }
  ],
  "tags": [
    {
      "name": "System",
      "description": "Health and topology"
    },
    {
      "name": "Process definitions",
      "description": "Deploy and read BPMN process definitions"
    },
    {
      "name": "Process instances",
      "description": "Start, read, update and cancel process instances"
    },
    {
      "name": "Job workers",
      "description": "Activate, complete and fail service task jobs"
    },
    {
      "name": "Incidents",
      "description": "Incident records raised when a job runs out of retries"
    },
    {
      "name": "Models, decisions and cases",
      "description": "Deploy any model kind, evaluate DMN decisions, run CMMN cases"
    },
    {
      "name": "AI agent",
      "description": "The per-account reasoning agent"
    },
    {
      "name": "Task list",
      "description": "Human tasks over GraphQL and REST"
    },
    {
      "name": "Worker registry",
      "description": "Optional, informational worker registration"
    },
    {
      "name": "Webhooks",
      "description": "Event subscriptions, test deliveries and delivery logs"
    },
    {
      "name": "Dead letters",
      "description": "Webhook deliveries that failed every attempt"
    },
    {
      "name": "Account and credits",
      "description": "Account details, credit balance, ledger and packs"
    },
    {
      "name": "Platform apps",
      "description": "Register and manage platform apps"
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "The account API key, an opaque string: ps_ followed by 64 hex characters (signup, rotation) or 32 (an account the site made on first use of the wallet, billing or the dashboard), or prio_ followed by 48 (reissued by support)."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The API key, or a signed-in session token, as Authorization: Bearer <value>."
      },
      "apiKeyQuery": {
        "type": "apiKey",
        "in": "query",
        "name": "api_key",
        "description": "The API key as a query parameter. URLs end up in logs, so prefer the header."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable message. There is no machine error code."
          }
        }
      },
      "InstanceStartCreditsError": {
        "type": "object",
        "required": [
          "error",
          "balance",
          "buy"
        ],
        "description": "Body of the 402 on POST /api/v1/process-instances. Every other charged route answers {\"error\":\"insufficient credits\"}.",
        "properties": {
          "error": {
            "type": "string",
            "description": "insufficient credits: have <n>, need 1, or account is disabled, or unknown api key."
          },
          "balance": {
            "type": "integer",
            "description": "Currently always 0, whatever the real balance."
          },
          "buy": {
            "type": "string",
            "description": "Currently https://priostack.com/credits. Buy packs at https://priostack.com/wallet."
          }
        }
      },
      "CreditPack": {
        "type": "object",
        "required": [
          "id",
          "credits",
          "price_cents"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "small",
              "medium",
              "large"
            ]
          },
          "credits": {
            "type": "integer"
          },
          "price_cents": {
            "type": "integer",
            "description": "Price in euro cents (500 = EUR 5)."
          }
        },
        "example": {
          "id": "small",
          "credits": 5556,
          "price_cents": 500
        }
      },
      "LedgerEntry": {
        "type": "object",
        "properties": {
          "at": {
            "type": "string",
            "format": "date-time"
          },
          "delta": {
            "type": "integer",
            "description": "Positive for a grant or top-up, negative for a spend."
          },
          "description": {
            "type": "string",
            "example": "workflow instance started"
          },
          "instance_key": {
            "type": "string"
          },
          "task_key": {
            "type": "string"
          },
          "feature": {
            "type": "string"
          }
        }
      },
      "Deployment": {
        "type": "object",
        "properties": {
          "processDefinitionKey": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02"
          },
          "bpmnProcessId": {
            "type": "string",
            "example": "order-process"
          },
          "id": {
            "type": "string",
            "description": "Same as bpmnProcessId.",
            "example": "order-process"
          },
          "version": {
            "type": "integer",
            "example": 1
          },
          "resourceName": {
            "type": "string",
            "example": "order-process.bpmn"
          },
          "tenantId": {
            "type": "string",
            "description": "Masked API key.",
            "example": "ps_1a2b3...9f0e"
          }
        }
      },
      "DeployResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "nullable": true,
            "description": "bpmnProcessId of the first deployed resource, null when none was deployed."
          },
          "deployments": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/Deployment"
            }
          },
          "key": {
            "type": "integer",
            "format": "int64",
            "description": "Server time in Unix milliseconds. Not an identifier."
          },
          "tenantId": {
            "type": "string",
            "example": "<default>"
          }
        }
      },
      "DefinitionSummary": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02"
          },
          "bpmnProcessId": {
            "type": "string",
            "example": "order-process"
          },
          "name": {
            "type": "string",
            "example": "order-process"
          },
          "version": {
            "type": "integer",
            "example": 1
          },
          "resourceName": {
            "type": "string",
            "example": "order-process.bpmn"
          },
          "tenantId": {
            "type": "string",
            "example": "ps_1a2b3...9f0e"
          }
        }
      },
      "DefinitionList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DefinitionSummary"
            }
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer",
            "description": "Always 0: the list is not paginated."
          },
          "pageSize": {
            "type": "integer",
            "description": "Equals total."
          }
        }
      },
      "StartInstanceRequest": {
        "type": "object",
        "required": [
          "bpmnProcessId"
        ],
        "properties": {
          "bpmnProcessId": {
            "type": "string",
            "example": "order-process",
            "description": "Id of the process in your BPMN. The latest deployed version of your own process starts."
          },
          "processDefinitionId": {
            "type": "string",
            "description": "Accepted alias, read only when bpmnProcessId is empty."
          },
          "variables": {
            "type": "object",
            "additionalProperties": true,
            "example": {
              "orderId": "ORD-42",
              "amount": 99.9
            }
          }
        }
      },
      "StartInstanceResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Same as processInstanceKey.",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "processInstanceKey": {
            "type": "string",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "processDefinitionKey": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02"
          },
          "bpmnProcessId": {
            "type": "string",
            "example": "order-process"
          },
          "version": {
            "type": "integer",
            "example": 1
          },
          "tenantId": {
            "type": "string",
            "example": "ps_1a2b3...9f0e"
          }
        }
      },
      "ElementEvent": {
        "type": "object",
        "properties": {
          "elementId": {
            "type": "string"
          },
          "elementName": {
            "type": "string"
          },
          "enteredAt": {
            "type": "string",
            "format": "date-time"
          },
          "exitedAt": {
            "type": "string",
            "format": "date-time"
          },
          "durationMs": {
            "type": "integer"
          }
        }
      },
      "Instance": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "processDefinitionKey": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02"
          },
          "bpmnProcessId": {
            "type": "string",
            "example": "order-process"
          },
          "version": {
            "type": "integer",
            "example": 1
          },
          "state": {
            "type": "string",
            "enum": [
              "ACTIVE",
              "COMPLETED",
              "INCIDENT",
              "TERMINATED"
            ],
            "description": "INCIDENT: the run failed and cannot move on. TERMINATED: cancelled with DELETE."
          },
          "startDate": {
            "type": "string",
            "format": "date-time"
          },
          "endDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "null while running."
          },
          "tenantId": {
            "type": "string",
            "example": "ps_1a2b3...9f0e"
          },
          "variables": {
            "type": "object",
            "additionalProperties": true
          },
          "activeTokenIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "elementHistory": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ElementEvent"
            }
          }
        }
      },
      "InstanceList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Instance"
            }
          },
          "total": {
            "type": "integer"
          },
          "page": {
            "type": "integer",
            "description": "Always 0: the list is not paginated."
          },
          "pageSize": {
            "type": "integer",
            "description": "Equals total."
          }
        }
      },
      "Job": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "a99f579d62ae71f8764f",
            "description": "20 lowercase hex characters."
          },
          "type": {
            "type": "string",
            "example": "send-email"
          },
          "processInstanceKey": {
            "type": "string",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "processDefinitionKey": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02",
            "description": "Empty for a CMMN case job."
          },
          "variables": {
            "type": "object",
            "additionalProperties": true,
            "description": "Every input variable of the job, unfiltered."
          },
          "retries": {
            "type": "integer",
            "example": 3
          },
          "deadline": {
            "type": "integer",
            "format": "int64",
            "description": "Unix epoch milliseconds, activation time + 300000. Informational: nothing reclaims the job when it passes. 0 in GET /api/v1/jobs."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "0001-01-01T00:00:00Z in the activation response; the real time in GET /api/v1/jobs."
          }
        }
      },
      "ActivateJobsRequest": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "example": "send-email",
            "description": "Job type to activate (the zeebe:taskDefinition type). Always send it: with neither type nor jobType, every waiting job of every type you own is activated, user tasks and message waits included."
          },
          "jobType": {
            "type": "string",
            "description": "Accepted alias, read only when type is empty."
          },
          "maxJobsToActivate": {
            "type": "integer",
            "example": 10,
            "description": "Caps the batch. No server default and no upper bound: omitted, 0 or negative activates every waiting job of that type. Send an explicit value."
          },
          "worker": {
            "type": "string",
            "description": "Accepted and ignored."
          },
          "timeout": {
            "type": "integer",
            "description": "Accepted and ignored: there is no lock duration."
          }
        }
      },
      "CompleteJobRequest": {
        "type": "object",
        "properties": {
          "variables": {
            "type": "object",
            "additionalProperties": true,
            "description": "Merged into the instance (only the names the task's output mapping declares, when it declares one)."
          }
        }
      },
      "FailJobRequest": {
        "type": "object",
        "properties": {
          "retries": {
            "type": "integer",
            "example": 2,
            "description": "The ABSOLUTE remaining retry count, stored as sent (the server does not decrement it). Send job.retries - 1 to use one attempt. > 0: the job is waiting again at once. <= 0 or omitted: the job is removed, the instance goes to INCIDENT and an incident record (JOB_FAILED) is created."
          },
          "errorMessage": {
            "type": "string",
            "example": "payment gateway timeout"
          }
        }
      },
      "Incident": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "inc-4f1c0a9b2d7e4e0c8a51b6f3d2c9e7a1"
          },
          "api_key": {
            "type": "string",
            "description": "The owner's full API key, echoed."
          },
          "process_key": {
            "type": "string"
          },
          "instance_key": {
            "type": "string",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "element_id": {
            "type": "string",
            "description": "For incidents raised by the engine, the job key."
          },
          "error_code": {
            "type": "string",
            "example": "JOB_FAILED"
          },
          "error_message": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "critical",
              "warning",
              "info"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "resolved_at": {
            "type": "string",
            "format": "date-time"
          },
          "resolved_by": {
            "type": "string"
          },
          "root_cause": {
            "type": "string"
          },
          "post_mortem_url": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "retry_count": {
            "type": "integer"
          },
          "alert_sent": {
            "type": "boolean"
          },
          "correlation_id": {
            "type": "string"
          }
        }
      },
      "IncidentList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Incident"
            }
          },
          "total": {
            "type": "integer"
          },
          "open_count": {
            "type": "integer"
          }
        }
      },
      "ModelDeployResponse": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "3f9c2a7e5b1d8c4e6a02"
          },
          "modelKind": {
            "type": "string",
            "enum": [
              "bpmn",
              "cmmn",
              "dmn",
              "archimate"
            ]
          },
          "resourceName": {
            "type": "string"
          },
          "tenantId": {
            "type": "string",
            "description": "Currently the full API key, echoed."
          }
        }
      },
      "ModelSummary": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "modelKind": {
            "type": "string",
            "enum": [
              "bpmn",
              "cmmn",
              "dmn",
              "archimate"
            ]
          },
          "id": {
            "type": "string",
            "description": "bpmnProcessId, case id or decision id."
          },
          "name": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "resourceName": {
            "type": "string"
          },
          "tenantId": {
            "type": "string"
          }
        }
      },
      "Case": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "run_1ce49bbc5260b39423bd"
          },
          "caseDefinitionId": {
            "type": "string",
            "example": "fraud_investigation_case"
          },
          "status": {
            "type": "string",
            "example": "ACTIVE"
          },
          "startTime": {
            "type": "string",
            "format": "date-time"
          },
          "endTime": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "variables": {
            "type": "object",
            "additionalProperties": true
          },
          "errorMessage": {
            "type": "string"
          },
          "tenantId": {
            "type": "string",
            "description": "Currently the full API key, echoed."
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "The job key."
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "process_id": {
            "type": "string",
            "description": "processDefinitionKey."
          },
          "instance_id": {
            "type": "string"
          },
          "variables": {
            "type": "object",
            "additionalProperties": true
          },
          "assignee": {
            "type": "string"
          },
          "candidate_groups": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "open",
              "claimed"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "due_date": {
            "type": "string",
            "nullable": true
          },
          "priority": {
            "type": "string",
            "example": "medium"
          }
        }
      },
      "Worker": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "wkr-9d2f4c1a7b3e4f60a8c5d1e2f3b4a596"
          },
          "api_key": {
            "type": "string",
            "description": "The owner's full API key, echoed."
          },
          "topics": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "last_heartbeat": {
            "type": "string",
            "format": "date-time"
          },
          "registered_at": {
            "type": "string",
            "format": "date-time"
          },
          "active": {
            "type": "boolean",
            "description": "true while the last heartbeat is under 90 s old."
          },
          "group_name": {
            "type": "string"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "wh-1727600000000000000"
          },
          "api_key": {
            "type": "string",
            "description": "The owner's full API key, echoed."
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          },
          "secret": {
            "type": "string",
            "description": "HMAC-SHA256 key for X-Priostack-Signature."
          },
          "active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "webhook_id": {
            "type": "string"
          },
          "event": {
            "type": "string"
          },
          "payload": {
            "type": "string",
            "description": "The JSON body that was sent, as a string."
          },
          "status_code": {
            "type": "integer"
          },
          "error": {
            "type": "string"
          },
          "latency_ms": {
            "type": "integer"
          },
          "delivered_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DeadLetter": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "channel_id": {
            "type": "string",
            "description": "The webhook id."
          },
          "tenant_id": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "secret": {
            "type": "string"
          },
          "event": {
            "type": "string"
          },
          "payload": {
            "type": "object",
            "additionalProperties": true
          },
          "error_reason": {
            "type": "string"
          },
          "retry_count": {
            "type": "integer"
          },
          "dead_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ServiceRecord": {
        "type": "object",
        "properties": {
          "app_id": {
            "type": "string"
          },
          "tenant_id": {
            "type": "string"
          },
          "manifest": {
            "type": "object",
            "additionalProperties": true
          },
          "scoped_token": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "unreachable",
              "degraded"
            ]
          },
          "registered_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_seen": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "tags": [
          "System"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Service healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "service": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "ok",
                  "service": "priostack"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/topology": {
      "get": {
        "summary": "Engine topology",
        "operationId": "getTopology",
        "tags": [
          "System"
        ],
        "security": [],
        "description": "Answers without a key. The shape mirrors a Zeebe topology so modelers can check reachability; gatewayVersion is a fixed string, not the Priostack version. Priostack speaks HTTPS and JSON only: there is no gRPC endpoint.",
        "responses": {
          "200": {
            "description": "Topology",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "brokers": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "clusterSize": {
                      "type": "integer"
                    },
                    "partitionsCount": {
                      "type": "integer"
                    },
                    "replicationFactor": {
                      "type": "integer"
                    },
                    "gatewayVersion": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "brokers": [
                    {
                      "nodeId": 0,
                      "host": "priostack.com",
                      "port": 443,
                      "partitions": [
                        {
                          "partitionId": 1,
                          "role": "LEADER",
                          "health": "HEALTHY"
                        }
                      ],
                      "version": "8.4.0"
                    }
                  ],
                  "clusterSize": 1,
                  "partitionsCount": 1,
                  "replicationFactor": 1,
                  "gatewayVersion": "8.4.0"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/process-definitions": {
      "post": {
        "summary": "Deploy BPMN",
        "operationId": "deployProcess",
        "tags": [
          "Process definitions"
        ],
        "description": "Deploys BPMN only (DMN, CMMN and ArchiMate go through POST /api/v1/models). Two encodings: a raw XML body when Content-Type contains xml (optional ?resourceName=, default process.bpmn), or multipart/form-data where EVERY file part is deployed whatever its field name, with the part's filename as resourceName. Parts are deployed in turn; the first failure answers 422 after the earlier parts are deployed. A multipart with no file part answers 200 with no deployment.\n\nRedeploying byte-identical XML returns the existing definition and version; changed XML with the same process id creates version n+1. Running instances keep the version they started on. There is no node-count limit; a model that does not parse or compile answers 422. This route takes no credit and never answers 402.",
        "parameters": [
          {
            "name": "resourceName",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Resource name for a raw XML body.",
            "example": "order-process.bpmn"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/xml": {
              "schema": {
                "type": "string",
                "description": "BPMN 2.0 XML"
              }
            },
            "text/xml": {
              "schema": {
                "type": "string",
                "description": "BPMN 2.0 XML"
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "A .bpmn file. Any field name works; every file part is deployed."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deployed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeployResponse"
                },
                "example": {
                  "id": "order-process",
                  "deployments": [
                    {
                      "processDefinitionKey": "3f9c2a7e5b1d8c4e6a02",
                      "bpmnProcessId": "order-process",
                      "id": "order-process",
                      "version": 1,
                      "resourceName": "order-process.bpmn",
                      "tenantId": "ps_1a2b3...9f0e"
                    }
                  ],
                  "key": 1727600000000,
                  "tenantId": "<default>"
                }
              }
            }
          },
          "400": {
            "description": "Wrong Content-Type, or empty body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "expected multipart form or application/xml body"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing api key"
                }
              }
            }
          },
          "422": {
            "description": "The model does not parse or compile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "deploy failed: bpmn xml: XML syntax error on line 8: expected element name after <"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List process definitions",
        "operationId": "listProcessDefinitions",
        "tags": [
          "Process definitions"
        ],
        "responses": {
          "200": {
            "description": "Your definitions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DefinitionList"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/process-definitions/{key}/xml": {
      "get": {
        "summary": "Get a definition's BPMN XML",
        "operationId": "getProcessDefinitionXML",
        "tags": [
          "Process definitions"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "processDefinitionKey",
            "example": "3f9c2a7e5b1d8c4e6a02"
          }
        ],
        "responses": {
          "200": {
            "description": "The BPMN source",
            "content": {
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown key, or another account's definition",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "definition 3f9c2a7e5b1d8c4e6a02 not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/process-instances": {
      "post": {
        "summary": "Start a process instance (1 credit)",
        "operationId": "createProcessInstance",
        "tags": [
          "Process instances"
        ],
        "description": "Starts the latest deployed version of your bpmnProcessId. The credit is taken before the body is read and refunded on 400 or 422. processDefinitionKey does NOT name the process (a string there fails with 400 invalid json); version, withResultVariables and operationReference are accepted and ignored. There is no batch route: start instances one call at a time.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartInstanceRequest"
              },
              "example": {
                "bpmnProcessId": "order-process",
                "variables": {
                  "orderId": "ORD-42",
                  "amount": 99.9
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Instance started, 1 credit spent",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StartInstanceResponse"
                }
              }
            },
            "headers": {
              "X-Credits-Spent": {
                "description": "Credits taken by this call (1).",
                "schema": {
                  "type": "integer",
                  "example": 1
                }
              }
            }
          },
          "400": {
            "description": "Body is not valid JSON (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid json"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing api key"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low, account disabled, or key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceStartCreditsError"
                },
                "example": {
                  "error": "insufficient credits: have 0, need 1",
                  "balance": 0,
                  "buy": "https://priostack.com/credits"
                }
              }
            }
          },
          "422": {
            "description": "No such process deployed for this key (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "process \"order-process\" not deployed"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List process instances",
        "operationId": "listProcessInstances",
        "tags": [
          "Process instances"
        ],
        "description": "Your instances, newest start first by default. Not paginated. Plain state=, status=, page and per_page are ignored; use the filter.* parameters. To find stuck instances use filter.state=INCIDENT.",
        "parameters": [
          {
            "name": "filter.state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "ACTIVE",
                "COMPLETED",
                "INCIDENT",
                "TERMINATED"
              ]
            },
            "description": "Instance state."
          },
          {
            "name": "filter.bpmnProcessId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Exact process id."
          },
          {
            "name": "filter.startAfter",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "RFC 3339 time."
          },
          {
            "name": "filter.startBefore",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "RFC 3339 time."
          },
          {
            "name": "filter.endAfter",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "RFC 3339 time."
          },
          {
            "name": "filter.endBefore",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "RFC 3339 time."
          },
          {
            "name": "filter.variable",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "key:value, a case-insensitive substring match on one variable.",
            "example": "orderId:ORD-42"
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "startDate",
                "endDate",
                "duration"
              ]
            },
            "description": "Sort field."
          },
          {
            "name": "sort.order",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            },
            "description": "Sort order (default desc)."
          }
        ],
        "responses": {
          "200": {
            "description": "Your instances",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceList"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/process-instances/{key}": {
      "get": {
        "summary": "Get a process instance",
        "operationId": "getProcessInstance",
        "tags": [
          "Process instances"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Process instance key",
            "example": "run_1ce49bbc5260b39423bd"
          }
        ],
        "responses": {
          "200": {
            "description": "The instance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Instance"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown key, or another account's instance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "instance run_1ce49bbc5260b39423bd not found"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update instance variables",
        "operationId": "updateProcessInstanceVariables",
        "tags": [
          "Process instances"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Process instance key",
            "example": "run_1ce49bbc5260b39423bd"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "variables"
                ],
                "properties": {
                  "variables": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "variables": {
                  "approved": true
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated instance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Instance"
                }
              }
            }
          },
          "400": {
            "description": "Body is not {\"variables\":{...}}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "body must be {\"variables\":{...}}"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "instance run_1ce49bbc5260b39423bd not found"
                }
              }
            }
          },
          "422": {
            "description": "The engine refused the update",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "set variables on run run_1ce49bbc5260b39423bd: <engine error>"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Cancel a process instance",
        "operationId": "cancelProcessInstance",
        "tags": [
          "Process instances"
        ],
        "description": "Cancels an ACTIVE instance, which becomes TERMINATED. An instance in INCIDENT cannot be cancelled (422).",
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Process instance key",
            "example": "run_1ce49bbc5260b39423bd"
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "key": "run_1ce49bbc5260b39423bd",
                  "message": "Process instance run_1ce49bbc5260b39423bd has been cancelled."
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "instance run_1ce49bbc5260b39423bd not found"
                }
              }
            }
          },
          "422": {
            "description": "Not ACTIVE",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "instance run_1ce49bbc5260b39423bd is not active (state: INCIDENT)"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs": {
      "get": {
        "summary": "List your waiting jobs (read-only)",
        "operationId": "listJobs",
        "tags": [
          "Job workers"
        ],
        "description": "A read-only view of your jobs that are waiting to be activated. It activates nothing. jobs is null when none waits.",
        "responses": {
          "200": {
            "description": "Waiting jobs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobs": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "$ref": "#/components/schemas/Job"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs/activate": {
      "post": {
        "summary": "Activate jobs",
        "operationId": "activateJobs",
        "tags": [
          "Job workers"
        ],
        "description": "Answers at once, with {\"jobs\":[]} when nothing waits: there is no long polling, so sleep 1 to 5 s between empty polls (the firewall allows 300 requests per minute per IP). An activated job stays yours until you complete or fail it: there is no lock expiry and no other worker receives it. On shutdown, fail unfinished jobs with retries unchanged to hand them back. Only jobs of your own instances and cases are handed out. The JSON body is read before the key is checked, so an empty body answers 400. Worker registration is not required. Free of credits.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ActivateJobsRequest"
              },
              "example": {
                "type": "send-email",
                "maxJobsToActivate": 10
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Activated jobs, possibly none",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Job"
                      }
                    }
                  }
                },
                "example": {
                  "jobs": [
                    {
                      "key": "a99f579d62ae71f8764f",
                      "type": "send-email",
                      "processInstanceKey": "run_1ce49bbc5260b39423bd",
                      "processDefinitionKey": "3f9c2a7e5b1d8c4e6a02",
                      "variables": {
                        "orderId": "ORD-42"
                      },
                      "retries": 3,
                      "deadline": 1727600300000,
                      "createdAt": "0001-01-01T00:00:00Z"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Body is empty or not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid json"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs/{key}/complete": {
      "post": {
        "summary": "Complete a job",
        "operationId": "completeJob",
        "tags": [
          "Job workers"
        ],
        "description": "Success is 204 with an empty body. A repeated completion answers 404, never 409: there is no idempotency key, so after a lost response read the instance to reconcile. Free of credits. The only other job action is /fail: no REST route throws a BPMN error or changes a job's retries.",
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Job key from activation",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteJobRequest"
              },
              "example": {
                "variables": {
                  "emailSent": true
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Completed"
          },
          "400": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid json"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown, already completed, failed to zero retries, cancelled, or another account's job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "job not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/jobs/{key}/fail": {
      "post": {
        "summary": "Fail a job",
        "operationId": "failJob",
        "tags": [
          "Job workers"
        ],
        "description": "Success is 204 with an empty body. retries is the absolute remaining count: > 0 makes the job activatable again immediately (no backoff), <= 0 or omitted raises an incident and puts the instance in INCIDENT. An INCIDENT instance cannot be resumed over REST today. Free of credits.",
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Job key from activation",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FailJobRequest"
              },
              "example": {
                "retries": 2,
                "errorMessage": "payment gateway timeout"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Failed"
          },
          "400": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid json"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown or finished job",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "job not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/incidents": {
      "get": {
        "summary": "List incident records",
        "operationId": "listIncidents",
        "tags": [
          "Incidents"
        ],
        "description": "Every incident record of your account, in no particular order, with no pagination and no filters. The engine creates a record only when a job is failed with retries <= 0. Other run failures put the instance in INCIDENT without a record: find those with GET /api/v1/process-instances?filter.state=INCIDENT. X-Correlation-ID is echoed.",
        "responses": {
          "200": {
            "description": "Your incidents",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IncidentList"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an incident record",
        "operationId": "createIncident",
        "tags": [
          "Incidents"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "process_key": {
                    "type": "string"
                  },
                  "instance_key": {
                    "type": "string"
                  },
                  "element_id": {
                    "type": "string"
                  },
                  "error_code": {
                    "type": "string"
                  },
                  "error_message": {
                    "type": "string"
                  },
                  "severity": {
                    "type": "string",
                    "enum": [
                      "critical",
                      "warning",
                      "info"
                    ],
                    "description": "Default warning."
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "retry_count": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Incident"
                }
              }
            }
          },
          "400": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid JSON body"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/incidents/{id}": {
      "patch": {
        "summary": "Resolve an incident record",
        "operationId": "resolveIncident",
        "tags": [
          "Incidents"
        ],
        "description": "Marks the RECORD resolved. It does not touch the instance, which stays in INCIDENT. A JSON body is required ({} is fine).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Incident id",
            "example": "inc-4f1c0a9b2d7e4e0c8a51b6f3d2c9e7a1"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "resolved_by": {
                    "type": "string"
                  },
                  "root_cause": {
                    "type": "string"
                  },
                  "post_mortem_url": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resolved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "id": "inc-4f1c0a9b2d7e4e0c8a51b6f3d2c9e7a1",
                  "status": "resolved"
                }
              }
            }
          },
          "400": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid JSON body"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "incidents: \"inc-4f1c0a9b2d7e4e0c8a51b6f3d2c9e7a1\" not found"
                }
              }
            }
          },
          "422": {
            "description": "Already resolved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "incidents: \"inc-4f1c0a9b2d7e4e0c8a51b6f3d2c9e7a1\" already resolved"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/incidents/bulk-resolve": {
      "post": {
        "summary": "Resolve several incident records",
        "operationId": "bulkResolveIncidents",
        "tags": [
          "Incidents"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "resolved_by": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Resolved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "resolved": {
                      "type": "integer"
                    },
                    "status": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "resolved": 2,
                  "status": "ok"
                }
              }
            }
          },
          "400": {
            "description": "No ids",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "ids must not be empty"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/incidents/export": {
      "get": {
        "summary": "Export incident records as CSV",
        "operationId": "exportIncidents",
        "tags": [
          "Incidents"
        ],
        "responses": {
          "200": {
            "description": "CSV file",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models": {
      "post": {
        "summary": "Deploy any model (1 credit)",
        "operationId": "deployModel",
        "tags": [
          "Models, decisions and cases"
        ],
        "description": "Deploys BPMN, DMN, CMMN or ArchiMate; the kind is detected from the XML. Costs 1 credit, refunded when the deploy fails. Body: raw XML (any Content-Type other than multipart or JSON, optional ?resourceName=), JSON {resourceName, xml}, or multipart with TEXT fields xml and resourceName (a file part is not read).",
        "parameters": [
          {
            "name": "resourceName",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Resource name for a raw XML body (default model.xml).",
            "example": "credit_policy.dmn"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/xml": {
              "schema": {
                "type": "string"
              }
            },
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "xml"
                ],
                "properties": {
                  "resourceName": {
                    "type": "string"
                  },
                  "xml": {
                    "type": "string"
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "resourceName": {
                    "type": "string"
                  },
                  "xml": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Deployed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelDeployResponse"
                }
              }
            }
          },
          "400": {
            "description": "Empty or unreadable body (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "xml body is required"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "insufficient credits"
                }
              }
            }
          },
          "422": {
            "description": "The model does not parse or compile (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "<parser or compiler error>"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List deployed models",
        "operationId": "listModels",
        "tags": [
          "Models, decisions and cases"
        ],
        "responses": {
          "200": {
            "description": "Your models",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "models": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "$ref": "#/components/schemas/ModelSummary"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/models/{id}/xml": {
      "get": {
        "summary": "Get a model's XML",
        "operationId": "getModelXML",
        "tags": [
          "Models, decisions and cases"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Model key",
            "example": "3f9c2a7e5b1d8c4e6a02"
          }
        ],
        "responses": {
          "200": {
            "description": "The XML source",
            "content": {
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "404": {
            "description": "Unknown model",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "model not found: 3f9c2a7e5b1d8c4e6a02"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/decisions/{decisionId}/evaluate": {
      "post": {
        "summary": "Evaluate a DMN decision (1 credit)",
        "operationId": "evaluateDecision",
        "tags": [
          "Models, decisions and cases"
        ],
        "description": "The body is a FLAT JSON object of inputs, not wrapped in variables. Outputs come back as strings. Deploy the DMN first with POST /api/v1/models. The credit is refunded on 400 or 422.",
        "parameters": [
          {
            "name": "decisionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The decision id in the DMN",
            "example": "discount"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              },
              "example": {
                "customerType": "silver",
                "orderAmount": 300
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Outputs of the matched rule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "result": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  }
                },
                "example": {
                  "result": {
                    "discountPercent": "8"
                  }
                }
              }
            },
            "headers": {
              "X-Credits-Spent": {
                "description": "Credits taken by this call (1).",
                "schema": {
                  "type": "integer",
                  "example": 1
                }
              }
            }
          },
          "400": {
            "description": "Body is not a JSON object",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid JSON inputs: unexpected EOF"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "insufficient credits"
                }
              }
            }
          },
          "422": {
            "description": "Decision not deployed for this key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "decision \"discount\" not deployed for this tenant"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/cases": {
      "post": {
        "summary": "Start a CMMN case (1 credit)",
        "operationId": "startCase",
        "tags": [
          "Models, decisions and cases"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "caseDefinitionId"
                ],
                "properties": {
                  "caseDefinitionId": {
                    "type": "string"
                  },
                  "variables": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "caseDefinitionId": "fraud_investigation_case",
                "variables": {
                  "alertId": "A-17"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Case started",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            },
            "headers": {
              "X-Credits-Spent": {
                "description": "Credits taken by this call (1).",
                "schema": {
                  "type": "integer",
                  "example": 1
                }
              }
            }
          },
          "400": {
            "description": "Body is not JSON (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid JSON: unexpected EOF"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "insufficient credits"
                }
              }
            }
          },
          "422": {
            "description": "Unknown case definition (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "case \"fraud_investigation_case\" not deployed"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List cases",
        "operationId": "listCases",
        "tags": [
          "Models, decisions and cases"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by case status."
          }
        ],
        "responses": {
          "200": {
            "description": "Your cases",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "cases": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Case"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/cases/{key}": {
      "get": {
        "summary": "Get a case",
        "operationId": "getCase",
        "tags": [
          "Models, decisions and cases"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Case key",
            "example": "run_1ce49bbc5260b39423bd"
          }
        ],
        "responses": {
          "200": {
            "description": "The case",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Case"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "404": {
            "description": "Unknown case",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Terminate a case",
        "operationId": "terminateCase",
        "tags": [
          "Models, decisions and cases"
        ],
        "parameters": [
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Case key",
            "example": "run_1ce49bbc5260b39423bd"
          }
        ],
        "responses": {
          "204": {
            "description": "Terminated"
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "404": {
            "description": "Unknown case",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found"
                }
              }
            }
          },
          "422": {
            "description": "The case is not active",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "case run_1ce49bbc5260b39423bd is not active (state: COMPLETED)"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/cases/jobs/{jobKey}/complete": {
      "post": {
        "summary": "Complete a case plan item",
        "operationId": "completePlanItem",
        "tags": [
          "Models, decisions and cases"
        ],
        "description": "Completes a human task or process task job of a case. Free of credits.",
        "parameters": [
          {
            "name": "jobKey",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The plan item's job key",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "variables": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "instanceKey": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "instanceKey": "run_1ce49bbc5260b39423bd"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "404": {
            "description": "Unknown job or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found"
                }
              }
            }
          },
          "422": {
            "description": "The engine refused",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "complete plan-item job a99f579d62ae71f8764f: no such job"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/agent/status": {
      "get": {
        "summary": "Agent status",
        "operationId": "agentStatus",
        "tags": [
          "AI agent"
        ],
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tenantId": {
                      "type": "string"
                    },
                    "totalReasoningCalls": {
                      "type": "integer"
                    },
                    "totalToolCalls": {
                      "type": "integer"
                    },
                    "successRate": {
                      "type": "number"
                    },
                    "tools": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "500": {
            "description": "The agent could not start",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "agent unavailable: ..."
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/agent/query": {
      "post": {
        "summary": "Ask the agent (1 credit)",
        "operationId": "agentQuery",
        "tags": [
          "AI agent"
        ],
        "description": "Costs 1 credit, refunded when the query fails.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "question"
                ],
                "properties": {
                  "question": {
                    "type": "string"
                  },
                  "context": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Answer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "answer": {
                      "type": "string"
                    },
                    "confidence": {
                      "type": "number"
                    },
                    "steps": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "No question",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "question is required"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "insufficient credits"
                }
              }
            }
          },
          "500": {
            "description": "The agent failed (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "agent error: ..."
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/agent/insights": {
      "get": {
        "summary": "Agent insights",
        "operationId": "agentInsights",
        "tags": [
          "AI agent"
        ],
        "responses": {
          "200": {
            "description": "Insights",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "insights": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "category": {
                            "type": "string"
                          },
                          "message": {
                            "type": "string"
                          },
                          "severity": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing API key"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/graphql": {
      "post": {
        "summary": "Human tasks over GraphQL",
        "operationId": "graphql",
        "tags": [
          "Task list"
        ],
        "description": "Not a full GraphQL server: the operation is chosen by operationName (getTasks, getTask, completeTask, claimTask). getTask, completeTask and claimTask read variables.taskId; completeTask reads variables.variables; claimTask reads variables.assignee. Always answers 200: errors, including a missing key, come back in errors[]. completeTask here is free of credits.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "operationName": {
                    "type": "string",
                    "enum": [
                      "getTasks",
                      "getTask",
                      "completeTask",
                      "claimTask"
                    ]
                  },
                  "query": {
                    "type": "string"
                  },
                  "variables": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              },
              "example": {
                "operationName": "completeTask",
                "query": "mutation completeTask($taskId: String!) { completeTask(taskId: $taskId) { id } }",
                "variables": {
                  "taskId": "a99f579d62ae71f8764f",
                  "variables": {
                    "approved": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "GraphQL envelope",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "nullable": true
                    },
                    "errors": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "type": "object",
                        "properties": {
                          "message": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks": {
      "get": {
        "summary": "List tasks",
        "operationId": "listTasks",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "description": "Every job of yours that waits to be activated. X-API-Key header or ?api_key only (no Bearer).",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "claimed"
              ]
            },
            "description": "open or claimed."
          },
          {
            "name": "definition_key",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Substring of processDefinitionKey."
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Task"
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "page": {
                      "type": "integer"
                    },
                    "per_page": {
                      "type": "integer"
                    },
                    "has_next": {
                      "type": "boolean"
                    },
                    "has_prev": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/claim": {
      "post": {
        "summary": "Claim a task",
        "operationId": "claimTask",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "responses": {
          "200": {
            "description": "Done",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "assignee": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "claimed",
                  "assignee": "you@company.com"
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/unclaim": {
      "post": {
        "summary": "Unclaim a task",
        "operationId": "unclaimTask",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "responses": {
          "200": {
            "description": "Done",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "assignee": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "unclaimed"
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/assign": {
      "post": {
        "summary": "Assign a task",
        "operationId": "assignTask",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "responses": {
          "200": {
            "description": "Done",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "assignee": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "assigned",
                  "assignee": "colleague@company.com"
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          },
          "400": {
            "description": "No user_id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "user_id required"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "user_id"
                ],
                "properties": {
                  "user_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/complete": {
      "post": {
        "summary": "Complete a task (1 credit)",
        "operationId": "completeTask",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "description": "Costs 1 credit, refunded when the engine refuses the completion. The same task completed through GraphQL completeTask or POST /api/v1/jobs/{key}/complete costs nothing.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "variables": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "completed"
                }
              }
            }
          },
          "400": {
            "description": "Body is not JSON, or the engine refused (credit refunded)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid json"
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "402": {
            "description": "Balance too low",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "insufficient credits"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/comment": {
      "post": {
        "summary": "Comment on a task",
        "operationId": "commentTask",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "text"
                ],
                "properties": {
                  "text": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Comment",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "task_id": {
                      "type": "string"
                    },
                    "author": {
                      "type": "string"
                    },
                    "text": {
                      "type": "string"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "No text",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "text required"
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/comments": {
      "get": {
        "summary": "List a task's comments",
        "operationId": "listTaskComments",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "description": "Comments are kept in memory and do not survive a server restart.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "responses": {
          "200": {
            "description": "Comments",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tasks/{id}/history": {
      "get": {
        "summary": "A task's history",
        "operationId": "taskHistory",
        "tags": [
          "Task list"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "apiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Task id (the job key)",
            "example": "a99f579d62ae71f8764f"
          }
        ],
        "responses": {
          "200": {
            "description": "Events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "task_id": {
                      "type": "string"
                    },
                    "events": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "action": {
                            "type": "string"
                          },
                          "actor": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown task, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "task not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/workers/register": {
      "post": {
        "summary": "Register a worker (optional)",
        "operationId": "registerWorker",
        "tags": [
          "Worker registry"
        ],
        "description": "Informational only: activation, locking and incidents never read the registry, and the API key alone is enough to activate jobs.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "topics"
                ],
                "properties": {
                  "topics": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "group_name": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "topics": [
                  "send-email"
                ],
                "group_name": "mailers"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registered",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Worker"
                }
              }
            }
          },
          "400": {
            "description": "No topics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "topics must not be empty"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/workers/heartbeat": {
      "get": {
        "summary": "Worker heartbeat (optional)",
        "operationId": "workerHeartbeat",
        "tags": [
          "Worker registry"
        ],
        "parameters": [
          {
            "name": "worker_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Worker id from registration."
          }
        ],
        "responses": {
          "200": {
            "description": "Recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "worker_id": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "No worker_id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "worker_id query param required"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Unknown or another account's worker",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "workers: worker \"wkr-9d2f4c1a7b3e4f60a8c5d1e2f3b4a596\" not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/workers": {
      "get": {
        "summary": "List registered workers",
        "operationId": "listWorkers",
        "tags": [
          "Worker registry"
        ],
        "responses": {
          "200": {
            "description": "Workers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Worker"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/webhooks": {
      "post": {
        "summary": "Create a webhook",
        "operationId": "createWebhook",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "description": "Only the X-API-Key header is accepted, and the key must belong to an account.\n\nEvents (the only ones any code fires): deploy.succeeded {count, deployments}, deploy.failed {resource, error}, credits.topped_up {credits, pack_id}, credits.low {balance, threshold} (thresholds 30, 20, 10), message.received, message.acknowledged, message.completed, message.failed, and test from the test route. There are no instance, job or incident events. A webhook receives only the events listed in its events array, matched exactly; an empty list receives nothing.\n\nEach delivery is a POST of {event, id: evt-<unixnano>, timestamp, data} with Content-Type application/json, User-Agent Priostack-Webhook/1.0 and X-Priostack-Signature: sha256=<hex HMAC-SHA256 of the raw body keyed with the secret>. 3 attempts in total, 0.5 s then 1 s apart, 10 s timeout each; any 2xx counts as delivered, and an exhausted delivery goes to the dead-letter queue. URLs that resolve to loopback, private, link-local or multicast addresses are refused at delivery time.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "deploy.succeeded",
                        "deploy.failed",
                        "credits.topped_up",
                        "credits.low",
                        "message.received",
                        "message.acknowledged",
                        "message.completed",
                        "message.failed"
                      ]
                    }
                  },
                  "secret": {
                    "type": "string",
                    "description": "Optional: a 64-hex-character secret is generated when blank."
                  }
                }
              },
              "example": {
                "url": "https://example.com/priostack-webhook",
                "events": [
                  "deploy.succeeded",
                  "credits.low"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (the response carries the secret)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Webhook"
                }
              }
            }
          },
          "400": {
            "description": "No url",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "url is required"
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List webhooks",
        "operationId": "listWebhooks",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "responses": {
          "200": {
            "description": "Your webhooks, secrets included",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "webhooks": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Webhook"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/webhooks/{id}": {
      "get": {
        "summary": "Get a webhook",
        "operationId": "getWebhook",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook id",
            "example": "wh-1727600000000000000"
          }
        ],
        "responses": {
          "200": {
            "description": "The webhook",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Webhook"
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          },
          "404": {
            "description": "Unknown webhook, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "webhook not found"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update a webhook",
        "operationId": "updateWebhook",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook id",
            "example": "wh-1727600000000000000"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string"
                  },
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "active": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Webhook"
                }
              }
            }
          },
          "400": {
            "description": "Body is not JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid request body"
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          },
          "404": {
            "description": "Unknown webhook, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "webhook not found"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete a webhook",
        "operationId": "deleteWebhook",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook id",
            "example": "wh-1727600000000000000"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "ok": true
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          },
          "404": {
            "description": "Unknown webhook, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "webhook not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/webhooks/{id}/test": {
      "post": {
        "summary": "Send a test delivery",
        "operationId": "testWebhook",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "description": "Sends one signed POST with event test, whatever the webhook's events list, and reports what the endpoint answered.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook id",
            "example": "wh-1727600000000000000"
          }
        ],
        "responses": {
          "200": {
            "description": "Result of the attempt",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status_code": {
                      "type": "integer"
                    },
                    "latency_ms": {
                      "type": "integer"
                    },
                    "success": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "status_code": 200,
                  "latency_ms": 143,
                  "success": true
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          },
          "404": {
            "description": "Unknown webhook, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "webhook not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/webhooks/{id}/deliveries": {
      "get": {
        "summary": "List delivery attempts",
        "operationId": "listWebhookDeliveries",
        "tags": [
          "Webhooks"
        ],
        "security": [
          {
            "apiKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Webhook id",
            "example": "wh-1727600000000000000"
          }
        ],
        "responses": {
          "200": {
            "description": "Attempts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deliveries": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing X-API-Key header, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "missing X-API-Key header"
                }
              }
            }
          },
          "404": {
            "description": "Unknown webhook, or another account's",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "webhook not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/dead-letters": {
      "get": {
        "summary": "List dead-lettered deliveries",
        "operationId": "listDeadLetters",
        "tags": [
          "Dead letters"
        ],
        "description": "Unresolved webhook deliveries that failed every attempt. A bare JSON array, or null when there is none.",
        "responses": {
          "200": {
            "description": "Dead letters",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "nullable": true,
                  "items": {
                    "$ref": "#/components/schemas/DeadLetter"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/dead-letters/{id}/reprocess": {
      "post": {
        "summary": "Retry a dead-lettered delivery",
        "operationId": "reprocessDeadLetter",
        "tags": [
          "Dead letters"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Dead letter id",
            "example": "dl-1727600000000000000"
          }
        ],
        "responses": {
          "200": {
            "description": "Delivered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "delivered": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "status": "reprocessed",
                  "delivered": true
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown or already resolved",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found or already resolved"
                }
              }
            }
          },
          "502": {
            "description": "The endpoint refused the retry; the message stays queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "status": "retry_failed",
                  "error": "the endpoint did not accept the retry"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/dead-letters/export": {
      "get": {
        "summary": "Export dead letters as JSON",
        "operationId": "exportDeadLetters",
        "tags": [
          "Dead letters"
        ],
        "responses": {
          "200": {
            "description": "JSON attachment",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "nullable": true,
                  "items": {
                    "$ref": "#/components/schemas/DeadLetter"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing key, or a key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "summary": "Account details and balance",
        "operationId": "getMe",
        "tags": [
          "Account and credits"
        ],
        "description": "api_key is always masked: the full key is never returned here. It arrives in the welcome email once the address is verified, and the signed-in owner can show or rotate it in Creator Studio. plan is a label computed from the balance (sandbox when the balance is 100 or less, builder above), not a subscription.",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user_id": {
                      "type": "string",
                      "description": "The account's sign-in email address."
                    },
                    "api_key": {
                      "type": "string",
                      "description": "Masked: first 8 characters, ..., last 4."
                    },
                    "balance": {
                      "type": "integer",
                      "description": "Credits."
                    },
                    "plan": {
                      "type": "string",
                      "enum": [
                        "sandbox",
                        "builder"
                      ]
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "workflow_endpoint": {
                      "type": "string"
                    }
                  }
                },
                "example": {
                  "user_id": "you@company.com",
                  "api_key": "ps_1a2b3...9f0e",
                  "balance": 187,
                  "plan": "builder",
                  "created_at": "2026-09-01T10:00:00Z",
                  "workflow_endpoint": "https://priostack.com/api/v1"
                }
              }
            }
          },
          "401": {
            "description": "Missing, unknown or disabled key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unknown or disabled api key"
                }
              }
            }
          }
        }
      }
    },
    "/api/usage": {
      "get": {
        "summary": "Credit ledger",
        "operationId": "getUsage",
        "tags": [
          "Account and credits"
        ],
        "description": "The whole ledger, oldest first, unpaginated. For pages use GET /api/wallet/transactions.",
        "responses": {
          "200": {
            "description": "Ledger",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer"
                    },
                    "entries": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/LedgerEntry"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "account not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/usage/export": {
      "get": {
        "summary": "Credit ledger as CSV",
        "operationId": "exportUsage",
        "tags": [
          "Account and credits"
        ],
        "description": "Columns Date, Description, Credits, Instance.",
        "responses": {
          "200": {
            "description": "CSV file",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "account not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/credits": {
      "get": {
        "summary": "Credit balance",
        "operationId": "getCredits",
        "tags": [
          "Account and credits"
        ],
        "responses": {
          "200": {
            "description": "Balance",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer"
                    }
                  }
                },
                "example": {
                  "balance": 187
                }
              }
            }
          },
          "401": {
            "description": "Missing or unknown key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unknown api key"
                }
              }
            }
          }
        }
      }
    },
    "/api/credits/packs": {
      "get": {
        "summary": "Credit packs (public price list)",
        "operationId": "listPacks",
        "tags": [
          "Account and credits"
        ],
        "security": [],
        "description": "Answers without a key. One-off packs: every pack is 10% off the base rate of EUR 1 for 1,000 credits, rounded up to the next whole credit. A pack renews nothing. Credits never expire.",
        "responses": {
          "200": {
            "description": "The packs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "packs"
                  ],
                  "properties": {
                    "packs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CreditPack"
                      }
                    }
                  }
                },
                "example": {
                  "packs": [
                    {
                      "id": "small",
                      "credits": 5556,
                      "price_cents": 500
                    },
                    {
                      "id": "medium",
                      "credits": 22223,
                      "price_cents": 2000
                    },
                    {
                      "id": "large",
                      "credits": 55556,
                      "price_cents": 5000
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/wallet": {
      "get": {
        "summary": "Wallet snapshot",
        "operationId": "getWallet",
        "tags": [
          "Account and credits"
        ],
        "responses": {
          "200": {
            "description": "Wallet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance": {
                      "type": "integer"
                    },
                    "total_spend": {
                      "type": "integer"
                    },
                    "total_top_up": {
                      "type": "integer"
                    },
                    "recent_entries": {
                      "type": "array",
                      "description": "The 20 newest ledger entries, newest first.",
                      "items": {
                        "$ref": "#/components/schemas/LedgerEntry"
                      }
                    },
                    "entry_count": {
                      "type": "integer"
                    },
                    "packs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/CreditPack"
                      }
                    },
                    "buy_url": {
                      "type": "string",
                      "example": "https://priostack.com/wallet"
                    },
                    "low_balance_warn": {
                      "type": "boolean",
                      "description": "true when the balance is under 20."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "account not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/wallet/transactions": {
      "get": {
        "summary": "Ledger, filtered and paginated",
        "operationId": "getTransactions",
        "tags": [
          "Account and credits"
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "spend",
                "topup"
              ]
            },
            "description": "spend or topup (default: all)."
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "1-based page (default 1)."
          },
          {
            "name": "size",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            },
            "description": "Page size (default 50, max 200)."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of entries, newest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transactions": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "$ref": "#/components/schemas/LedgerEntry"
                      }
                    },
                    "page": {
                      "type": "integer"
                    },
                    "page_size": {
                      "type": "integer"
                    },
                    "total": {
                      "type": "integer"
                    },
                    "total_pages": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          },
          "404": {
            "description": "Key with no account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "account not found"
                }
              }
            }
          }
        }
      }
    },
    "/api/badges": {
      "get": {
        "summary": "Badges earned",
        "operationId": "getBadges",
        "tags": [
          "Account and credits"
        ],
        "security": [
          {
            "apiKeyHeader": []
          },
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Badges",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "badges": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "api key required"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/platform/register": {
      "post": {
        "summary": "Register a platform app",
        "operationId": "registerPlatformApp",
        "tags": [
          "Platform apps"
        ],
        "description": "Registers (or re-registers) an app manifest and returns its scoped token. Unknown fields are rejected with 400. A bundle only lists model paths: registering deploys nothing. The app's own calls (heartbeat, token introspection, credit charge and refund, events, platform workers) authenticate with the scoped token and are not in this reference.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "name"
                ],
                "additionalProperties": false,
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "version": {
                    "type": "string"
                  },
                  "category": {
                    "type": "string"
                  },
                  "base_url": {
                    "type": "string"
                  },
                  "icon": {
                    "type": "string"
                  },
                  "color": {
                    "type": "string"
                  },
                  "vendor": {
                    "type": "string"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "credit_costs": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "integer"
                    }
                  },
                  "market_listed": {
                    "type": "boolean"
                  },
                  "market_price": {
                    "type": "string"
                  },
                  "readme": {
                    "type": "string"
                  },
                  "health_path": {
                    "type": "string"
                  },
                  "topics": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "platforms": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "provides": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Capabilities the app offers."
                  },
                  "emits": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Event types the app reports."
                  },
                  "bundle": {
                    "type": "object",
                    "description": "Model paths for a model-only app."
                  }
                }
              },
              "example": {
                "id": "invoice-checker",
                "name": "Invoice checker"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Registered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "app_id": {
                      "type": "string"
                    },
                    "scoped_token": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "registered",
                        "already_registered"
                      ]
                    },
                    "accepted": {
                      "type": "object",
                      "properties": {
                        "capabilities": {
                          "type": "integer"
                        },
                        "events": {
                          "type": "integer"
                        },
                        "models": {
                          "type": "integer"
                        },
                        "scopes": {
                          "type": "integer"
                        },
                        "headless": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid manifest",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "invalid manifest: json: unknown field \"x\""
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/platform/services": {
      "get": {
        "summary": "List your platform apps",
        "operationId": "listPlatformApps",
        "tags": [
          "Platform apps"
        ],
        "responses": {
          "200": {
            "description": "Apps",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "services": {
                      "type": "array",
                      "nullable": true,
                      "items": {
                        "$ref": "#/components/schemas/ServiceRecord"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/platform/services/{id}": {
      "get": {
        "summary": "Get a platform app",
        "operationId": "getPlatformApp",
        "tags": [
          "Platform apps"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "app_id",
            "example": "invoice-checker"
          }
        ],
        "responses": {
          "200": {
            "description": "The app",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceRecord"
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown app",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Deregister a platform app",
        "operationId": "deregisterPlatformApp",
        "tags": [
          "Platform apps"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "app_id",
            "example": "invoice-checker"
          }
        ],
        "responses": {
          "200": {
            "description": "Removed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                },
                "example": {
                  "ok": true
                }
              }
            }
          },
          "401": {
            "description": "Missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "unauthorized"
                }
              }
            }
          },
          "404": {
            "description": "Unknown app",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "not found"
                }
              }
            }
          }
        }
      }
    }
  }
}
