{
  "openapi": "3.1.0",
  "info": {
    "title": "Leadveyor API",
    "version": "1.0.0"
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key (`lv_live_…` / `lv_test_…`) or console session token (`lvs_…`). Account-wide keys select a workspace with the `Leadveyor-Workspace` header; users in several accounts select one with `Leadveyor-Account`."
      }
    },
    "schemas": {
      "ProfileDocument": {
        "type": "object",
        "properties": {
          "schemaVersion": {
            "type": "string",
            "enum": [
              "2026-10"
            ],
            "default": "2026-10"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "brief": {
            "type": "string",
            "maxLength": 4000,
            "default": ""
          },
          "extract": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ExtractField"
            },
            "maxItems": 30,
            "default": []
          },
          "dimensions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9_]{0,63}$"
                },
                "label": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                }
              },
              "required": [
                "id",
                "label"
              ]
            },
            "maxItems": 10,
            "default": [],
            "description": "Qualification dimensions (e.g. who / what / when / where / why, or BANT) for the score breakdown"
          },
          "criteria": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Criterion"
            },
            "maxItems": 30,
            "default": []
          },
          "scoring": {
            "type": "object",
            "properties": {
              "method": {
                "type": "string",
                "enum": [
                  "points",
                  "sum",
                  "average"
                ],
                "default": "sum",
                "description": "points: the score is the sum of the chosen levels' points (0–100); sum: criterion points scaled to 0–100; average: average grade scaled to 0–100"
              },
              "maxGrade": {
                "type": "integer",
                "minimum": 2,
                "maximum": 10,
                "default": 5
              }
            },
            "default": {
              "method": "sum",
              "maxGrade": 5
            }
          },
          "tiers": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tier"
            },
            "minItems": 2,
            "maxItems": 6,
            "default": [
              {
                "name": "hot",
                "minScore": 70
              },
              {
                "name": "warm",
                "minScore": 40
              },
              {
                "name": "cold",
                "minScore": 0
              }
            ]
          },
          "junk": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean",
                "default": true
              },
              "extraRules": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 500
                },
                "maxItems": 20,
                "default": []
              },
              "blockDomains": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z0-9.-]+\\.[a-z]{2,}$/i"
                },
                "maxItems": 200,
                "default": []
              },
              "allowDomains": {
                "type": "array",
                "items": {
                  "type": "string",
                  "pattern": "^[a-z0-9.-]+\\.[a-z]{2,}$/i"
                },
                "maxItems": 200,
                "default": []
              }
            },
            "default": {
              "enabled": true,
              "extraRules": [],
              "blockDomains": [],
              "allowDomains": []
            }
          }
        },
        "required": [
          "name"
        ]
      },
      "ExtractField": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "type": {
            "type": "string",
            "enum": [
              "string",
              "text",
              "number",
              "money",
              "date",
              "datetime",
              "boolean",
              "enum",
              "multi_enum",
              "email",
              "phone",
              "url"
            ]
          },
          "description": {
            "type": "string",
            "maxLength": 500,
            "description": "Hint for the AI: what this field means"
          },
          "values": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "minItems": 1,
            "maxItems": 50,
            "description": "Allowed values for enum / multi_enum"
          },
          "range": {
            "type": "string",
            "enum": [
              "min",
              "max",
              "mid"
            ],
            "description": "number / money / date: which value to use when the customer gives a range (\"101–200\", \"next month\"). Default min. Both ends are kept; date conditions use the whole range."
          },
          "required": {
            "type": "boolean"
          }
        },
        "required": [
          "key",
          "type"
        ]
      },
      "Criterion": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "dimension": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$",
                "description": "Dimension this criterion belongs to (e.g. what / when / where / why); shown as a breakdown, doesn't change the score"
              },
              "type": {
                "type": "string",
                "enum": [
                  "rule"
                ]
              },
              "condition": {
                "$ref": "#/components/schemas/Condition"
              },
              "levels": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/CriterionLevel"
                },
                "minItems": 1,
                "maxItems": 10
              },
              "points": {
                "type": "integer",
                "minimum": -100,
                "maximum": 100
              }
            },
            "required": [
              "id",
              "label",
              "type"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "dimension": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$",
                "description": "Dimension this criterion belongs to (e.g. what / when / where / why); shown as a breakdown, doesn't change the score"
              },
              "type": {
                "type": "string",
                "enum": [
                  "ai"
                ]
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1000
              },
              "guidance": {
                "type": "string",
                "minLength": 1,
                "maxLength": 6000,
                "description": "Detailed instructions for the model when answering the question: keywords, defaults, edge cases"
              },
              "levels": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/CriterionLevel"
                },
                "minItems": 1,
                "maxItems": 10
              },
              "points": {
                "type": "integer",
                "minimum": -100,
                "maximum": 100
              }
            },
            "required": [
              "id",
              "label",
              "type",
              "question"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "dimension": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$",
                "description": "Dimension this criterion belongs to (e.g. what / when / where / why); shown as a breakdown, doesn't change the score"
              },
              "type": {
                "type": "string",
                "enum": [
                  "disqualify"
                ]
              },
              "condition": {
                "$ref": "#/components/schemas/Condition"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1000
              },
              "guidance": {
                "type": "string",
                "minLength": 1,
                "maxLength": 6000,
                "description": "Detailed instructions for the model when answering the question: keywords, defaults, edge cases"
              },
              "reason": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              }
            },
            "required": [
              "id",
              "label",
              "type",
              "reason"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$"
              },
              "label": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120
              },
              "dimension": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_]{0,63}$",
                "description": "Dimension this criterion belongs to (e.g. what / when / where / why); shown as a breakdown, doesn't change the score"
              },
              "type": {
                "type": "string",
                "enum": [
                  "escalate"
                ]
              },
              "condition": {
                "$ref": "#/components/schemas/Condition"
              },
              "question": {
                "type": "string",
                "minLength": 1,
                "maxLength": 1000
              },
              "guidance": {
                "type": "string",
                "minLength": 1,
                "maxLength": 6000,
                "description": "Detailed instructions for the model when answering the question: keywords, defaults, edge cases"
              },
              "reason": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "tier": {
                "type": "string",
                "description": "Tier to force; defaults to the highest"
              }
            },
            "required": [
              "id",
              "label",
              "type",
              "reason"
            ]
          }
        ]
      },
      "Condition": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "field": {
                "type": "string",
                "minLength": 1,
                "maxLength": 100
              },
              "op": {
                "type": "string",
                "enum": [
                  "eq",
                  "neq",
                  "gt",
                  "gte",
                  "lt",
                  "lte",
                  "in",
                  "nin",
                  "contains",
                  "exists",
                  "within"
                ]
              },
              "value": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "number"
                  },
                  {
                    "type": "boolean"
                  },
                  {
                    "type": "array",
                    "items": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        }
                      ]
                    },
                    "maxItems": 200
                  }
                ]
              }
            },
            "required": [
              "field",
              "op"
            ]
          },
          {
            "type": "object",
            "properties": {
              "all": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Condition"
                },
                "minItems": 1,
                "maxItems": 20
              }
            },
            "required": [
              "all"
            ]
          },
          {
            "type": "object",
            "properties": {
              "any": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Condition"
                },
                "minItems": 1,
                "maxItems": 20
              }
            },
            "required": [
              "any"
            ]
          },
          {
            "type": "object",
            "properties": {
              "not": {
                "$ref": "#/components/schemas/Condition"
              }
            },
            "required": [
              "not"
            ]
          }
        ]
      },
      "CriterionLevel": {
        "type": "object",
        "properties": {
          "grade": {
            "type": "integer",
            "description": "Level number the model picks (unique within the criterion); also the grade in 'average' scoring"
          },
          "points": {
            "type": "integer",
            "minimum": -100,
            "maximum": 100,
            "description": "Points this level adds; required in 'points' scoring"
          },
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1000,
            "description": "Required for ai criteria"
          },
          "condition": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Condition"
              },
              {
                "description": "Required for rule criteria"
              }
            ]
          }
        },
        "required": [
          "grade"
        ]
      },
      "Tier": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]{0,63}$"
          },
          "minScore": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          }
        },
        "required": [
          "name",
          "minScore"
        ]
      },
      "Health": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "checks": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "enum": [
                "ok",
                "error"
              ]
            }
          }
        },
        "required": [
          "status",
          "checks"
        ]
      },
      "User": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "user"
            ]
          },
          "id": {
            "type": "string",
            "example": "usr_3fK9aQ2LmZp8VxR1cT0bYw7e"
          },
          "email": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "emailVerified": {
            "type": "boolean"
          },
          "hasPassword": {
            "type": "boolean"
          },
          "googleLinked": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "email",
          "name",
          "emailVerified",
          "hasPassword",
          "googleLinked",
          "createdAt"
        ]
      },
      "Account": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "account"
            ]
          },
          "id": {
            "type": "string",
            "example": "acc_8Hc2Qe5VnLx0TzJ4uM1rWk6a"
          },
          "name": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "name",
          "createdAt"
        ]
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "workspace"
            ]
          },
          "id": {
            "type": "string",
            "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
          },
          "accountId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "businessContext": {
            "type": [
              "string",
              "null"
            ]
          },
          "location": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "address": {
                "type": "string"
              },
              "lat": {
                "type": "number"
              },
              "lng": {
                "type": "number"
              }
            },
            "required": [
              "address",
              "lat",
              "lng"
            ]
          },
          "locale": {
            "type": "object",
            "properties": {
              "language": {
                "type": "string"
              },
              "timezone": {
                "type": "string"
              },
              "currency": {
                "type": "string"
              }
            },
            "required": [
              "language",
              "timezone",
              "currency"
            ]
          },
          "businessHours": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {
              "type": [
                "object",
                "null"
              ],
              "properties": {
                "open": {
                  "type": "string"
                },
                "close": {
                  "type": "string"
                }
              },
              "required": [
                "open",
                "close"
              ]
            }
          },
          "defaultProfileId": {
            "type": [
              "string",
              "null"
            ]
          },
          "retentionDays": {
            "type": "integer"
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "accountId",
          "name",
          "businessContext",
          "location",
          "locale",
          "businessHours",
          "defaultProfileId",
          "retentionDays",
          "createdAt",
          "updatedAt"
        ]
      },
      "Session": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "session"
            ]
          },
          "token": {
            "type": "string",
            "description": "Bearer token. Shown once; send as `Authorization: Bearer <token>`."
          },
          "expiresAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "token",
          "expiresAt"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "param": {
                "type": "string"
              },
              "errors": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "path": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "path",
                    "message"
                  ]
                },
                "description": "All field-level problems, e.g. for profile validation"
              },
              "request_id": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "SignupRequest": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "maxLength": 254,
            "format": "email",
            "example": "owner@example.com"
          },
          "password": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128,
            "example": "correct horse battery"
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "accountName": {
            "type": "string",
            "maxLength": 100,
            "description": "Agency / company name. Defaults to the user's name."
          }
        },
        "required": [
          "email",
          "password"
        ]
      },
      "LoginRequest": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "maxLength": 254,
            "format": "email",
            "example": "owner@example.com"
          },
          "password": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          }
        },
        "required": [
          "email",
          "password"
        ]
      },
      "GoogleLoginRequest": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2000,
            "description": "Authorization code from Google's redirect (the console's flow)"
          },
          "redirectUri": {
            "type": "string",
            "maxLength": 500,
            "description": "The redirect URI the code was issued for; required with code"
          },
          "idToken": {
            "type": "string",
            "minLength": 1,
            "description": "Alternatively, a Google ID token (e.g. from a mobile app)"
          }
        }
      },
      "ForgotPasswordRequest": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string",
            "maxLength": 254,
            "format": "email",
            "example": "owner@example.com"
          }
        },
        "required": [
          "email"
        ]
      },
      "ResetPasswordRequest": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "minLength": 1
          },
          "password": {
            "type": "string",
            "minLength": 8,
            "maxLength": 128,
            "example": "correct horse battery"
          }
        },
        "required": [
          "token",
          "password"
        ]
      },
      "Me": {
        "type": "object",
        "properties": {
          "user": {
            "$ref": "#/components/schemas/User"
          },
          "memberships": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Membership"
            }
          }
        },
        "required": [
          "user",
          "memberships"
        ]
      },
      "Membership": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "member"
            ]
          },
          "account": {
            "$ref": "#/components/schemas/Account"
          },
          "workspaces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Workspace"
            }
          }
        },
        "required": [
          "role",
          "account",
          "workspaces"
        ]
      },
      "ApiKeyList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ApiKey"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "ApiKey": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "api_key"
            ]
          },
          "id": {
            "type": "string",
            "example": "key_5Tg8Wm2PqXc7Ln0Rv4Bz1Hjk"
          },
          "name": {
            "type": "string"
          },
          "prefix": {
            "type": "string",
            "example": "lv_live_ab12",
            "description": "First characters of the key, for display"
          },
          "permission": {
            "type": "string",
            "enum": [
              "read",
              "write",
              "admin"
            ]
          },
          "workspaceId": {
            "type": [
              "string",
              "null"
            ],
            "description": "null = account-wide key"
          },
          "livemode": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string"
          },
          "lastUsedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "expiresAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "revokedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "id",
          "name",
          "prefix",
          "permission",
          "workspaceId",
          "livemode",
          "createdAt",
          "lastUsedAt",
          "expiresAt",
          "revokedAt"
        ]
      },
      "CreatedApiKey": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ApiKey"
          },
          {
            "type": "object",
            "properties": {
              "secret": {
                "type": "string",
                "description": "The full key. Shown only once; store it securely."
              }
            },
            "required": [
              "secret"
            ]
          }
        ]
      },
      "CreateApiKeyRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "example": "n8n production"
          },
          "permission": {
            "type": "string",
            "enum": [
              "read",
              "write",
              "admin"
            ]
          },
          "workspaceId": {
            "type": "string",
            "description": "Restrict the key to one workspace. Omit for an account-wide key."
          },
          "livemode": {
            "type": "boolean",
            "description": "false creates a test key (lv_test_…). Default true."
          },
          "expiresAt": {
            "type": "string",
            "description": "ISO date; omit for no expiry"
          }
        },
        "required": [
          "name",
          "permission"
        ]
      },
      "WorkspaceList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Workspace"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "CreateWorkspaceRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "businessContext": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 4000,
            "description": "What the business does, its services and area. Used by AI for every profile."
          },
          "location": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "address": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "lat": {
                "type": "number",
                "minimum": -90,
                "maximum": 90
              },
              "lng": {
                "type": "number",
                "minimum": -180,
                "maximum": 180
              }
            },
            "required": [
              "address"
            ],
            "description": "Business address. Send only the address and Leadveyor finds the coordinates (and tidies the address)."
          },
          "locale": {
            "type": "object",
            "properties": {
              "language": {
                "type": "string",
                "maxLength": 10
              },
              "timezone": {
                "type": "string",
                "maxLength": 64
              },
              "currency": {
                "type": "string",
                "minLength": 3,
                "maxLength": 3
              }
            },
            "required": [
              "language",
              "timezone",
              "currency"
            ]
          },
          "businessHours": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "mon": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "tue": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "wed": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "thu": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "fri": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "sat": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "sun": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              }
            }
          },
          "retentionDays": {
            "type": "integer",
            "minimum": 7,
            "maximum": 365
          }
        },
        "required": [
          "name"
        ]
      },
      "UpdateWorkspaceRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "businessContext": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 4000,
            "description": "What the business does, its services and area. Used by AI for every profile."
          },
          "location": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "address": {
                "type": "string",
                "minLength": 1,
                "maxLength": 300
              },
              "lat": {
                "type": "number",
                "minimum": -90,
                "maximum": 90
              },
              "lng": {
                "type": "number",
                "minimum": -180,
                "maximum": 180
              }
            },
            "required": [
              "address"
            ],
            "description": "Business address. Send only the address and Leadveyor finds the coordinates (and tidies the address)."
          },
          "locale": {
            "type": "object",
            "properties": {
              "language": {
                "type": "string",
                "maxLength": 10
              },
              "timezone": {
                "type": "string",
                "maxLength": 64
              },
              "currency": {
                "type": "string",
                "minLength": 3,
                "maxLength": 3
              }
            },
            "required": [
              "language",
              "timezone",
              "currency"
            ]
          },
          "businessHours": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "mon": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "tue": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "wed": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "thu": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "fri": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "sat": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              },
              "sun": {
                "type": [
                  "object",
                  "null"
                ],
                "properties": {
                  "open": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  },
                  "close": {
                    "type": "string",
                    "pattern": "^\\d{2}:\\d{2}$"
                  }
                },
                "required": [
                  "open",
                  "close"
                ]
              }
            }
          },
          "retentionDays": {
            "type": "integer",
            "minimum": 7,
            "maximum": 365
          },
          "defaultProfileId": {
            "type": [
              "string",
              "null"
            ],
            "description": "A published profile of this workspace"
          }
        }
      },
      "ProfileTemplateList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProfileTemplate"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "ProfileTemplate": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "profile_template"
            ]
          },
          "id": {
            "type": "string",
            "description": "Template ID, used as templateId",
            "example": "plumbing"
          },
          "name": {
            "type": "string",
            "description": "Display name; also the default profile name"
          },
          "category": {
            "type": "string",
            "enum": [
              "trades",
              "home_services",
              "events",
              "professional_services",
              "b2b",
              "general"
            ],
            "description": "Kind of business, for grouping in a gallery"
          },
          "description": {
            "type": "string",
            "description": "Who the template is for and what it scores highest"
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TemplateVariable"
            },
            "description": "Values filled in when a profile is created; all have defaults"
          },
          "document": {
            "type": "object",
            "properties": {},
            "additionalProperties": {},
            "description": "Profile document with {{variable}} placeholders; {{currency}} is the workspace currency"
          }
        },
        "required": [
          "object",
          "id",
          "name",
          "category",
          "description",
          "variables",
          "document"
        ]
      },
      "TemplateVariable": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "description": "Name to use in `variables` when creating a profile",
            "example": "service_radius_km"
          },
          "label": {
            "type": "string",
            "description": "Short label for a form field"
          },
          "type": {
            "type": "string",
            "enum": [
              "number",
              "money",
              "text"
            ],
            "description": "money is an amount in the workspace currency"
          },
          "default": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "string"
              }
            ],
            "description": "Used when the variable isn't given"
          },
          "description": {
            "type": "string",
            "description": "What the value means"
          },
          "min": {
            "type": "number",
            "description": "Smallest allowed value"
          },
          "max": {
            "type": "number",
            "description": "Largest allowed value"
          },
          "unit": {
            "type": "string",
            "description": "Unit shown next to the value, e.g. km"
          }
        },
        "required": [
          "key",
          "label",
          "type",
          "default",
          "description"
        ]
      },
      "ProfileList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Profile"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Profile": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "profile"
            ]
          },
          "id": {
            "type": "string",
            "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
          },
          "workspaceId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "isDefault": {
            "type": "boolean",
            "description": "Used when a source or request doesn't name a profile"
          },
          "activeVersion": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Version used for scoring; null until published"
          },
          "latestVersion": {
            "type": "integer"
          },
          "document": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ProfileDocument"
              },
              {
                "type": [
                  "object",
                  "null"
                ],
                "description": "Document of the active version"
              }
            ]
          },
          "draft": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "document": {
                "$ref": "#/components/schemas/ProfileDocument"
              },
              "basedOnVersion": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "updatedAt": {
                "type": "string"
              }
            },
            "required": [
              "document",
              "basedOnVersion",
              "updatedAt"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "name",
          "isDefault",
          "activeVersion",
          "latestVersion",
          "document",
          "draft",
          "createdAt",
          "updatedAt"
        ]
      },
      "ProfileValidation": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "profile_validation"
            ]
          },
          "valid": {
            "type": "boolean"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "path",
                "message"
              ]
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "path": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              },
              "required": [
                "path",
                "message"
              ]
            }
          },
          "document": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ProfileDocument"
              },
              {
                "type": [
                  "object",
                  "null"
                ],
                "description": "Normalized document with defaults, when valid"
              }
            ]
          }
        },
        "required": [
          "object",
          "valid",
          "errors",
          "warnings",
          "document"
        ]
      },
      "GeneratedCriterion": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "generated_criterion"
            ]
          },
          "criterion": {
            "$ref": "#/components/schemas/Criterion"
          },
          "usage": {
            "type": "object",
            "properties": {
              "costUsd": {
                "type": "number"
              },
              "inputTokens": {
                "type": "number"
              },
              "outputTokens": {
                "type": "number"
              },
              "models": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "costUsd",
              "inputTokens",
              "outputTokens",
              "models"
            ]
          }
        },
        "required": [
          "object",
          "criterion",
          "usage"
        ]
      },
      "GenerateCriterionRequest": {
        "type": "object",
        "properties": {
          "description": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000,
            "description": "What to look for, in plain words; may include your own grade levels",
            "example": "Weddings are our best jobs. 5 if it's a wedding, 3 for engagement parties, 1 for anything else."
          },
          "kind": {
            "type": "string",
            "enum": [
              "graded",
              "escalate",
              "disqualify"
            ],
            "default": "graded",
            "description": "graded: an ai criterion with grade levels; escalate: when met, the lead goes to the top tier; disqualify: when met, the lead is rejected"
          },
          "profile": {
            "type": "object",
            "properties": {},
            "additionalProperties": {},
            "description": "The profile document being edited; its dimensions, grade scale, brief and criterion ids are used"
          }
        },
        "required": [
          "description"
        ]
      },
      "GeneratedProfile": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "generated_profile"
            ]
          },
          "profile": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Profile"
              },
              {
                "description": "The new profile; the generated document is its draft (not published)"
              }
            ]
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "What the AI assumed that the brief didn't say — check these"
          },
          "dropped": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Generated criteria or fields left out because they were invalid"
          },
          "usage": {
            "type": "object",
            "properties": {
              "costUsd": {
                "type": "number"
              },
              "inputTokens": {
                "type": "number"
              },
              "outputTokens": {
                "type": "number"
              },
              "models": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "costUsd",
              "inputTokens",
              "outputTokens",
              "models"
            ]
          }
        },
        "required": [
          "object",
          "profile",
          "assumptions",
          "dropped",
          "usage"
        ]
      },
      "GenerateProfileRequest": {
        "type": "object",
        "properties": {
          "brief": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4000,
            "description": "The business and what a good lead is, in plain words: services, area, best customers, what you don't do",
            "example": "Plumbing business in Brisbane. Emergencies and bathroom renovations are our best jobs, we also do hot water systems. We don't do commercial work or new builds."
          },
          "name": {
            "type": "string",
            "maxLength": 100,
            "description": "Profile name; by default the AI names it"
          },
          "templateId": {
            "type": "string",
            "description": "Start from this template (GET /v1/templates) and adapt it to the brief"
          },
          "variables": {
            "type": "object",
            "additionalProperties": {
              "anyOf": [
                {
                  "type": "number"
                },
                {
                  "type": "string"
                }
              ]
            },
            "description": "Template variables, with templateId"
          }
        },
        "required": [
          "brief"
        ]
      },
      "ProfilePatchRequest": {
        "type": "object",
        "properties": {
          "set": {
            "type": "object",
            "properties": {},
            "additionalProperties": {},
            "description": "Replace top-level parts: name, brief, scoring, tiers, junk"
          },
          "upsertFields": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {},
              "additionalProperties": {}
            },
            "description": "Add or replace extract fields by key"
          },
          "removeFields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "upsertCriteria": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {},
              "additionalProperties": {}
            },
            "description": "Add or replace criteria by id"
          },
          "removeCriteria": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "ProfileVersionList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ProfileVersion"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "ProfileVersion": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "profile_version"
            ]
          },
          "id": {
            "type": "string"
          },
          "profileId": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "document": {
            "$ref": "#/components/schemas/ProfileDocument"
          },
          "publishedAt": {
            "type": "string"
          },
          "publishedBy": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "user",
                  "api_key"
                ]
              },
              "id": {
                "type": "string"
              }
            },
            "required": [
              "type",
              "id"
            ]
          }
        },
        "required": [
          "object",
          "id",
          "profileId",
          "version",
          "document",
          "publishedAt",
          "publishedBy"
        ]
      },
      "EvaluationResult": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "evaluation_result"
            ]
          },
          "livemode": {
            "type": "boolean"
          },
          "classification": {
            "type": "string",
            "enum": [
              "lead",
              "junk",
              "not_lead"
            ]
          },
          "junk": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "category": {
                "type": "string"
              },
              "confidence": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              },
              "rule": {
                "type": "string"
              }
            },
            "required": [
              "category",
              "confidence",
              "reason"
            ],
            "description": "Why the message isn't a lead"
          },
          "profile": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "version": {
                    "type": "number"
                  }
                },
                "required": [
                  "id",
                  "version"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "inline": {
                    "type": "boolean",
                    "enum": [
                      true
                    ]
                  }
                },
                "required": [
                  "inline"
                ]
              }
            ]
          },
          "leads": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LeadEvaluation"
            },
            "description": "0..N leads found in the message"
          },
          "usage": {
            "type": "object",
            "properties": {
              "costUsd": {
                "type": "number"
              },
              "inputTokens": {
                "type": "number"
              },
              "outputTokens": {
                "type": "number"
              },
              "models": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "costUsd",
              "inputTokens",
              "outputTokens",
              "models"
            ]
          },
          "timing": {
            "type": "object",
            "properties": {
              "totalMs": {
                "type": "number"
              },
              "steps": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "ms": {
                      "type": "number"
                    },
                    "detail": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "name",
                    "ms"
                  ]
                }
              }
            },
            "required": [
              "totalMs",
              "steps"
            ]
          },
          "pipelineVersion": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "livemode",
          "classification",
          "junk",
          "profile",
          "leads",
          "usage",
          "timing",
          "pipelineVersion"
        ]
      },
      "LeadEvaluation": {
        "type": "object",
        "properties": {
          "contact": {
            "type": "object",
            "properties": {
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "firstName": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "lastName": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "emails": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "phones": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "other": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "type",
                    "value"
                  ]
                }
              },
              "company": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "name",
              "firstName",
              "lastName",
              "emails",
              "phones",
              "other",
              "company"
            ]
          },
          "request": {
            "type": "object",
            "properties": {
              "summary": {
                "type": "string"
              },
              "service": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "summary",
              "service"
            ]
          },
          "location": {
            "type": "object",
            "properties": {
              "address": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "city": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "postcode": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "country": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "address",
              "city",
              "postcode",
              "country"
            ]
          },
          "language": {
            "type": [
              "string",
              "null"
            ]
          },
          "fields": {
            "type": "object",
            "additionalProperties": {},
            "description": "Profile fields, typed (numbers, { amount, currency }, { value, asWritten } for dates…)"
          },
          "evaluation": {
            "$ref": "#/components/schemas/Evaluation"
          }
        },
        "required": [
          "contact",
          "request",
          "location",
          "language",
          "fields",
          "evaluation"
        ]
      },
      "Evaluation": {
        "type": "object",
        "properties": {
          "score": {
            "type": [
              "number",
              "null"
            ],
            "description": "0–100; null when nothing could be scored"
          },
          "tier": {
            "type": "string",
            "description": "One of the profile's tiers, or disqualified / unscored"
          },
          "confidence": {
            "type": "number",
            "description": "Share of criteria that could be determined, 0–1"
          },
          "decidedBy": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "type": {
                "type": "string",
                "enum": [
                  "disqualify",
                  "escalate"
                ]
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "type",
              "reason"
            ]
          },
          "dimensions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "score": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "confidence": {
                  "type": "number"
                },
                "known": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "unknown": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "id",
                "label",
                "score",
                "confidence",
                "known",
                "unknown"
              ]
            }
          },
          "criteria": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "rule",
                    "ai",
                    "disqualify",
                    "escalate"
                  ]
                },
                "result": {
                  "type": "string",
                  "enum": [
                    "met",
                    "not_met",
                    "unknown"
                  ]
                },
                "grade": {
                  "type": [
                    "number",
                    "null"
                  ]
                },
                "points": {
                  "type": "number"
                },
                "evidence": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Exact quote from the message"
                },
                "dimension": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "label",
                "type",
                "result",
                "grade",
                "points",
                "evidence",
                "dimension"
              ]
            }
          }
        },
        "required": [
          "score",
          "tier",
          "confidence",
          "decidedBy",
          "dimensions",
          "criteria"
        ]
      },
      "EvaluateRequest": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "maxLength": 100000,
            "description": "Free text: an email body, a chat message, a transcript…"
          },
          "email": {
            "type": "object",
            "properties": {
              "from": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "email": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                ],
                "description": "\"Jane Doe <jane@example.com>\" or { name, email }"
              },
              "subject": {
                "type": "string",
                "maxLength": 1000
              },
              "text": {
                "type": "string",
                "maxLength": 100000
              },
              "html": {
                "type": "string",
                "maxLength": 500000,
                "description": "Used when text is missing; converted to text"
              }
            }
          },
          "fields": {
            "type": "object",
            "additionalProperties": {},
            "description": "Form fields exactly as received; no mapping needed",
            "example": {
              "name": "Sarah",
              "message": "Wedding for 120 guests"
            }
          },
          "channel": {
            "type": "string",
            "maxLength": 50,
            "description": "email, form, chat, … Inferred when omitted"
          },
          "profileId": {
            "type": "string",
            "description": "Profile to score with (its active version). Default: the workspace default profile"
          },
          "profile": {
            "type": "object",
            "properties": {},
            "additionalProperties": {},
            "description": "A whole profile document inline, instead of a stored profile"
          }
        }
      },
      "SourceList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Source"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Source": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "source"
            ]
          },
          "id": {
            "type": "string",
            "example": "src_4Hd8Kq2Lm7Xp1Vz9Rt3Bc6Nw"
          },
          "workspaceId": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "api",
              "email",
              "form",
              "telegram",
              "google_ads",
              "facebook_lead_ads"
            ]
          },
          "name": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused",
              "error",
              "pending_setup"
            ]
          },
          "profileId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Profile for this source's messages; null = workspace default"
          },
          "config": {
            "type": "object",
            "additionalProperties": {}
          },
          "stats": {
            "type": "object",
            "properties": {
              "total": {
                "type": "number"
              },
              "lastInboundAt": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "total",
              "lastInboundAt"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "type",
          "name",
          "status",
          "profileId",
          "config",
          "stats",
          "createdAt",
          "updatedAt"
        ]
      },
      "CreateSourceRequest": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "api",
              "email",
              "form",
              "telegram",
              "google_ads",
              "facebook_lead_ads"
            ],
            "description": "Available now: api, email (you get an address to forward mail to), form (you get a URL to post forms to). Others later."
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "profileId": {
            "type": [
              "string",
              "null"
            ]
          },
          "redirectUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "form: page to send people to after a classic HTML form submit"
          }
        },
        "required": [
          "type"
        ]
      },
      "UpdateSourceRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "profileId": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "paused"
            ]
          },
          "redirectUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "form sources only"
          }
        }
      },
      "InboundResult": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Inbound"
          },
          {
            "type": "object",
            "properties": {
              "leads": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Lead"
                },
                "description": "With wait=true and a finished run: the leads found"
              }
            }
          }
        ]
      },
      "Job": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "job"
            ]
          },
          "id": {
            "type": "string"
          },
          "inboundId": {
            "type": "string"
          },
          "trigger": {
            "type": "string",
            "enum": [
              "initial",
              "reprocess"
            ]
          },
          "options": {
            "type": "object",
            "properties": {
              "notJunk": {
                "type": "boolean"
              },
              "profileId": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "notJunk",
              "profileId"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "processing",
              "completed",
              "failed"
            ]
          },
          "attempts": {
            "type": "number"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "ms": {
                  "type": "number"
                },
                "detail": {
                  "type": "string"
                }
              },
              "required": [
                "name",
                "ms"
              ]
            }
          },
          "usage": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "costUsd": {
                "type": "number"
              },
              "inputTokens": {
                "type": "number"
              },
              "outputTokens": {
                "type": "number"
              },
              "models": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "costUsd",
              "inputTokens",
              "outputTokens",
              "models"
            ]
          },
          "pipelineVersion": {
            "type": [
              "string",
              "null"
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "startedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "finishedAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "id",
          "inboundId",
          "trigger",
          "options",
          "status",
          "attempts",
          "steps",
          "usage",
          "pipelineVersion",
          "error",
          "createdAt",
          "startedAt",
          "finishedAt"
        ]
      },
      "Lead": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "lead"
            ]
          },
          "id": {
            "type": "string",
            "example": "lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr"
          },
          "workspaceId": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "sourceId": {
            "type": "string"
          },
          "inboundIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "contactId": {
            "type": [
              "string",
              "null"
            ],
            "description": "The person (same email or phone); null without email and phone"
          },
          "contact": {
            "type": "object",
            "additionalProperties": {}
          },
          "request": {
            "type": "object",
            "properties": {
              "summary": {
                "type": "string"
              },
              "service": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "summary",
              "service"
            ]
          },
          "location": {
            "type": "object",
            "additionalProperties": {}
          },
          "language": {
            "type": [
              "string",
              "null"
            ]
          },
          "fields": {
            "type": "object",
            "additionalProperties": {}
          },
          "evaluation": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Evaluation"
              },
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "profileId": {
                    "type": "string"
                  },
                  "profileVersion": {
                    "type": "number"
                  },
                  "evaluatedAt": {
                    "type": "string"
                  }
                },
                "required": [
                  "id",
                  "profileId",
                  "profileVersion",
                  "evaluatedAt"
                ]
              }
            ]
          },
          "outcome": {
            "$ref": "#/components/schemas/Outcome"
          },
          "state": {
            "type": "string",
            "enum": [
              "active",
              "archived"
            ]
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "legacy": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "details": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "title": {
                      "type": "string"
                    },
                    "value": {},
                    "group": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "title",
                    "group"
                  ]
                }
              },
              "priority": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "rate": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "number"
            ],
            "description": "Original ID and number, for records imported from another system"
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "livemode",
          "sourceId",
          "inboundIds",
          "contactId",
          "contact",
          "request",
          "location",
          "language",
          "fields",
          "evaluation",
          "outcome",
          "state",
          "metadata",
          "legacy",
          "createdAt",
          "updatedAt"
        ]
      },
      "Outcome": {
        "type": [
          "object",
          "null"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "won",
              "lost",
              "no_response",
              "disqualified",
              "other"
            ]
          },
          "value": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "amount": {
                "type": "number"
              },
              "currency": {
                "type": "string"
              }
            },
            "required": [
              "amount",
              "currency"
            ]
          },
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "occurredAt": {
            "type": "string"
          },
          "recordedAt": {
            "type": "string"
          },
          "recordedBy": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": "string"
              }
            },
            "required": [
              "type"
            ]
          }
        },
        "required": [
          "status",
          "value",
          "reason",
          "occurredAt",
          "recordedAt",
          "recordedBy"
        ],
        "description": "What happened to the lead, as reported by you"
      },
      "Inbound": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "inbound"
            ]
          },
          "id": {
            "type": "string",
            "example": "inb_9Qe3Wn7Kd2Lp5Xr8Vt1Mz4Bh"
          },
          "workspaceId": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "sourceId": {
            "type": "string"
          },
          "channel": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "received",
              "processing",
              "processed",
              "failed",
              "quota_exceeded"
            ],
            "description": "quota_exceeded: kept, waits for the plan's allowance and is then processed automatically"
          },
          "classification": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "lead",
              "junk",
              "not_lead",
              null
            ]
          },
          "junk": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "category": {
                "type": "string"
              },
              "confidence": {
                "type": "string"
              },
              "reason": {
                "type": "string"
              },
              "rule": {
                "type": "string"
              }
            },
            "required": [
              "category",
              "confidence",
              "reason"
            ]
          },
          "leadIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "profile": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "version": {
                "type": "number"
              }
            },
            "required": [
              "id",
              "version"
            ]
          },
          "error": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ],
            "description": "Why processing failed (after all retries)"
          },
          "externalId": {
            "type": [
              "string",
              "null"
            ]
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "content": {
            "type": "object",
            "additionalProperties": {},
            "description": "The message, normalized"
          },
          "receivedAt": {
            "type": "string"
          },
          "processedAt": {
            "type": [
              "string",
              "null"
            ]
          },
          "jobs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Job"
            },
            "description": "Processing runs, newest first (single inbound only)"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "livemode",
          "sourceId",
          "channel",
          "status",
          "classification",
          "junk",
          "leadIds",
          "profile",
          "error",
          "externalId",
          "metadata",
          "content",
          "receivedAt",
          "processedAt"
        ]
      },
      "CreateInboundRequest": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "maxLength": 100000,
            "description": "Free text: an email body, a chat message, a transcript…"
          },
          "email": {
            "type": "object",
            "properties": {
              "from": {
                "anyOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      },
                      "email": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                ],
                "description": "\"Jane Doe <jane@example.com>\" or { name, email }"
              },
              "subject": {
                "type": "string",
                "maxLength": 1000
              },
              "text": {
                "type": "string",
                "maxLength": 100000
              },
              "html": {
                "type": "string",
                "maxLength": 500000,
                "description": "Used when text is missing; converted to text"
              }
            }
          },
          "fields": {
            "type": "object",
            "additionalProperties": {},
            "description": "Form fields exactly as received; no mapping needed",
            "example": {
              "name": "Sarah",
              "message": "Wedding for 120 guests"
            }
          },
          "channel": {
            "type": "string",
            "maxLength": 50,
            "description": "email, form, chat, … Inferred when omitted"
          },
          "sourceId": {
            "type": "string",
            "description": "Default: the workspace's API source"
          },
          "profileId": {
            "type": "string",
            "description": "Override the source's / workspace's profile for this message"
          },
          "externalId": {
            "type": "string",
            "maxLength": 200,
            "description": "Your ID for this message; sending it again returns the same inbound (no double processing)"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 500
            },
            "description": "Your key-values, copied to the leads (e.g. a CRM id)"
          }
        }
      },
      "InboundList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Inbound"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "ReprocessRequest": {
        "type": "object",
        "properties": {
          "notJunk": {
            "type": "boolean",
            "description": "Skip the junk filter (the message was wrongly marked junk)"
          },
          "profileId": {
            "type": "string"
          }
        }
      },
      "LeadList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Lead"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "EvaluationList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EvaluationRecord"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "EvaluationRecord": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Evaluation"
          },
          {
            "type": "object",
            "properties": {
              "object": {
                "type": "string",
                "enum": [
                  "evaluation"
                ]
              },
              "id": {
                "type": "string"
              },
              "leadId": {
                "type": "string"
              },
              "inboundId": {
                "type": "string"
              },
              "jobId": {
                "type": "string"
              },
              "profileId": {
                "type": "string"
              },
              "profileVersion": {
                "type": "number"
              },
              "pipelineVersion": {
                "type": "string"
              },
              "createdAt": {
                "type": "string"
              }
            },
            "required": [
              "object",
              "id",
              "leadId",
              "inboundId",
              "jobId",
              "profileId",
              "profileVersion",
              "pipelineVersion",
              "createdAt"
            ]
          }
        ]
      },
      "RecordOutcomeRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "won",
              "lost",
              "no_response",
              "disqualified",
              "other"
            ]
          },
          "amount": {
            "type": "number",
            "minimum": 0,
            "description": "Deal value"
          },
          "currency": {
            "type": "string",
            "minLength": 3,
            "maxLength": 3,
            "description": "ISO 4217; default: the workspace currency"
          },
          "reason": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 2000,
            "description": "Why, especially for lost"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "description": "When it happened; default: now"
          }
        },
        "required": [
          "status"
        ]
      },
      "ContactList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Contact"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Contact": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "contact"
            ]
          },
          "id": {
            "type": "string",
            "example": "ctc_7Rm2Kx9Pq4Lz1Wv6Tn3Hb8Dc"
          },
          "workspaceId": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "firstName": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastName": {
            "type": [
              "string",
              "null"
            ]
          },
          "company": {
            "type": [
              "string",
              "null"
            ]
          },
          "emails": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "phones": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "vip": {
            "type": "boolean"
          },
          "blocked": {
            "type": "boolean"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "stats": {
            "type": "object",
            "properties": {
              "leads": {
                "type": "number"
              },
              "won": {
                "type": "number"
              },
              "lost": {
                "type": "number"
              },
              "lastLeadAt": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "leads",
              "won",
              "lost",
              "lastLeadAt"
            ]
          },
          "legacy": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "number": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "details": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "title": {
                      "type": "string"
                    },
                    "value": {},
                    "group": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  },
                  "required": [
                    "title",
                    "group"
                  ]
                }
              },
              "priority": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "rate": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "id",
              "number"
            ],
            "description": "Original ID and number, for records imported from another system"
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "livemode",
          "name",
          "firstName",
          "lastName",
          "company",
          "emails",
          "phones",
          "vip",
          "blocked",
          "metadata",
          "stats",
          "legacy",
          "createdAt",
          "updatedAt"
        ]
      },
      "UpdateContactRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "company": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 200
          },
          "vip": {
            "type": "boolean"
          },
          "blocked": {
            "type": "boolean",
            "description": "Mark as never-a-customer (spam, competitor)"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 500
            },
            "description": "Replaces your key-values, e.g. a CRM id"
          }
        }
      },
      "ContactLeadList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Lead"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "DestinationList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Destination"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Destination": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "destination"
            ]
          },
          "id": {
            "type": "string",
            "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
          },
          "workspaceId": {
            "type": "string"
          },
          "livemode": {
            "type": "boolean"
          },
          "type": {
            "type": "string",
            "enum": [
              "webhook"
            ]
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "filter": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": {}
          },
          "secretPrefix": {
            "type": "string",
            "description": "Start of the signing secret, for identification"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "disabled"
            ]
          },
          "failureStreak": {
            "type": "number"
          },
          "disabledReason": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          }
        },
        "required": [
          "object",
          "id",
          "workspaceId",
          "livemode",
          "type",
          "name",
          "url",
          "events",
          "filter",
          "secretPrefix",
          "status",
          "failureStreak",
          "disabledReason",
          "createdAt",
          "updatedAt"
        ]
      },
      "DestinationWithSecret": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Destination"
          },
          {
            "type": "object",
            "properties": {
              "secret": {
                "type": "string",
                "description": "Signing secret (whsec_…). Shown only on create and rotation."
              }
            },
            "required": [
              "secret"
            ]
          }
        ]
      },
      "CreateDestinationRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "example": "https://n8n.example.com/webhook/abc"
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "lead.created, lead.updated, lead.scored, lead.outcome_recorded, inbound.junk, inbound.failed, or a prefix like lead.*. Default: lead.scored"
          },
          "filter": {
            "type": [
              "object",
              "null"
            ],
            "properties": {},
            "additionalProperties": {},
            "description": "Send only matching events, e.g. { \"field\": \"evaluation.tier\", \"op\": \"in\", \"value\": [\"hot\", \"warm\"] }"
          }
        },
        "required": [
          "url"
        ]
      },
      "UpdateDestinationRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "maxLength": 100
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "lead.created, lead.updated, lead.scored, lead.outcome_recorded, inbound.junk, inbound.failed, or a prefix like lead.*. Default: lead.scored"
          },
          "filter": {
            "type": [
              "object",
              "null"
            ],
            "properties": {},
            "additionalProperties": {},
            "description": "Send only matching events, e.g. { \"field\": \"evaluation.tier\", \"op\": \"in\", \"value\": [\"hot\", \"warm\"] }"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "disabled"
            ],
            "description": "active re-enables a disabled destination"
          }
        }
      },
      "Event": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "event"
            ]
          },
          "id": {
            "type": "string",
            "example": "evt_6Gk2Pq9Tz4Lm1Wx8Rc3Vn7Bd"
          },
          "type": {
            "type": "string",
            "example": "lead.scored"
          },
          "livemode": {
            "type": "boolean"
          },
          "workspaceId": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "object": {
                "type": "object",
                "additionalProperties": {},
                "description": "The lead or inbound, as returned by the API"
              },
              "previous": {
                "type": "object",
                "additionalProperties": {},
                "description": "lead.updated: why and the previous evaluation"
              }
            },
            "required": [
              "object"
            ]
          }
        },
        "required": [
          "object",
          "id",
          "type",
          "livemode",
          "workspaceId",
          "createdAt",
          "data"
        ]
      },
      "DeliveryList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Delivery"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Delivery": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "delivery"
            ]
          },
          "id": {
            "type": "string"
          },
          "destinationId": {
            "type": "string"
          },
          "eventId": {
            "type": "string"
          },
          "eventType": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "succeeded",
              "failed"
            ]
          },
          "attempts": {
            "type": "number"
          },
          "response": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "status": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "body": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "ms": {
                "type": "number"
              }
            },
            "required": [
              "status",
              "body",
              "ms"
            ]
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "lastAttemptAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "id",
          "destinationId",
          "eventId",
          "eventType",
          "status",
          "attempts",
          "response",
          "error",
          "createdAt",
          "lastAttemptAt"
        ]
      },
      "EventList": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "list"
            ]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            }
          },
          "has_more": {
            "type": "boolean"
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "object",
          "data",
          "has_more",
          "next_cursor"
        ]
      },
      "Billing": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "billing"
            ]
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "starter",
              "pro",
              "agency",
              "scale",
              "internal"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "past_due",
              "canceled"
            ]
          },
          "cancelAtPeriodEnd": {
            "type": "boolean"
          },
          "pendingPlan": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "free",
              "starter",
              "pro",
              "agency",
              "scale",
              "internal",
              null
            ],
            "description": "Downgrade that starts with the next period"
          },
          "spendLimitUsd": {
            "type": [
              "number",
              "null"
            ]
          },
          "hasSubscription": {
            "type": "boolean"
          },
          "paymentsEnabled": {
            "type": "boolean"
          },
          "usage": {
            "$ref": "#/components/schemas/Usage"
          },
          "plans": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Plan"
            }
          },
          "allowances": {
            "type": "object",
            "properties": {
              "nonLeadMultiple": {
                "type": "number"
              },
              "testLeads": {
                "type": "number"
              },
              "freeEvaluations": {
                "type": "number"
              },
              "evaluationsPerLead": {
                "type": "number"
              },
              "generations": {
                "type": "number"
              },
              "thresholds": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              }
            },
            "required": [
              "nonLeadMultiple",
              "testLeads",
              "freeEvaluations",
              "evaluationsPerLead",
              "generations",
              "thresholds"
            ]
          }
        },
        "required": [
          "object",
          "plan",
          "status",
          "cancelAtPeriodEnd",
          "pendingPlan",
          "spendLimitUsd",
          "hasSubscription",
          "paymentsEnabled",
          "usage",
          "plans",
          "allowances"
        ]
      },
      "Usage": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "usage"
            ]
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "starter",
              "pro",
              "agency",
              "scale",
              "internal"
            ]
          },
          "periodStart": {
            "type": "string",
            "format": "date-time"
          },
          "periodEnd": {
            "type": "string",
            "format": "date-time"
          },
          "leads": {
            "type": "object",
            "properties": {
              "used": {
                "type": "integer",
                "description": "New leads this period, plus evaluations beyond the free number (4 = 1 lead)"
              },
              "included": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "percent": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "overage": {
                "type": "integer",
                "description": "Leads beyond the plan"
              },
              "overageUsd": {
                "type": "number"
              },
              "spendLimitUsd": {
                "type": [
                  "number",
                  "null"
                ],
                "description": "Cap on charges for leads beyond the plan; null on Free"
              }
            },
            "required": [
              "used",
              "included",
              "percent",
              "overage",
              "overageUsd",
              "spendLimitUsd"
            ]
          },
          "nonLeads": {
            "type": "object",
            "properties": {
              "used": {
                "type": "number"
              },
              "limit": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "used",
              "limit"
            ],
            "description": "Messages that were not leads (free up to 10× the lead allowance)"
          },
          "testLeads": {
            "type": "object",
            "properties": {
              "used": {
                "type": "number"
              },
              "limit": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "used",
              "limit"
            ],
            "description": "Leads created with test keys"
          },
          "evaluations": {
            "type": "object",
            "properties": {
              "used": {
                "type": "integer"
              },
              "free": {
                "type": "integer"
              }
            },
            "required": [
              "used",
              "free"
            ]
          },
          "generations": {
            "type": "object",
            "properties": {
              "used": {
                "type": "number"
              },
              "limit": {
                "type": [
                  "number",
                  "null"
                ]
              }
            },
            "required": [
              "used",
              "limit"
            ],
            "description": "Profiles / criteria generated from a description"
          },
          "byWorkspace": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "workspaceId": {
                  "type": "string"
                },
                "leads": {
                  "type": "integer"
                }
              },
              "required": [
                "workspaceId",
                "leads"
              ]
            }
          }
        },
        "required": [
          "object",
          "plan",
          "periodStart",
          "periodEnd",
          "leads",
          "nonLeads",
          "testLeads",
          "evaluations",
          "generations",
          "byWorkspace"
        ]
      },
      "Plan": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "free",
              "starter",
              "pro",
              "agency",
              "scale",
              "internal"
            ]
          },
          "name": {
            "type": "string"
          },
          "priceUsd": {
            "type": [
              "number",
              "null"
            ],
            "description": "Per month; null = by contract"
          },
          "leads": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Leads included per period; null = unlimited"
          },
          "overageUsd": {
            "type": [
              "number",
              "null"
            ],
            "description": "Price of each lead beyond the plan; null = processing stops at the limit"
          },
          "workspaces": {
            "type": [
              "integer",
              "null"
            ]
          },
          "requestsPerSecond": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "priceUsd",
          "leads",
          "overageUsd",
          "workspaces",
          "requestsPerSecond"
        ]
      },
      "BillingRedirect": {
        "type": "object",
        "properties": {
          "object": {
            "type": "string",
            "enum": [
              "checkout_session",
              "portal_session"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        },
        "required": [
          "object",
          "url"
        ]
      },
      "CheckoutRequest": {
        "type": "object",
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "starter",
              "pro",
              "agency"
            ]
          }
        },
        "required": [
          "plan"
        ]
      },
      "ChangePlanRequest": {
        "type": "object",
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "starter",
              "pro",
              "agency"
            ]
          }
        },
        "required": [
          "plan"
        ]
      },
      "SpendLimitRequest": {
        "type": "object",
        "properties": {
          "spendLimitUsd": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 100000,
            "description": "null = the plan price"
          }
        },
        "required": [
          "spendLimitUsd"
        ]
      }
    },
    "parameters": {}
  },
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "Service health",
        "responses": {
          "200": {
            "description": "All dependencies are reachable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          },
          "503": {
            "description": "A dependency is unreachable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/signup": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Register a user; creates their account and first workspace",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignupRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Registered and signed in",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": {
                      "$ref": "#/components/schemas/User"
                    },
                    "account": {
                      "$ref": "#/components/schemas/Account"
                    },
                    "workspace": {
                      "$ref": "#/components/schemas/Workspace"
                    },
                    "session": {
                      "$ref": "#/components/schemas/Session"
                    }
                  },
                  "required": [
                    "user",
                    "account",
                    "workspace",
                    "session"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/login": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Sign in with email and password",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LoginRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": {
                      "$ref": "#/components/schemas/User"
                    },
                    "session": {
                      "$ref": "#/components/schemas/Session"
                    }
                  },
                  "required": [
                    "user",
                    "session"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/google": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Sign in or register with Google (authorization code from the redirect, or an ID token)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GoogleLoginRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed in",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": {
                      "$ref": "#/components/schemas/User"
                    },
                    "session": {
                      "$ref": "#/components/schemas/Session"
                    },
                    "isNew": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "user",
                    "session",
                    "isNew"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/logout": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Revoke the current session",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "204": {
            "description": "Signed out"
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/password/forgot": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Email a password reset link (always succeeds, to avoid revealing registered emails)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ForgotPasswordRequest"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "If the email is registered, a link was sent"
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/password/reset": {
      "post": {
        "tags": [
          "Auth"
        ],
        "summary": "Set a new password with a reset token; signs out all sessions",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResetPasswordRequest"
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Password changed"
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "tags": [
          "Auth"
        ],
        "summary": "Current user with accounts, roles and workspaces",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current user",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/api-keys": {
      "get": {
        "tags": [
          "API keys"
        ],
        "summary": "List API keys of the account (admin)",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "API keys",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "API keys"
        ],
        "summary": "Create an API key (admin). The secret is returned only once.",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateApiKeyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedApiKey"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/api-keys/{id}/revoke": {
      "post": {
        "tags": [
          "API keys"
        ],
        "summary": "Revoke an API key (admin). Idempotent.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "key_5Tg8Wm2PqXc7Ln0Rv4Bz1Hjk"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKey"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces": {
      "get": {
        "tags": [
          "Workspaces"
        ],
        "summary": "List workspaces the caller can access",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspaces",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkspaceList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Create a workspace (admin, account-wide access)",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateWorkspaceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Workspace"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}": {
      "get": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Get a workspace",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Workspace",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Workspace"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Workspaces"
        ],
        "summary": "Update a workspace (admin)",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": true,
            "name": "id",
            "in": "path"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateWorkspaceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Workspace"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/templates": {
      "get": {
        "tags": [
          "Templates"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Built-in profile templates",
        "description": "Create a profile from one with POST /v1/profiles `{ templateId, variables }`.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "enum": [
                "trades",
                "home_services",
                "events",
                "professional_services",
                "b2b",
                "general"
              ],
              "description": "Only templates of this category"
            },
            "required": false,
            "description": "Only templates of this category",
            "name": "category",
            "in": "query"
          }
        ],
        "responses": {
          "200": {
            "description": "Templates",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileTemplateList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/templates/{id}": {
      "get": {
        "tags": [
          "Templates"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One template with its variables and document",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Template ID, e.g. plumbing",
              "example": "plumbing"
            },
            "required": true,
            "description": "Template ID, e.g. plumbing",
            "name": "id",
            "in": "path"
          }
        ],
        "responses": {
          "200": {
            "description": "Template",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileTemplate"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles": {
      "get": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "List profiles of the workspace",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Profiles",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Create a profile from a document or a template (saved as draft; ?publish=true publishes version 1)",
        "description": "Send a full profile document, or `{ templateId, variables, name }` to start from a built-in template (see GET /v1/templates).",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "publish",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "additionalProperties": {},
                "description": "A profile document (see the ProfileDocument schema)",
                "example": {
                  "name": "Kitchen renovation"
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/validate": {
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Validate a profile document without saving; returns all errors with paths",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "additionalProperties": {},
                "description": "A profile document (see the ProfileDocument schema)",
                "example": {
                  "name": "Kitchen renovation"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileValidation"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/criteria/generate": {
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Draft a criterion from a plain-language description (AI); nothing is saved",
        "description": "Add the returned criterion to a draft with PUT or PATCH /v1/profiles/{id}/draft. Usually 3–8 s.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateCriterionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Drafted criterion",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GeneratedCriterion"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "AI or internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/generate": {
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Draft a whole profile from a description of the business (AI)",
        "description": "Creates a new profile whose draft is the generated document (not published): fields, criteria with points, escalations, disqualifiers, junk rules. Optionally starts from a template. Review, test (POST /v1/profiles/{id}/test) and publish it. Usually 10–30 s, about $0.02.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateProfileRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Generated profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GeneratedProfile"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "AI or internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}": {
      "get": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Get a profile with its active version and draft",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Delete a profile (published versions are kept for past evaluations)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "enum": [
                        "profile"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "id",
                    "deleted"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}/draft": {
      "put": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Replace the draft with a full document",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {},
                "additionalProperties": {},
                "description": "A profile document (see the ProfileDocument schema)",
                "example": {
                  "name": "Kitchen renovation"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile with updated draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Edit the draft: set top-level parts, upsert/remove fields and criteria",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfilePatchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile with updated draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Discard the draft",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}/publish": {
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Publish the draft as a new active version",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Published",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}/activate": {
      "post": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Make a published version active (rollback)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer",
                    "minimum": 1
                  }
                },
                "required": [
                  "version"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}/versions": {
      "get": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Published versions, newest first",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Versions",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileVersionList"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}/versions/{version}": {
      "get": {
        "tags": [
          "Profiles"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One published version",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "prof_7Kd2Rm9QxV4Lp1Zt8Nc3Hy6b"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "example": 1
            },
            "required": true,
            "name": "version",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileVersion"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/evaluate": {
      "post": {
        "tags": [
          "Evaluate"
        ],
        "summary": "Evaluate a message right away, without storing anything",
        "description": "Finds the lead(s) in a message, filters junk and scores each lead with a profile. Synchronous (usually 5–10 s). Nothing is stored: no history, no duplicate detection, no webhooks.",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace keys"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EvaluateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Evaluation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvaluationResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "AI or internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sources": {
      "get": {
        "tags": [
          "Sources"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "List the workspace's message sources",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Sources",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Sources"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Add a source",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSourceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Source"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sources/{id}": {
      "get": {
        "tags": [
          "Sources"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Get a source",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "src_4Hd8Kq2Lm7Xp1Vz9Rt3Bc6Nw"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Source",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Source"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Sources"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Rename, change profile, pause or resume a source",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "src_4Hd8Kq2Lm7Xp1Vz9Rt3Bc6Nw"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateSourceRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Source"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Sources"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Delete a source (its messages and leads are kept)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "src_4Hd8Kq2Lm7Xp1Vz9Rt3Bc6Nw"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "enum": [
                        "source"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "id",
                    "deleted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/inbounds": {
      "post": {
        "tags": [
          "Inbounds"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Send a message for processing",
        "description": "Stores the message and queues it (202). It is filtered for junk, its leads are extracted and scored, and failures are retried. With wait=true the request waits up to 30 s and returns the result (200), or 202 if still processing. Repeating a request with the same externalId returns the original inbound (200) without processing it again.",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "wait",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInboundRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Processed, or already received",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundResult"
                }
              }
            }
          },
          "202": {
            "description": "Accepted, processing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Inbounds"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Messages received, newest first: the processing queue and history",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "received",
                "processing",
                "processed",
                "failed"
              ]
            },
            "required": false,
            "name": "status",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "lead",
                "junk",
                "not_lead"
              ]
            },
            "required": false,
            "name": "classification",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "sourceId",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Inbounds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboundList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/inbounds/{id}": {
      "get": {
        "tags": [
          "Inbounds"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One message with its processing runs (steps, errors, cost)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "inb_9Qe3Wn7Kd2Lp5Xr8Vt1Mz4Bh"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Inbound",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Inbound"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/inbounds/{id}/reprocess": {
      "post": {
        "tags": [
          "Inbounds"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Process a message again (e.g. it was wrongly marked junk, or with another profile)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "inb_9Qe3Wn7Kd2Lp5Xr8Vt1Mz4Bh"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReprocessRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/leads": {
      "get": {
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Scored leads, newest first",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "e.g. hot, critical, disqualified, unscored"
            },
            "required": false,
            "description": "e.g. hot, critical, disqualified, unscored",
            "name": "tier",
            "in": "query"
          },
          {
            "schema": {
              "type": [
                "number",
                "null"
              ],
              "minimum": 0,
              "maximum": 100
            },
            "required": false,
            "name": "min_score",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "source_id",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "archived"
              ]
            },
            "required": false,
            "name": "state",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "contact_id",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "won",
                "lost",
                "no_response",
                "disqualified",
                "other",
                "none"
              ],
              "description": "none = no outcome yet"
            },
            "required": false,
            "description": "none = no outcome yet",
            "name": "outcome",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Original lead ID, for leads imported from another system (any state)"
            },
            "required": false,
            "description": "Original lead ID, for leads imported from another system (any state)",
            "name": "legacy_id",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Leads",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LeadList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}": {
      "get": {
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One lead with its current evaluation",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Lead",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/evaluations": {
      "get": {
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Evaluation history of a lead, newest first",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Evaluations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvaluationList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/leads/{id}/outcome": {
      "post": {
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Record what happened to the lead: won, lost, … (replaces an earlier outcome)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordOutcomeRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Lead with its outcome",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Leads"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Remove the outcome (the deal was reopened)",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "lead_2Ph6Tc9Ks4Wm1Lx7Qv3Nb8Dr"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Lead without outcome",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Lead"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/contacts": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "People who sent leads, newest first",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": false,
            "name": "email",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Any format; matched by the last 9 digits"
            },
            "required": false,
            "description": "Any format; matched by the last 9 digits",
            "name": "phone",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "vip",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "required": false,
            "name": "blocked",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Original contact ID, for contacts imported from another system"
            },
            "required": false,
            "description": "Original contact ID, for contacts imported from another system",
            "name": "legacy_id",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Contacts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/contacts/{id}": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One contact with lead and outcome counts",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "ctc_7Rm2Kx9Pq4Lz1Wv6Tn3Hb8Dc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Contact",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Contacts"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Mark VIP or blocked, fix name or company, set your metadata",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "ctc_7Rm2Kx9Pq4Lz1Wv6Tn3Hb8Dc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateContactRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Contact"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/contacts/{id}/leads": {
      "get": {
        "tags": [
          "Contacts"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "All leads of this person, newest first",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "ctc_7Rm2Kx9Pq4Lz1Wv6Tn3Hb8Dc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Leads",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactLeadList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations": {
      "get": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "List webhook destinations",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Destinations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DestinationList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Add a webhook: events are POSTed to the URL, signed with Leadveyor-Signature",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDestinationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (includes the signing secret)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DestinationWithSecret"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations/{id}": {
      "get": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Get a destination",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Destination",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destination"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Change URL, events, filter; disable or re-enable",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateDestinationRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Destination"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Delete a destination",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "enum": [
                        "destination"
                      ]
                    },
                    "id": {
                      "type": "string"
                    },
                    "deleted": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "object",
                    "id",
                    "deleted"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations/{id}/rotate-secret": {
      "post": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Issue a new signing secret",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "New secret",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DestinationWithSecret"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations/{id}/test": {
      "post": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Send a destination.test event",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "202": {
            "description": "Test event queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Event"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations/{id}/deliveries": {
      "get": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Delivery log: status, attempts, response",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Deliveries",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/destinations/{id}/deliveries/{deliveryId}/retry": {
      "post": {
        "tags": [
          "Destinations (webhooks)"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Send a delivery again",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "dst_3Jw8Hn5Kq1Tz7Lx2Pv9Rm4Bc"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string"
            },
            "required": true,
            "name": "deliveryId",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Delivery"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events": {
      "get": {
        "tags": [
          "Events"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "Events of the last 30 days, newest first: what changed since…",
        "parameters": [
          {
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "description": "1–100, default 20"
            },
            "required": false,
            "description": "1–100, default 20",
            "name": "limit",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "ID of the last item of the previous page"
            },
            "required": false,
            "description": "ID of the last item of the previous page",
            "name": "starting_after",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Exact type or prefix like lead.*"
            },
            "required": false,
            "description": "Exact type or prefix like lead.*",
            "name": "type",
            "in": "query"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Events",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events/{id}": {
      "get": {
        "tags": [
          "Events"
        ],
        "security": [
          {
            "bearer": []
          }
        ],
        "summary": "One event",
        "parameters": [
          {
            "schema": {
              "type": "string",
              "example": "evt_6Gk2Pq9Tz4Lm1Wx8Rc3Vn7Bd"
            },
            "required": true,
            "name": "id",
            "in": "path"
          },
          {
            "schema": {
              "type": "string",
              "description": "Workspace ID; not needed for workspace-scoped API keys",
              "example": "ws_1Bq7Xn4KpRz9Lc2Vt6Hy0Mde"
            },
            "required": false,
            "description": "Workspace ID; not needed for workspace-scoped API keys",
            "name": "leadveyor-workspace",
            "in": "header"
          }
        ],
        "responses": {
          "200": {
            "description": "Event",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Event"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "Plan, subscription and this period's usage",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Billing"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "Billing"
        ],
        "summary": "Set the spending limit for leads beyond the plan (admin)",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SpendLimitRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Billing"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "Billing"
        ],
        "summary": "This period's usage against the plan",
        "description": "Leads used and included, leads beyond the plan and their cost, broken down by workspace.",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Usage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/checkout": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "Start a subscription (admin): returns a Stripe Checkout link",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Open `url` to pay",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingRedirect"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/plan": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "Change plan (admin): upgrades apply now, downgrades from the next period",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangePlanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Billing",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Billing"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/portal": {
      "post": {
        "tags": [
          "Billing"
        ],
        "summary": "Card, invoices and cancelling (admin): returns a Stripe portal link",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "Open `url`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingRedirect"
                }
              }
            }
          },
          "401": {
            "description": "Not authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {}
}
