{
  "openapi": "3.1.0",
  "info": {
    "title": "Loopfour Workflows API",
    "description": "The Loopfour Workflows API lets you build, trigger, inspect, and manage deterministic finance workflows programmatically. For action discovery, start with listBlocks (kind=integrations) or call getBlock directly with a known type such as quickbooks. Catalog results expose action IDs, input definitions, requirements, choices, and direct links. REST responses advertise OpenAPI and the API catalog in their Link headers. All endpoints use `x-api-key` authentication and return a consistent `{success, data}` envelope.",
    "version": "1.0.0",
    "contact": {
      "name": "Loopfour Sales",
      "email": "sales@loopfour.ai",
      "url": "https://loopfour.ai/contact"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://loopfour.ai/terms-and-conditions"
    },
    "termsOfService": "https://loopfour.ai/terms-and-conditions"
  },
  "servers": [
    {
      "url": "https://workflow.loopfour.ai/api/v1",
      "description": "Loopfour Workflows API"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "externalDocs": {
    "url": "https://loopfour.ai/docs/api-reference",
    "description": "Loopfour Workflows API reference."
  },
  "tags": [
    {
      "name": "Blocks",
      "description": "Discover actions, typed inputs, conditions and report choices."
    },
    {
      "name": "Workflows",
      "description": "Build, activate, and manage workflow definitions."
    },
    {
      "name": "Runs",
      "description": "Inspect and retrieve workflow execution history."
    },
    {
      "name": "Agents",
      "description": "Create and manage AI agent configurations."
    },
    {
      "name": "Connections",
      "description": "Manage OAuth provider connections."
    },
    {
      "name": "Webhooks",
      "description": "Subscribe to outbound webhook events."
    },
    {
      "name": "Tables",
      "description": "Read and write to persistent data tables."
    },
    {
      "name": "Secrets",
      "description": "Store and manage encrypted workflow secrets."
    }
  ],
  "paths": {
    "/blocks": {
      "get": {
        "operationId": "listBlocks",
        "summary": "Discover workflow blocks and actions",
        "description": "Start here when the integration is unknown. Returns the deployed non-hidden block catalog, including action IDs, typed inputs, field requirements and static choices. Filter kind=integrations for provider actions, then follow each result's links.self or call getBlock with its type. Requires workflows:read. Uses the standard read rate limit. No provider API calls or tenant connection data; no pagination.",
        "tags": [
          "Blocks"
        ],
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "core",
                "integrations",
                "triggers"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BlockMetadata"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests — rate limit exceeded.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/blocks/{type}": {
      "get": {
        "operationId": "getBlock",
        "summary": "Get a block action catalog and input definitions",
        "description": "Call directly when the block type is known, avoiding the full catalog. For example, quickbooks exposes quickbooks.runReport and all reportType choices, date/filter inputs and report output fields. Requires workflows:read. Unknown or hidden block types return 404. Provider permissions and region availability are checked only during execution.",
        "tags": [
          "Blocks"
        ],
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "quickbooks"
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/BlockMetadata"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests — rate limit exceeded.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows": {
      "get": {
        "operationId": "listWorkflows",
        "summary": "List workflows",
        "description": "Returns a paginated list of workflows for the authenticated workspace.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "active",
                "paused",
                "archived"
              ]
            },
            "description": "Filter by workflow status."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search by workflow name."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            },
            "description": "Number of results (1-100)."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Pagination cursor from a previous response."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Workflow"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createWorkflow",
        "summary": "Create a workflow",
        "description": "Creates a new workflow in draft status.",
        "tags": [
          "Workflows"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "trigger",
                  "steps"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Invoice Processing",
                    "description": "Workflow name (1-255 chars)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Human-readable description."
                  },
                  "trigger": {
                    "type": "object",
                    "description": "Trigger configuration."
                  },
                  "steps": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Array of workflow steps."
                  },
                  "inputSchema": {
                    "type": "object",
                    "description": "JSON Schema for input validation."
                  },
                  "outputSchema": {
                    "type": "object",
                    "description": "JSON Schema for output."
                  },
                  "settings": {
                    "type": "object",
                    "description": "Workflow settings."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workflow created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}": {
      "get": {
        "operationId": "getWorkflow",
        "summary": "Get a workflow",
        "description": "Returns full details for a specific workflow.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workflow ID."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateWorkflow",
        "summary": "Update a workflow",
        "description": "Updates workflow metadata. Increments the version number.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteWorkflow",
        "summary": "Delete a workflow",
        "description": "Soft deletes (archives) a workflow. Active workflows must be paused first.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/canvas": {
      "patch": {
        "operationId": "saveCanvas",
        "summary": "Save canvas",
        "description": "Saves the workflow canvas (steps and layout). Creates a new draft version.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "canvasState"
                ],
                "properties": {
                  "canvasState": {
                    "type": "object",
                    "description": "Canvas blocks, edges, Loop/Parallel membership, and optional viewport."
                  },
                  "steps": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Compiled steps; omission leaves saved steps unchanged."
                  },
                  "triggerConfig": {
                    "type": "object",
                    "description": "Replacement trigger configuration; omission leaves it unchanged."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Canvas saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict — resource already exists or state mismatch.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/activate": {
      "post": {
        "operationId": "activateWorkflow",
        "summary": "Activate a workflow",
        "description": "Transitions a workflow from draft or paused to active.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/pause": {
      "post": {
        "operationId": "pauseWorkflow",
        "summary": "Pause a workflow",
        "description": "Transitions an active workflow to paused. In-flight runs are not cancelled.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/run": {
      "post": {
        "operationId": "triggerWorkflowRun",
        "summary": "Trigger a workflow run",
        "description": "Manually triggers a workflow run. Returns 200 when the run completes synchronously, or 202 when it is queued.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "input": {
                    "type": "object",
                    "description": "Input data for the workflow."
                  },
                  "idempotencyKey": {
                    "type": "string",
                    "description": "Prevent duplicate runs (24h TTL)."
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "async",
                      "sync"
                    ],
                    "default": "async",
                    "description": "`async` (default) or `sync`."
                  },
                  "maxExecutionTimeMs": {
                    "type": "number",
                    "minimum": 1000,
                    "maximum": 300000,
                    "default": 30000,
                    "description": "Max wait time for sync mode (1000-300000ms)."
                  },
                  "onTimeout": {
                    "type": "string",
                    "enum": [
                      "return_run_id",
                      "throw_error"
                    ],
                    "default": "return_run_id",
                    "description": "Sync timeout behavior."
                  },
                  "onFailure": {
                    "type": "string",
                    "enum": [
                      "throw_error",
                      "switch_to_async"
                    ],
                    "default": "throw_error",
                    "description": "Sync failure behavior."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Run completed synchronously or idempotency key matched",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/WorkflowRunSyncResult"
                        },
                        {
                          "$ref": "#/components/schemas/WorkflowRunIdempotencyResult"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Run queued asynchronously",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/WorkflowRunAsyncResult"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "408": {
            "description": "Request timeout — sync execution exceeded maxExecutionTimeMs.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/runs": {
      "get": {
        "operationId": "listWorkflowRuns",
        "summary": "List workflow runs",
        "description": "Returns a paginated list of runs for a specific workflow.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Run"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/clone": {
      "post": {
        "operationId": "cloneWorkflow",
        "summary": "Clone a workflow",
        "description": "Creates a copy of a workflow in draft status.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Name for the cloned workflow."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workflow cloned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/versions": {
      "get": {
        "operationId": "listWorkflowVersions",
        "summary": "List workflow versions",
        "description": "Returns all versions of a workflow.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Versions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/versions/compare": {
      "get": {
        "operationId": "compareWorkflowVersions",
        "summary": "Compare workflow versions",
        "description": "Compare two versions of a workflow and return the differences.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Source version number."
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Target version number."
          }
        ],
        "responses": {
          "200": {
            "description": "Version comparison",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/versions/{version}": {
      "get": {
        "operationId": "getWorkflowVersion",
        "summary": "Get a specific version",
        "description": "Returns canvas and metadata for a specific workflow version.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/versions/{version}/rollback": {
      "post": {
        "operationId": "rollbackWorkflowVersion",
        "summary": "Rollback to a version",
        "description": "Rolls the workflow back to a previous version, creating a new version from it.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Workflow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/schedule": {
      "get": {
        "operationId": "getWorkflowSchedule",
        "summary": "Get schedule",
        "description": "Returns the current schedule configuration for a workflow.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Schedule",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateWorkflowSchedule",
        "summary": "Update schedule",
        "description": "Sets or updates the cron schedule for a workflow.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "cron": {
                    "type": "string",
                    "example": "0 9 * * 1-5",
                    "description": "Cron expression."
                  },
                  "interval": {
                    "type": "object",
                    "description": "Interval configuration.",
                    "required": [
                      "value",
                      "unit"
                    ],
                    "properties": {
                      "value": {
                        "type": "number",
                        "description": "Interval value."
                      },
                      "unit": {
                        "type": "string",
                        "enum": [
                          "minutes",
                          "hours",
                          "days",
                          "weeks"
                        ],
                        "description": "Interval unit."
                      }
                    }
                  },
                  "timezone": {
                    "type": "string",
                    "example": "America/New_York",
                    "description": "IANA timezone."
                  },
                  "enabled": {
                    "type": "boolean",
                    "description": "Enable/disable schedule."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{id}/schedule/trigger": {
      "post": {
        "operationId": "triggerScheduledRun",
        "summary": "Trigger scheduled run",
        "description": "Manually fires a scheduled workflow run immediately.",
        "tags": [
          "Workflows"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Triggered",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Run"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs": {
      "get": {
        "operationId": "listRuns",
        "summary": "List runs",
        "description": "Returns a paginated list of workflow runs across all workflows.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "workflowId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by workflow ID."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by run status."
          },
          {
            "name": "triggerType",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by trigger type."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter runs started after this time."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Filter runs started before this time."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search by run ID prefix."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Run"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs/{id}": {
      "get": {
        "operationId": "getRun",
        "summary": "Get a run",
        "description": "Returns details of a specific workflow run. Syncs status from the execution engine if the run is in progress.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Run UUID."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Run"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs/{id}/logs": {
      "get": {
        "operationId": "getRunLogs",
        "summary": "Get run logs",
        "description": "Returns step-by-step execution logs for a workflow run.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Run logs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "runId": {
                          "type": "string"
                        },
                        "logs": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "status": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs/{id}/cancel": {
      "post": {
        "operationId": "cancelRun",
        "summary": "Cancel a run",
        "description": "Cancels a running or pending workflow run.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Run cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "cancelled": {
                          "type": "boolean"
                        },
                        "triggerDevCancelled": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Bad gateway — upstream service error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs/{id}/restart": {
      "post": {
        "operationId": "restartRun",
        "summary": "Restart a run",
        "description": "Restarts a failed or completed run from a specific step.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "fromStepId"
                ],
                "properties": {
                  "fromStepId": {
                    "type": "string",
                    "description": "Step ID to restart from (inclusive)."
                  },
                  "overrideInput": {
                    "type": "object",
                    "description": "Override workflow input fields."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Run restarted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "originalRunId": {
                          "type": "string"
                        },
                        "newRunId": {
                          "type": "string"
                        },
                        "workflowId": {
                          "type": "string"
                        },
                        "restartFromStepId": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "createdAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "warning": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/runs/{id}/retry": {
      "post": {
        "operationId": "retryRun",
        "summary": "Retry a failed run",
        "description": "Retries a failed workflow run from the first failed step.",
        "tags": [
          "Runs"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "202": {
            "description": "Run retried",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "originalRunId": {
                          "type": "string"
                        },
                        "newRunId": {
                          "type": "string"
                        },
                        "workflowId": {
                          "type": "string"
                        },
                        "restartFromStepId": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "createdAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "warning": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agents": {
      "get": {
        "operationId": "listAgents",
        "summary": "List agents",
        "description": "Returns all agents including core agents and company-owned custom agents.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by agent type."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Agent"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createAgent",
        "summary": "Create an agent",
        "description": "Creates a new custom agent.",
        "tags": [
          "Agents"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "type",
                  "systemPrompt"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Agent display name."
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "extraction",
                      "content",
                      "transform",
                      "decision",
                      "code",
                      "classification",
                      "custom"
                    ]
                  },
                  "systemPrompt": {
                    "type": "string",
                    "description": "System prompt defining agent behavior."
                  },
                  "provider": {
                    "type": "string",
                    "enum": [
                      "openai",
                      "anthropic"
                    ],
                    "default": "openai",
                    "description": "AI provider (default: openai)."
                  },
                  "model": {
                    "type": "string",
                    "default": "gpt-5.6-sol",
                    "description": "Model ID (defaults to gpt-5.6-sol)."
                  },
                  "outputSchema": {
                    "type": "object",
                    "description": "JSON Schema for structured output."
                  },
                  "temperature": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2,
                    "default": 0.7,
                    "description": "Temperature (0.0-2.0), defaults to 0.7."
                  },
                  "maxTokens": {
                    "type": "integer",
                    "default": 4096,
                    "description": "Max tokens in response, defaults to 4096."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Agent created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Agent"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{id}": {
      "get": {
        "operationId": "getAgent",
        "summary": "Get an agent",
        "description": "Returns details for a specific agent, including core agents.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Agent ID or core agent ID (e.g. agent_extraction)."
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Agent"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateAgent",
        "summary": "Update an agent",
        "description": "Updates a custom agent. Only company-owned agents can be updated.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "systemPrompt": {
                    "type": "string"
                  },
                  "temperature": {
                    "type": "number"
                  },
                  "maxTokens": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Agent"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAgent",
        "summary": "Delete an agent",
        "description": "Soft-deletes a custom agent. Core agents cannot be deleted.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{id}/test": {
      "post": {
        "operationId": "testAgent",
        "summary": "Test an agent",
        "description": "Runs an agent with sample input to verify configuration and output.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input"
                ],
                "properties": {
                  "input": {
                    "type": "object"
                  },
                  "userMessage": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{id}/execute": {
      "post": {
        "operationId": "executeAgent",
        "summary": "Execute an agent",
        "description": "Executes an agent standalone, outside of a workflow context.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "input"
                ],
                "properties": {
                  "input": {
                    "type": "object"
                  },
                  "userMessage": {
                    "type": "string"
                  },
                  "workflowRunId": {
                    "type": "string"
                  },
                  "overrides": {
                    "type": "object",
                    "properties": {
                      "temperature": {
                        "type": "number"
                      },
                      "maxTokens": {
                        "type": "integer"
                      },
                      "model": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Execution result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/agents/{id}/executions": {
      "get": {
        "operationId": "listAgentExecutions",
        "summary": "List agent executions",
        "description": "Returns execution history for an agent.",
        "tags": [
          "Agents"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AgentExecution"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections": {
      "get": {
        "operationId": "listConnections",
        "summary": "List connections",
        "description": "Returns all OAuth connections for the workspace.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "provider",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by provider (e.g. stripe, hubspot)."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by connection status."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Connection"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createConnection",
        "summary": "Create a connection",
        "description": "Initiates a new OAuth connection for a provider.",
        "tags": [
          "Connections"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "provider"
                ],
                "properties": {
                  "provider": {
                    "type": "string",
                    "description": "Provider integration ID."
                  },
                  "name": {
                    "type": "string",
                    "description": "Display name for the connection."
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Additional metadata."
                  },
                  "connectionConfig": {
                    "type": "object",
                    "description": "Provider-specific config."
                  },
                  "isDefault": {
                    "type": "boolean",
                    "description": "Set as default for the provider."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection initiated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "provider": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "isDefault": {
                          "type": "boolean"
                        },
                        "authUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{provider}/auth-url": {
      "get": {
        "operationId": "getConnectionAuthUrl",
        "summary": "Get OAuth auth URL",
        "description": "Generates an OAuth authorization URL for a provider. Creates a pending connection.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "stripe",
                "salesforce",
                "hubspot",
                "quickbooks",
                "pandadoc",
                "netsuite",
                "slack",
                "gmail"
              ]
            }
          },
          {
            "name": "redirectUrl",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uri"
            }
          },
          {
            "name": "connectionName",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Auth URL",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "connectionId": {
                          "type": "string"
                        },
                        "provider": {
                          "type": "string"
                        },
                        "authUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "isDefault": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{id}": {
      "get": {
        "operationId": "getConnection",
        "summary": "Get a connection",
        "description": "Returns details for a specific connection.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Connection"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateConnection",
        "summary": "Update a connection",
        "description": "Updates connection display name and/or metadata (partial merge).",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "New display name."
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Metadata to merge."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Connection"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteConnection",
        "summary": "Delete a connection",
        "description": "Revokes and deletes a connection.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        },
                        "promotedDefaultConnectionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "promotedDefaultConnectionName": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Bad gateway — upstream service error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{id}/set-default": {
      "post": {
        "operationId": "setConnectionDefault",
        "summary": "Set connection as default",
        "description": "Sets a connection as the default for its provider.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Set as default",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "provider": {
                          "type": "string"
                        },
                        "isDefault": {
                          "type": "boolean"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{id}/refresh": {
      "post": {
        "operationId": "refreshConnection",
        "summary": "Refresh a connection",
        "description": "Manually refreshes connection credentials.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Refreshed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "lastSyncedAt": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "message": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{id}/verify": {
      "post": {
        "operationId": "verifyConnection",
        "summary": "Verify a connection",
        "description": "Verifies connection health by testing credentials.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Verification result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "healthy": {
                          "type": "boolean"
                        },
                        "connectionId": {
                          "type": "string"
                        },
                        "provider": {
                          "type": "string"
                        },
                        "status": {
                          "type": "string"
                        },
                        "externalAccountId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "checkedAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/connections/{provider}/api-key": {
      "post": {
        "operationId": "createApiKeyConnection",
        "summary": "Create API key connection",
        "description": "Creates or updates a connection using API key authentication.",
        "tags": [
          "Connections"
        ],
        "parameters": [
          {
            "name": "provider",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "rillet",
                "resend",
                "airwallex",
                "odoo"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "apiKey"
                ],
                "properties": {
                  "apiKey": {
                    "type": "string",
                    "description": "The API key."
                  },
                  "clientId": {
                    "type": "string",
                    "description": "Client ID (Airwallex only)."
                  },
                  "externalAccountId": {
                    "type": "string",
                    "description": "Account ID (Airwallex only)."
                  },
                  "domain": {
                    "type": "string",
                    "description": "Instance domain (Odoo only)."
                  },
                  "connectionId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Update existing connection."
                  },
                  "name": {
                    "type": "string",
                    "description": "Display name."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Connection updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Connection"
                    }
                  }
                }
              }
            }
          },
          "201": {
            "description": "Connection created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Connection"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints": {
      "get": {
        "operationId": "listWebhookEndpoints",
        "summary": "List outbound webhook endpoints",
        "description": "Returns all outbound webhook endpoint subscriptions.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "paused",
                "disabled"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookEndpoint"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createWebhookEndpoint",
        "summary": "Create a webhook endpoint",
        "description": "Subscribes a URL to receive outbound webhook events.",
        "tags": [
          "Webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "url"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Human-readable name."
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "HTTPS URL to deliver events to."
                  },
                  "events": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    },
                    "description": "Event types to receive (omit or null = all)."
                  },
                  "workflowIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    },
                    "description": "Restrict to specific workflows (omit or null = all)."
                  },
                  "headers": {
                    "type": "object",
                    "description": "Additional headers to include on each delivery."
                  },
                  "description": {
                    "type": "string",
                    "description": "Free-form description."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Endpoint created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/WebhookEndpoint"
                        },
                        {
                          "properties": {
                            "secret": {
                              "type": "string",
                              "description": "HMAC-SHA256 signing secret (only returned on creation)."
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}": {
      "get": {
        "operationId": "getWebhookEndpoint",
        "summary": "Get a webhook endpoint",
        "description": "Returns details for a specific outbound webhook endpoint.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "updateWebhookEndpoint",
        "summary": "Update a webhook endpoint",
        "description": "Updates webhook endpoint configuration. Fields set to null clear the value.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "events": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    },
                    "description": "Event types (null clears to all events)."
                  },
                  "workflowIds": {
                    "type": [
                      "array",
                      "null"
                    ],
                    "items": {
                      "type": "string"
                    },
                    "description": "Workflow IDs (null clears to all workflows)."
                  },
                  "headers": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "Custom headers (null clears)."
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "active",
                      "paused"
                    ]
                  },
                  "description": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Description (null clears)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/WebhookEndpoint"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteWebhookEndpoint",
        "summary": "Delete a webhook endpoint",
        "description": "Removes a webhook endpoint subscription.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}/rotate-secret": {
      "post": {
        "operationId": "rotateWebhookSecret",
        "summary": "Rotate webhook secret",
        "description": "Generates a new signing secret for the webhook endpoint.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Secret rotated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "secret": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}/test": {
      "post": {
        "operationId": "testWebhookEndpoint",
        "summary": "Test a webhook endpoint",
        "description": "Sends a test webhook to verify the endpoint.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "eventType": {
                    "type": "string",
                    "enum": [
                      "workflow.started",
                      "workflow.completed",
                      "workflow.failed",
                      "workflow.timeout",
                      "workflow.checkpoint",
                      "workflow.cancelled"
                    ],
                    "default": "workflow.completed",
                    "description": "Event type to simulate."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Test result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean"
                        },
                        "httpStatus": {
                          "type": [
                            "number",
                            "null"
                          ]
                        },
                        "responseBody": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "eventId": {
                          "type": "string"
                        },
                        "error": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}/deliveries": {
      "get": {
        "operationId": "listWebhookDeliveries",
        "summary": "List webhook deliveries",
        "description": "Returns delivery history for a webhook endpoint.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "delivered",
                "failed",
                "retrying"
              ]
            }
          },
          {
            "name": "eventType",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "runId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 20,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/WebhookDelivery"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}/deliveries/{deliveryId}": {
      "get": {
        "operationId": "getWebhookDelivery",
        "summary": "Get a webhook delivery",
        "description": "Returns details for a specific delivery including payload.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "deliveryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delivery details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/WebhookDelivery"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "payload": {
                              "type": "object"
                            },
                            "responseBody": {
                              "type": [
                                "string",
                                "null"
                              ]
                            },
                            "responseHeaders": {
                              "type": [
                                "object",
                                "null"
                              ]
                            },
                            "nextRetryAt": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "format": "date-time"
                            },
                            "durationMs": {
                              "type": [
                                "number",
                                "null"
                              ]
                            },
                            "updatedAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhook-endpoints/{id}/deliveries/{deliveryId}/retry": {
      "post": {
        "operationId": "retryWebhookDelivery",
        "summary": "Retry a webhook delivery",
        "description": "Manually retries a failed delivery.",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "deliveryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Retry queued",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "queued": {
                          "type": "boolean"
                        },
                        "deliveryId": {
                          "type": "string"
                        },
                        "taskId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables": {
      "get": {
        "operationId": "listTables",
        "summary": "List data tables",
        "description": "Returns all data tables in the workspace.",
        "tags": [
          "Tables"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DataTable"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createTable",
        "summary": "Create a data table",
        "description": "Creates a new data table. Idempotent by name within a workspace.",
        "tags": [
          "Tables"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Display name (1-255 chars)."
                  },
                  "description": {
                    "type": "string",
                    "description": "Free-form description."
                  },
                  "columns": {
                    "type": "array",
                    "description": "Column definitions.",
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "type"
                      ],
                      "properties": {
                        "name": {
                          "type": "string"
                        },
                        "type": {
                          "type": "string",
                          "enum": [
                            "text",
                            "number",
                            "boolean",
                            "date",
                            "select",
                            "url",
                            "email",
                            "json"
                          ]
                        }
                      }
                    }
                  },
                  "schema": {
                    "type": "object",
                    "description": "Free-form schema metadata."
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Free-form metadata."
                  },
                  "maxRows": {
                    "type": "number",
                    "default": 10000,
                    "description": "Row cap (1-100,000, default 10,000)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Table created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/DataTable"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/import": {
      "post": {
        "operationId": "importTable",
        "summary": "Import a data table",
        "description": "Creates a new data table with rows in a single operation.",
        "tags": [
          "Tables"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "columns",
                  "rows"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Display name."
                  },
                  "description": {
                    "type": "string"
                  },
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": [
                        "name",
                        "type"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "type": {
                          "type": "string"
                        }
                      }
                    }
                  },
                  "rows": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    },
                    "description": "Row data objects."
                  },
                  "schema": {
                    "type": "object"
                  },
                  "metadata": {
                    "type": "object"
                  },
                  "maxRows": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Table imported",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/DataTable"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}": {
      "get": {
        "operationId": "getTable",
        "summary": "Get a data table",
        "description": "Returns schema and metadata for a specific data table.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/DataTable"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "updateTable",
        "summary": "Update a data table",
        "description": "Updates table metadata, columns, or settings.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "schema": {
                    "type": "object"
                  },
                  "metadata": {
                    "type": "object"
                  },
                  "maxRows": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/DataTable"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteTable",
        "summary": "Delete a data table",
        "description": "Deletes a data table and all its rows.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}/rows": {
      "get": {
        "operationId": "listTableRows",
        "summary": "List table rows",
        "description": "Returns rows from a data table. Maximum 100 rows per page.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 100
            },
            "description": "1-100 rows per page."
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Zero-based offset."
          },
          {
            "name": "filter",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "URL-encoded JSON filter object."
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Column ID to sort by."
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "asc"
            },
            "description": "Sort direction."
          }
        ],
        "responses": {
          "200": {
            "description": "Rows",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TableRow"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createTableRow",
        "summary": "Create a table row",
        "description": "Creates a single row in a data table.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "data"
                ],
                "properties": {
                  "data": {
                    "type": "object",
                    "description": "Row payload. Keys beyond declared columns are preserved."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Row created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/TableRow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}/rows/query": {
      "post": {
        "operationId": "queryTableRows",
        "summary": "Query table rows",
        "description": "Body-based query for structured filters that should not appear in URLs.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "limit": {
                    "type": "integer",
                    "default": 50,
                    "maximum": 100
                  },
                  "offset": {
                    "type": "integer",
                    "default": 0
                  },
                  "filter": {
                    "type": "object",
                    "description": "Structured filter object."
                  },
                  "sort": {
                    "type": "string"
                  },
                  "order": {
                    "type": "string",
                    "enum": [
                      "asc",
                      "desc"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rows",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TableRow"
                      }
                    },
                    "meta": {
                      "$ref": "#/components/schemas/Meta"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}/rows/{rowId}": {
      "patch": {
        "operationId": "updateTableRow",
        "summary": "Update a table row",
        "description": "Updates a row in a data table.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "rowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "data"
                ],
                "properties": {
                  "data": {
                    "type": "object",
                    "description": "Row data to update."
                  },
                  "merge": {
                    "type": "boolean",
                    "default": false,
                    "description": "Merge with existing data."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Row updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/TableRow"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteTableRow",
        "summary": "Delete a table row",
        "description": "Deletes a row from a data table.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "rowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}/columns/{columnId}/values": {
      "get": {
        "operationId": "listColumnValues",
        "summary": "List column values",
        "description": "Returns distinct values for a column across the table.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "columnId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filter",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "URL-encoded JSON filter."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Search within values."
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100,
              "maximum": 500
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Distinct values",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "values": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "value": {},
                              "label": {
                                "type": "string"
                              },
                              "count": {
                                "type": "number"
                              }
                            }
                          }
                        },
                        "truncated": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tables/{id}/columns/{columnId}/values/query": {
      "post": {
        "operationId": "queryColumnValues",
        "summary": "Query column values",
        "description": "Body-based query for column distinct values.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "columnId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filter": {
                    "type": "object"
                  },
                  "search": {
                    "type": "string"
                  },
                  "limit": {
                    "type": "integer",
                    "default": 100,
                    "maximum": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Distinct values",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "values": {
                          "type": "array",
                          "items": {
                            "type": "object"
                          }
                        },
                        "truncated": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/table-folders": {
      "get": {
        "operationId": "listTableFolders",
        "summary": "List table folders",
        "description": "Returns all table folders and their table assignments.",
        "tags": [
          "Tables"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TableFolder"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createTableFolder",
        "summary": "Create a table folder",
        "description": "Creates a new folder for organizing data tables.",
        "tags": [
          "Tables"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Folder name (1-255 chars)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Folder created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/TableFolder"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict — resource already exists or state mismatch.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/table-folders/tables/{tableId}": {
      "patch": {
        "operationId": "moveTableToFolder",
        "summary": "Move table to folder",
        "description": "Moves a table into a folder, or to the root if folderId is null.",
        "tags": [
          "Tables"
        ],
        "parameters": [
          {
            "name": "tableId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "folderId"
                ],
                "properties": {
                  "folderId": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uuid",
                    "description": "Target folder ID, or null for root."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Table moved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "tableId": {
                          "type": "string"
                        },
                        "folderId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{workflowId}/secrets": {
      "get": {
        "operationId": "listWorkflowSecrets",
        "summary": "List workflow secrets",
        "description": "Returns secret names (not values) for a workflow.",
        "tags": [
          "Secrets"
        ],
        "parameters": [
          {
            "name": "workflowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Secret"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createWorkflowSecret",
        "summary": "Create a workflow secret",
        "description": "Stores a new secret for a workflow. Values are encrypted at rest.",
        "tags": [
          "Secrets"
        ],
        "parameters": [
          {
            "name": "workflowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "key",
                  "value"
                ],
                "properties": {
                  "key": {
                    "type": "string",
                    "example": "SIGNING_KEY",
                    "description": "Upper snake case, starts with a letter, max 64 characters."
                  },
                  "value": {
                    "type": "string",
                    "description": "Secret value, 1-8192 characters."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Secret created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Secret"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict — resource already exists or state mismatch.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/workflows/{workflowId}/secrets/{key}": {
      "put": {
        "operationId": "rotateWorkflowSecret",
        "summary": "Rotate a workflow secret",
        "description": "Updates (rotates) the value of an existing secret without revealing the previous one.",
        "tags": [
          "Secrets"
        ],
        "parameters": [
          {
            "name": "workflowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Secret key."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "value"
                ],
                "properties": {
                  "value": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Secret"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — invalid parameters or request body.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteWorkflowSecret",
        "summary": "Delete a workflow secret",
        "description": "Permanently deletes a workflow secret.",
        "tags": [
          "Secrets"
        ],
        "parameters": [
          {
            "name": "workflowId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Secret key."
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden — insufficient permissions for this resource.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Resource not found.",
            "headers": {
              "Link": {
                "$ref": "#/components/headers/ApiDiscovery"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "headers": {
      "ApiDiscovery": {
        "description": "RFC 8288 links to the public OpenAPI spec (service-desc), API catalog (api-catalog), and general API reference (service-doc). Available before authentication.",
        "schema": {
          "type": "string"
        },
        "example": "<https://loopfour.ai/openapi.json>; rel=\"service-desc\"; type=\"application/json\""
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "API key issued from your Loopfour workspace settings."
      }
    },
    "schemas": {
      "BlockFieldCondition": {
        "type": "object",
        "required": [
          "field",
          "value"
        ],
        "properties": {
          "field": {
            "type": "string"
          },
          "value": {
            "description": "Match a scalar, or any member of an array. Negate with not; combine with and.",
            "oneOf": [
              {
                "type": [
                  "string",
                  "number",
                  "boolean",
                  "null"
                ]
              },
              {
                "type": "array",
                "items": {
                  "type": [
                    "string",
                    "number",
                    "boolean",
                    "null"
                  ]
                }
              }
            ]
          },
          "not": {
            "type": "boolean"
          },
          "and": {
            "$ref": "#/components/schemas/BlockFieldCondition"
          }
        }
      },
      "BlockMetadata": {
        "type": "object",
        "required": [
          "type",
          "name",
          "description",
          "kind",
          "connectionRequired",
          "actions",
          "inputs",
          "outputs",
          "subBlocks",
          "links"
        ],
        "properties": {
          "type": {
            "type": "string",
            "example": "quickbooks"
          },
          "name": {
            "type": "string",
            "example": "QuickBooks"
          },
          "description": {
            "type": "string"
          },
          "kind": {
            "type": "string",
            "enum": [
              "core",
              "integrations",
              "triggers"
            ]
          },
          "category": {
            "type": "string"
          },
          "connectionRequired": {
            "type": "boolean"
          },
          "links": {
            "type": "object",
            "required": [
              "self",
              "collection"
            ],
            "properties": {
              "self": {
                "type": "string",
                "format": "uri-reference",
                "example": "/api/v1/blocks/quickbooks"
              },
              "collection": {
                "type": "string",
                "format": "uri-reference",
                "example": "/api/v1/blocks"
              }
            },
            "description": "Resolve against the API origin. Follow self for block details and collection to return to the catalog."
          },
          "actions": {
            "type": "array",
            "description": "Action IDs declared by this block. Discover the deployed catalog at runtime.",
            "items": {
              "type": "string"
            },
            "example": [
              "quickbooks.runReport",
              "quickbooks.getInvoice"
            ]
          },
          "inputs": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "key",
                "type"
              ],
              "properties": {
                "key": {
                  "type": "string",
                  "example": "reportType"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "string",
                    "number",
                    "boolean",
                    "json",
                    "array",
                    "file"
                  ]
                },
                "description": {
                  "type": "string"
                },
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "description": "Nested input schema, when declared by the block."
                }
              }
            }
          },
          "outputs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "Header",
              "Columns",
              "Rows"
            ]
          },
          "subBlocks": {
            "type": "array",
            "description": "Field definitions. Join id to inputs.key for types and nested schemas. A required field applies only when visibleWhen matches.",
            "items": {
              "type": "object",
              "required": [
                "id",
                "type"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "example": "reportType"
                },
                "title": {
                  "type": "string",
                  "example": "Report"
                },
                "type": {
                  "type": "string",
                  "example": "combobox",
                  "description": "Authoring control type; the value type is in inputs."
                },
                "required": {
                  "type": "boolean"
                },
                "requiredWhen": {
                  "$ref": "#/components/schemas/BlockFieldCondition"
                },
                "visibleWhen": {
                  "$ref": "#/components/schemas/BlockFieldCondition"
                },
                "options": {
                  "type": "array",
                  "description": "Static choices, including all QuickBooks report names. Connection-dependent choices are not resolved.",
                  "items": {
                    "type": "object",
                    "required": [
                      "id",
                      "label"
                    ],
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "label": {
                        "type": "string"
                      }
                    }
                  },
                  "example": [
                    {
                      "id": "ProfitAndLoss",
                      "label": "Profit And Loss"
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "const": false
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "example": "NOT_FOUND"
              },
              "message": {
                "type": "string",
                "example": "Workflow not found."
              }
            }
          }
        }
      },
      "Workflow": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "wf_abc123"
          },
          "name": {
            "type": "string",
            "example": "Invoice Processing"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "draft",
              "active",
              "paused",
              "archived"
            ]
          },
          "trigger": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "provider": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "events": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "version": {
            "type": "number",
            "example": 3
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Run": {
        "type": "object",
        "description": "Full run details returned by GET /runs/{id}",
        "properties": {
          "id": {
            "type": "string",
            "example": "run_550e8400-e29b-41d4-a716-446655440000"
          },
          "workflowId": {
            "type": "string",
            "example": "wf_abc123"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "waiting_approval",
              "completed",
              "failed",
              "suspended",
              "cancelled"
            ]
          },
          "triggerType": {
            "type": "string",
            "example": "webhook"
          },
          "input": {
            "type": [
              "object",
              "null"
            ]
          },
          "output": {
            "type": [
              "object",
              "null"
            ]
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "durationMs": {
            "type": [
              "number",
              "null"
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkflowRunAsyncResult": {
        "type": "object",
        "description": "Response when workflow is queued asynchronously (202)",
        "required": [
          "run_id",
          "status",
          "workflow_id",
          "mode"
        ],
        "properties": {
          "run_id": {
            "type": "string",
            "example": "run_550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "example": "pending"
          },
          "workflow_id": {
            "type": "string",
            "example": "wf_abc123"
          },
          "mode": {
            "type": "string",
            "enum": [
              "async"
            ]
          },
          "timed_out": {
            "type": "boolean",
            "description": "Present when sync mode timed out and fell back to async"
          },
          "switched_to_async": {
            "type": "boolean",
            "description": "Present when failure caused switch to async mode"
          },
          "message": {
            "type": "string",
            "description": "Additional context message"
          },
          "error": {
            "type": "object",
            "description": "Error details if run failed before switching to async"
          }
        }
      },
      "WorkflowRunSyncResult": {
        "type": "object",
        "description": "Response when workflow completes synchronously (200)",
        "required": [
          "run_id",
          "status",
          "workflow_id",
          "mode",
          "output",
          "duration_ms"
        ],
        "properties": {
          "run_id": {
            "type": "string",
            "example": "run_550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "example": "completed"
          },
          "workflow_id": {
            "type": "string",
            "example": "wf_abc123"
          },
          "mode": {
            "type": "string",
            "enum": [
              "sync"
            ]
          },
          "output": {
            "type": "object",
            "description": "Workflow output data"
          },
          "duration_ms": {
            "type": "number",
            "description": "Execution duration in milliseconds"
          }
        }
      },
      "WorkflowRunIdempotencyResult": {
        "type": "object",
        "description": "Response when idempotency key matched an existing run (200)",
        "required": [
          "run_id",
          "status",
          "workflow_id",
          "message"
        ],
        "properties": {
          "run_id": {
            "type": "string",
            "example": "run_550e8400-e29b-41d4-a716-446655440000"
          },
          "status": {
            "type": "string",
            "example": "completed"
          },
          "workflow_id": {
            "type": "string",
            "example": "wf_abc123"
          },
          "message": {
            "type": "string",
            "example": "Existing run returned (idempotency key matched)"
          }
        }
      },
      "Agent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "agent_abc123"
          },
          "name": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "extraction",
              "content",
              "transform",
              "decision",
              "code",
              "classification",
              "custom"
            ]
          },
          "provider": {
            "type": "string",
            "enum": [
              "openai",
              "anthropic"
            ]
          },
          "model": {
            "type": "string",
            "example": "claude-opus-5"
          },
          "version": {
            "type": "number"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AgentExecution": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "agentId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "completed",
              "failed"
            ]
          },
          "input": {
            "type": [
              "object",
              "null"
            ]
          },
          "output": {
            "type": [
              "object",
              "null"
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ]
          },
          "promptTokens": {
            "type": [
              "number",
              "null"
            ]
          },
          "completionTokens": {
            "type": [
              "number",
              "null"
            ]
          },
          "totalTokens": {
            "type": [
              "number",
              "null"
            ]
          },
          "estimatedCost": {
            "type": [
              "number",
              "null"
            ]
          },
          "latencyMs": {
            "type": [
              "number",
              "null"
            ]
          },
          "model": {
            "type": [
              "string",
              "null"
            ]
          },
          "provider": {
            "type": [
              "string",
              "null"
            ]
          },
          "workflowRunId": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Connection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "conn_550e8400-e29b-41d4-a716-446655440000"
          },
          "provider": {
            "type": "string",
            "example": "stripe"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "error",
              "disconnected",
              "pending",
              "expired"
            ]
          },
          "externalAccountId": {
            "type": [
              "string",
              "null"
            ]
          },
          "isDefault": {
            "type": "boolean"
          },
          "authVariant": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastSyncedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookEndpoint": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "workflowIds": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "headers": {
            "type": [
              "object",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused",
              "disabled"
            ]
          },
          "lastDeliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "consecutiveFailures": {
            "type": "number"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WebhookDelivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "eventType": {
            "type": "string"
          },
          "eventId": {
            "type": "string"
          },
          "runId": {
            "type": [
              "string",
              "null"
            ]
          },
          "workflowId": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "delivered",
              "failed",
              "retrying"
            ]
          },
          "httpStatus": {
            "type": [
              "number",
              "null"
            ]
          },
          "attemptCount": {
            "type": "number"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          },
          "deliveredAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DataTable": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "text",
                    "number",
                    "boolean",
                    "date",
                    "select",
                    "url",
                    "email",
                    "json"
                  ]
                }
              }
            }
          },
          "schema": {
            "type": [
              "object",
              "null"
            ]
          },
          "metadata": {
            "type": [
              "object",
              "null"
            ]
          },
          "maxRows": {
            "type": "number"
          },
          "rowCount": {
            "type": "number"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TableRow": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "data": {
            "type": "object"
          },
          "position": {
            "type": [
              "number",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TableFolder": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "tableIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Secret": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "workflowId": {
            "type": "string"
          },
          "key": {
            "type": "string",
            "example": "SIGNING_KEY"
          },
          "maskedValue": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastUsedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Meta": {
        "type": "object",
        "description": "Pagination metadata returned by list endpoints",
        "properties": {
          "cursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "hasMore": {
            "type": "boolean"
          },
          "total": {
            "type": [
              "number",
              "null"
            ]
          },
          "limit": {
            "type": [
              "number",
              "null"
            ]
          },
          "offset": {
            "type": [
              "number",
              "null"
            ]
          }
        }
      }
    }
  }
}