{
  "openapi": "3.0.3",
  "info": {
    "title": "Kryptos API",
    "version": "1.0",
    "description": "The Integrations API: create workspaces for your customers with your client ID and secret, then connect their wallets and exchanges and read their transactions, holdings and more with the workspace token. Guide: https://docs.kryptos.io/docs/integrations-api/overview"
  },
  "servers": [
    {
      "url": "https://api-v2.kryptos.io/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Assets",
      "description": "Global asset catalog search — auth required; no workspace context needed"
    },
    {
      "name": "Labels & Types",
      "description": "Canonical transaction labels + transaction types (read-only reference; auth required, no workspace context needed)"
    },
    {
      "name": "Holdings",
      "description": "Portfolio holdings with live prices"
    },
    {
      "name": "Portfolio",
      "description": "DeFi positions, NFTs and liabilities as each exchange or chain reports them"
    },
    {
      "name": "Transactions",
      "description": "Transaction CRUD and bulk operations"
    },
    {
      "name": "Ledgers",
      "description": "Ledger entries (double-entry records)"
    },
    {
      "name": "Tasks",
      "description": "Async job tracking"
    },
    {
      "name": "Providers",
      "description": "Public provider catalog — no auth required"
    },
    {
      "name": "Integrations",
      "description": "Integration account management"
    },
    {
      "name": "Credentials",
      "description": "Credential management and validation"
    },
    {
      "name": "Sync",
      "description": "Sync job management"
    },
    {
      "name": "CSV",
      "description": "CSV/XLSX file uploads"
    },
    {
      "name": "Workspace management",
      "description": "Create and manage your workspaces on connect-api.kryptos.io, authenticated with your client ID and secret."
    }
  ],
  "paths": {
    "/labels": {
      "get": {
        "tags": [
          "Labels & Types"
        ],
        "summary": "List canonical transaction labels (with type + tax event)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "deposit",
                "withdrawal",
                "trade",
                "transfer",
                "payment"
              ]
            },
            "description": "Restrict to labels applicable to this transaction type (common labels Ignore/Failed/Unknown/Spam appear under every type). Omit for all labels."
          }
        ],
        "responses": {
          "200": {
            "description": "List of canonical labels, each with its transaction type and tax event",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/TransactionLabelInfo"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid query params (e.g. unknown type)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorEnvelope"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/labels/types": {
      "get": {
        "tags": [
          "Labels & Types"
        ],
        "summary": "List transaction types (with their labels)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "All transaction types, each with the canonical labels that belong to it",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/TransactionTypeInfo"
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/assets/search": {
      "get": {
        "tags": [
          "Assets"
        ],
        "summary": "Search the global asset catalog",
        "description": "Fuzzy search over the full asset catalog when `q` is provided (typo-tolerant, ranked by 0.7·text relevance + 0.3·CMC popularity), or filter-only ranked by CMC rank then name. With no params, returns the default list — top assets by CMC rank.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Free-text query over symbol + name (enables fuzzy/relevance ranking); category matches only on an exact value (e.g. `fiat`). A pasted contract address resolves to its asset."
          },
          {
            "name": "contractAddress",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact contract-address match (case-insensitive)"
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "crypto",
                "fiat",
                "nft",
                "stablecoin"
              ]
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "chainId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Restrict to assets with a contract on this chain (e.g. ethereum)"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked asset search results",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/AssetSearchItem"
                          }
                        },
                        "total": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "offset": {
                          "type": "integer"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid query parameter"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/holdings": {
      "get": {
        "tags": [
          "Holdings"
        ],
        "summary": "Workspace-wide holdings (with live prices by default)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "rates",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ],
              "default": "true"
            },
            "description": "Include live prices"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "value",
                "quantity",
                "name",
                "24hrChange",
                "txnCount"
              ],
              "default": "value"
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "xstocks"
              ]
            },
            "description": "Ecosystem filter. `all` (or omitted) = no filter. `xstocks` = only xStock (Backed Finance tokenized equity) holdings."
          },
          {
            "name": "assetIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated asset IDs"
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "minValue",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0
            },
            "description": "Hide holdings with market value below this USD threshold"
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "maximum": 1000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Holdings, largest first. Values are in the workspace base currency.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/HoldingItem"
                      }
                    },
                    "totalCount": {
                      "type": "integer",
                      "example": 12
                    },
                    "offset": {
                      "type": "integer",
                      "example": 0
                    },
                    "limit": {
                      "type": "integer",
                      "example": 50
                    },
                    "hasMore": {
                      "type": "boolean",
                      "example": false
                    },
                    "totalValue": {
                      "type": "number",
                      "example": 15234.18,
                      "description": "Value of every holding, before search or paging."
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/holdings/{assetId}": {
      "get": {
        "tags": [
          "Holdings"
        ],
        "summary": "Single asset detail — workspace-wide (always with rates)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "assetId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Holding detail",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/HoldingItem"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/defi": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "DeFi positions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "lending",
                "borrowing",
                "staking",
                "locked",
                "farming",
                "leveraged_farming",
                "reward",
                "trading",
                "derivatives",
                "options_seller",
                "options_buyer",
                "perpetuals",
                "insurance",
                "insurance_seller",
                "insurance_buyer",
                "governance",
                "vesting",
                "other"
              ]
            }
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Wallet filter — integration account id."
          },
          {
            "name": "networkId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Network filter by provider ID (e.g. ethereum, base). Values come from GET /defi/networks."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Free-text search over protocol name."
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Not supported yet: spam marking does not apply to DeFi positions (unlike token/NFT holdings), so this parameter currently has no effect. Reserved for future position-level spam flagging."
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DeFi positions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/DefiPosition"
                      }
                    },
                    "totalCount": {
                      "type": "integer",
                      "example": 12
                    },
                    "offset": {
                      "type": "integer",
                      "example": 0
                    },
                    "limit": {
                      "type": "integer",
                      "example": 50
                    },
                    "hasMore": {
                      "type": "boolean",
                      "example": false
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/defi/totals": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "Workspace-wide DeFi overview totals",
        "description": "Aggregate totals for the DeFi Overview card: total balance (net of debt), borrowed, earned rewards, and count of connected protocols.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Not supported yet: spam marking does not apply to DeFi positions (unlike token/NFT holdings), so this parameter currently has no effect. Reserved for future position-level spam flagging."
          }
        ],
        "responses": {
          "200": {
            "description": "DeFi totals",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "totalBalance": {
                          "type": "number",
                          "example": 5120.4
                        },
                        "borrowed": {
                          "type": "number",
                          "example": 800
                        },
                        "earnedRewards": {
                          "type": "number",
                          "example": 12.5
                        },
                        "connectedProtocols": {
                          "type": "integer",
                          "example": 3
                        },
                        "baseCurrency": {
                          "type": "string",
                          "example": "USD"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/nfts": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "NFT holdings",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "chain",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "collectionId",
            "in": "query",
            "description": "Filter to NFTs in a single collection (SimpleHash collection_id)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "NFTs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/NftItem"
                      }
                    },
                    "totalCount": {
                      "type": "integer",
                      "example": 7
                    },
                    "totalEstimatedValueUsd": {
                      "type": "number",
                      "example": 1830.5
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/nfts/collections": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "NFT holdings grouped by collection",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "chain",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "collectionId",
            "in": "query",
            "description": "Filter to a single collection (SimpleHash collection_id) — combine with limit=1 to fetch one collection reliably",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "NFT collections",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "collectionId": {
                            "type": "string",
                            "example": "boredapeyachtclub"
                          },
                          "name": {
                            "type": "string",
                            "nullable": true,
                            "example": "Bored Ape Yacht Club"
                          },
                          "imageUrl": {
                            "type": "string",
                            "nullable": true
                          },
                          "itemCount": {
                            "type": "integer",
                            "example": 2
                          },
                          "totalValueUsd": {
                            "type": "number",
                            "example": 1500
                          }
                        }
                      }
                    },
                    "totalCount": {
                      "type": "integer",
                      "example": 3
                    },
                    "totalEstimatedValueUsd": {
                      "type": "number",
                      "example": 1830.5
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/nfts/{contractAddress}/{tokenId}": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "Single NFT detail — workspace-wide",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "contractAddress",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "The NFT",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/NftItem"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/liabilities": {
      "get": {
        "tags": [
          "Portfolio"
        ],
        "summary": "Liability positions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Liabilities (borrowed amounts) as the exchange or protocol reports them",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "integrationId": {
                            "type": "string"
                          },
                          "walletId": {
                            "type": "string"
                          },
                          "assetId": {
                            "type": "string",
                            "nullable": true
                          },
                          "assetRaw": {
                            "type": "object",
                            "additionalProperties": true
                          },
                          "quantity": {
                            "type": "string",
                            "example": "250.5",
                            "description": "Decimal string."
                          },
                          "liabilityType": {
                            "type": "string",
                            "example": "Margin Borrow"
                          },
                          "isEstimation": {
                            "type": "boolean",
                            "example": false
                          },
                          "updatedAt": {
                            "type": "string",
                            "format": "date-time"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer",
                      "example": 1
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions": {
      "get": {
        "tags": [
          "Transactions"
        ],
        "summary": "List transactions with ledgers",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "labels",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "types",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated canonical types: deposit,withdrawal,trade,transfer,payment"
          },
          {
            "name": "walletIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "syncIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated sync run ids (max 100); txns with any leg written by one of these syncs. A re-sync does not re-stamp rows that already exist; legs with no sync id (manual entries, legacy or edited detected transfers) never match"
          },
          {
            "name": "importSourceTypes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated: API,CSV,Manual"
          },
          {
            "name": "isDefiTrx",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "isNFTTrx",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "isManual",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "isEdited",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "assetIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated UUIDs"
          },
          {
            "name": "fromAddresses",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "toAddresses",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "addresses",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; matches either side (sender or receiver)"
          },
          {
            "name": "providers",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "ledgerTypes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated: incoming,outgoing,fee"
          },
          {
            "name": "tags",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "hasMissingPrice",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "hasMissingAsset",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "isMissingTransaction",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "hasComments",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "With/without comments: true = has at least one comment, false = none"
          },
          {
            "name": "isHighPnLReviewed",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Reconciliation review flag: filter reviewed/unreviewed high-PnL transactions"
          },
          {
            "name": "isUncategorisedIgnored",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Reconciliation review flag: filter ignored uncategorized deposits/withdrawals"
          },
          {
            "name": "isMissingPriceIgnored",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Reconciliation review flag: filter ignored missing-price transactions"
          },
          {
            "name": "minTotalGains",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "High-PnL threshold: matches transactions whose gain OR loss magnitude is at least this value (totalGains >= value OR totalGains <= -value). Used by the high-PnL reconciliation view."
          },
          {
            "name": "minValue",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "Min net fiat value (transactions.netValue.fiatValue). Compared as numeric, so transactions whose fiatValue is null (any leg unpriced) are excluded, not treated as 0."
          },
          {
            "name": "maxValue",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "Max net fiat value (transactions.netValue.fiatValue). Compared as numeric, so transactions whose fiatValue is null (any leg unpriced) are excluded, not treated as 0."
          },
          {
            "name": "notLabels",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude these labels"
          },
          {
            "name": "notTypes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude these types"
          },
          {
            "name": "notImportSourceTypes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude API/CSV/Manual"
          },
          {
            "name": "notTags",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude txns carrying any of these tags"
          },
          {
            "name": "notWalletIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude txns with any transfer on these accounts"
          },
          {
            "name": "notSyncIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated (max 100); exclude txns with any leg produced by these syncs"
          },
          {
            "name": "notAssetIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude txns with any transfer in these assets/currencies"
          },
          {
            "name": "notProviders",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude txns with any transfer from these providers"
          },
          {
            "name": "notLedgerTypes",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude txns with any transfer of these ledger types"
          },
          {
            "name": "notFromAddresses",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude by sender address"
          },
          {
            "name": "notToAddresses",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated; exclude by recipient address"
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "trxId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Exact match on the transaction's own id (the `id` field returned in responses)."
          },
          {
            "name": "trxHash",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact match on the platform-supplied transaction id — a CEX order id or an on-chain transaction hash, depending on source."
          },
          {
            "name": "coaTagStatus",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "tagged",
                "partial",
                "untagged"
              ]
            },
            "description": "COA tagging filter (enterprise). A leg is complete when it carries the COA side(s) its transaction type requires — both for deposit/withdrawal/payment, one for trade/transfer legs, and always both for a fee leg. tagged = every leg is complete, fee legs included; partial = some work is done and something is still missing; untagged = nothing is done. Progress is judged on non-fee legs only (fee codes are assigned automatically, so an auto-coded gas leg is not 'started'), falling back to the fee legs on a fee-only transaction. Ignored for retail."
          },
          {
            "name": "coaSyncStatus",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "synced",
                "unsynced"
              ]
            },
            "description": "COA ERP-sync filter (enterprise): synced = pushed; unsynced = journal exists, not yet pushed."
          },
          {
            "name": "coaTagged",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Deprecated — use coaTagStatus (true→tagged, false→untagged)."
          },
          {
            "name": "syncedToERP",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Deprecated — use coaSyncStatus (true→synced, false→unsynced)."
          },
          {
            "name": "includeSpam",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include spam-labelled transactions. Default excludes them."
          },
          {
            "name": "includeIgnored",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include Ignore-labelled transactions. Default excludes them."
          },
          {
            "name": "startTime",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "Unix ms"
          },
          {
            "name": "endTime",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "Unix ms"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 1000,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "timestamp",
                "netValue",
                "totalGains",
                "createdAt"
              ]
            },
            "description": "Nullable columns (`netValue`, `totalGains`) always sort NULLS LAST in both directions, so unpriced/no-gain transactions never bury the real values at the top of a `desc` page."
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction list (page-based). meta.total is the exact filter-aware row count for pagination; meta.hasMore indicates a next page.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TransactionWithLedgers"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "example": 50
                        },
                        "offset": {
                          "type": "integer",
                          "example": 0
                        },
                        "hasMore": {
                          "type": "boolean",
                          "description": "True if another page exists (computed via limit+1, not a COUNT)."
                        },
                        "total": {
                          "type": "integer",
                          "description": "Exact count of rows matching the current filters (short-cached), for page-count pagination."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      },
      "post": {
        "tags": [
          "Transactions"
        ],
        "summary": "Create manual transaction",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "timestamp",
                  "label"
                ],
                "properties": {
                  "timestamp": {
                    "type": "number",
                    "description": "Transaction time as Unix epoch in milliseconds.",
                    "example": 1718800000000
                  },
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Transaction label / classification (required, non-empty).",
                    "example": "Trade"
                  },
                  "description": {
                    "type": "string",
                    "description": "Optional free-text description."
                  },
                  "notes": {
                    "type": "string",
                    "description": "Optional internal notes."
                  },
                  "incomingAssets": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/IncomingAsset"
                    },
                    "default": [],
                    "description": "Asset legs received in this transaction."
                  },
                  "outgoingAssets": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/OutgoingAsset"
                    },
                    "default": [],
                    "description": "Asset legs sent in this transaction."
                  },
                  "fee": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/FeeAsset"
                    },
                    "default": [],
                    "description": "Fee legs for this transaction."
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Free-form tags.",
                    "example": [
                      "defi",
                      "q2-2024"
                    ]
                  },
                  "clonedFrom": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Id of the transaction this one copies (Clone). Records the create in the activity log as a clone of that transaction."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Transaction created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "savedCount": {
                          "type": "integer",
                          "example": 2,
                          "description": "Transactions saved."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/bulk": {
      "patch": {
        "tags": [
          "Transactions"
        ],
        "summary": "Bulk update transactions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids",
                  "data"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "description": "Transaction ids to update (at least one).",
                    "example": [
                      "11111111-1111-1111-1111-111111111111"
                    ]
                  },
                  "data": {
                    "type": "object",
                    "description": "Fields to apply to every listed transaction. All optional. If ONLY tags is sent, the update skips isEdited and the balance-recompute trigger — tags are a free-form organizational label and never affect balances or cost basis. Tags still survive a wallet resync.",
                    "properties": {
                      "label": {
                        "type": "string",
                        "minLength": 1,
                        "description": "New label.",
                        "example": "Trade"
                      },
                      "description": {
                        "type": "string",
                        "description": "New description."
                      },
                      "notes": {
                        "type": "string",
                        "description": "New notes."
                      },
                      "tags": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        },
                        "description": "Replacement tag list."
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Update count",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "updatedCount": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      },
      "delete": {
        "tags": [
          "Transactions"
        ],
        "summary": "Bulk delete transactions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "description": "Transaction ids to delete (at least one).",
                    "example": [
                      "11111111-1111-1111-1111-111111111111"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transactions deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deletedCount": {
                          "type": "integer",
                          "example": 2,
                          "description": "Transactions deleted."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/batch": {
      "post": {
        "tags": [
          "Transactions"
        ],
        "summary": "Batch write transactions (import)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "transactions"
                ],
                "properties": {
                  "transactions": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/BatchTransaction"
                    },
                    "minItems": 1,
                    "description": "Transactions to import (at least one)."
                  },
                  "baseCurrency": {
                    "type": "string",
                    "description": "Base currency applied to legs that omit their own.",
                    "example": "USD"
                  },
                  "splitFrom": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Id of the transaction these were split from (Split Amount). Records the write in the activity log as a split of that transaction; it does not delete the original."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Batch written",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "savedCount": {
                          "type": "integer",
                          "example": 2,
                          "description": "Transactions saved (new or updated)."
                        },
                        "errorCount": {
                          "type": "integer",
                          "example": 0,
                          "description": "Transactions that failed to process."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/{id}": {
      "get": {
        "tags": [
          "Transactions"
        ],
        "summary": "Get transaction with ledgers",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction detail. Unlike the list endpoint, coaJournal includes lines (enterprise only).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TransactionWithLedgers"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      },
      "patch": {
        "tags": [
          "Transactions"
        ],
        "summary": "Update transaction label/notes/tags, or toggle a reconciliation review flag",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Partial update. All fields optional. If ONLY tags and/or the three review-flag fields (isUncategorisedIgnored / isHighPnLReviewed / isMissingPriceIgnored) are sent — no timestamp/label/description/notes — the update skips isEdited and the balance-recompute trigger. Tags are a free-form organizational label and the review flags are dismiss/un-dismiss toggles for the /reconciliation review page; neither affects balances or cost basis. Tags still survive a wallet resync.",
                "properties": {
                  "label": {
                    "type": "string",
                    "minLength": 1,
                    "description": "New label.",
                    "example": "Trade"
                  },
                  "description": {
                    "type": "string",
                    "description": "New description."
                  },
                  "notes": {
                    "type": "string",
                    "description": "New internal notes."
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Replacement tag list."
                  },
                  "isUncategorisedIgnored": {
                    "type": "boolean",
                    "description": "Dismiss/un-dismiss from the reconciliation uncategorized count (/reconciliation/summary)."
                  },
                  "isHighPnLReviewed": {
                    "type": "boolean",
                    "description": "Dismiss/un-dismiss from the reconciliation high-pnl count (/reconciliation/summary)."
                  },
                  "isMissingPriceIgnored": {
                    "type": "boolean",
                    "description": "Dismiss/un-dismiss from the reconciliation 'missing-prices' list."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated transaction. Its ledgers are not included: read them with GET /transactions/{id}.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TransactionWithLedgers"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      },
      "delete": {
        "tags": [
          "Transactions"
        ],
        "summary": "Delete transaction",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/{id}/ledgers": {
      "get": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Get transaction's ledger entries",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "The transaction's ledger entries, with their assets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TransactionLedgerLeg"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/{id}/ledgers/bulk": {
      "patch": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Bulk update ledger entries for a transaction",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids",
                  "data"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "description": "Ledger entry ids to update (at least one).",
                    "example": [
                      "22222222-2222-2222-2222-222222222222"
                    ]
                  },
                  "data": {
                    "type": "object",
                    "description": "Fields to apply to every listed ledger entry. All optional. Changing assetId, price, quantity or baseCurrency reprices the entries and recomputes each affected transaction netValue; a supplied price is applied even when a leg's asset is still unresolved.",
                    "properties": {
                      "assetId": {
                        "type": "string",
                        "format": "uuid",
                        "description": "Reassign the matched asset."
                      },
                      "price": {
                        "$ref": "#/components/schemas/PriceModel"
                      },
                      "quantity": {
                        "type": "string",
                        "description": "New quantity (decimal string).",
                        "example": "1.5"
                      },
                      "label": {
                        "type": "string",
                        "description": "New label."
                      },
                      "description": {
                        "type": "string",
                        "description": "New description."
                      },
                      "internalLabel": {
                        "type": "string",
                        "description": "New internal sub-label."
                      },
                      "fromAccount": {
                        "$ref": "#/components/schemas/AccountType"
                      },
                      "toAccount": {
                        "$ref": "#/components/schemas/AccountType"
                      },
                      "baseCurrency": {
                        "type": "string",
                        "description": "Currency the supplied price is denominated in. Not stored verbatim — the entry is always pinned to the workspace reporting currency, and any price is FX-converted onto it.",
                        "example": "USD"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ledger entries updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "updatedCount": {
                          "type": "integer",
                          "example": 2,
                          "description": "Ledger entries updated."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      },
      "delete": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Bulk delete ledger entries for a transaction",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "ids"
                ],
                "properties": {
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "description": "Ledger entry ids to delete (at least one).",
                    "example": [
                      "22222222-2222-2222-2222-222222222222"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Ledger entries deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "deletedCount": {
                          "type": "integer",
                          "example": 2,
                          "description": "Ledger entries deleted."
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/transactions/{id}/ledgers/{ledgerId}": {
      "patch": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Update a single ledger entry",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Partial update of a single ledger entry. All fields optional. Changing assetId, price, quantity or baseCurrency reprices the entry and recomputes the transaction netValue; a supplied price is applied even when the asset is still unresolved.",
                "properties": {
                  "assetId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Reassign the matched asset."
                  },
                  "price": {
                    "$ref": "#/components/schemas/PriceModel"
                  },
                  "quantity": {
                    "type": "string",
                    "description": "New quantity (decimal string).",
                    "example": "1.5"
                  },
                  "label": {
                    "type": "string",
                    "description": "New label."
                  },
                  "description": {
                    "type": "string",
                    "description": "New description."
                  },
                  "internalLabel": {
                    "type": "string",
                    "description": "New internal sub-label."
                  },
                  "fromAccount": {
                    "$ref": "#/components/schemas/AccountType"
                  },
                  "toAccount": {
                    "$ref": "#/components/schemas/AccountType"
                  },
                  "baseCurrency": {
                    "type": "string",
                    "description": "Currency the supplied price is denominated in. Not stored verbatim — the entry is always pinned to the workspace reporting currency, and any price is FX-converted onto it.",
                    "example": "USD"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated ledger entry",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TransactionLedgerLeg"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/ledgers": {
      "get": {
        "tags": [
          "Ledgers"
        ],
        "summary": "List ledger entries across all transactions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "transactionIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "assetIds",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "unresolvedSymbols",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated. Matches ledgers with assetId=NULL whose raw asset symbol is one of these — for unresolved assets that have no real assetId to filter by (e.g. from /reconciliation/missing-balances rows with assetId: null)."
          },
          {
            "name": "walletIds",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated"
          },
          {
            "name": "types",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "providers",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "labels",
            "in": "query",
            "description": "Comma-separated ledger labels to include (exact, case-sensitive; canonical names from GET /labels). Matches the leg label itself, which can differ from the transaction label (edited or fee legs).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "notLabels",
            "in": "query",
            "description": "Comma-separated ledger labels to exclude (NULL-label legs are kept).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "hasMissingPrice",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "hasMissingAsset",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "ltAfterBalance",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d{1,4})?$"
            },
            "example": "0",
            "description": "Only ledgers whose afterBalance is strictly less than this value. Sent as a decimal string to preserve full precision. `ltAfterBalance=0` returns negative balances. Rows with no afterBalance are excluded."
          },
          {
            "name": "gtAfterBalance",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^-?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d{1,4})?$"
            },
            "description": "Only ledgers whose afterBalance is strictly greater than this value. Sent as a decimal string to preserve full precision. Combine with `ltAfterBalance` for a range. Rows with no afterBalance are excluded."
          },
          {
            "name": "startTime",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "endTime",
            "in": "query",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "maximum": 1000
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "timestamp",
                "createdAt"
              ]
            }
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ledger list with meta",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/TransactionLedgerLeg"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "offset": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/ledgers/{id}": {
      "get": {
        "tags": [
          "Ledgers"
        ],
        "summary": "Get ledger entry by ID",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Ledger entry",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/TransactionLedgerLeg"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/tasks": {
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "List tasks for workspace",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkspaceId"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "running",
                "completed",
                "failed",
                "cancelled"
              ]
            }
          },
          {
            "name": "operationType",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Task list",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Task"
                          }
                        },
                        "meta": {
                          "type": "object",
                          "properties": {
                            "total": {
                              "type": "integer"
                            },
                            "limit": {
                              "type": "integer"
                            },
                            "offset": {
                              "type": "integer"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/tasks/{taskId}": {
      "get": {
        "tags": [
          "Tasks"
        ],
        "summary": "Get task by ID",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Task",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Task"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/tasks/{taskId}/cancel": {
      "post": {
        "tags": [
          "Tasks"
        ],
        "summary": "Cancel a running task",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/WorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "The cancelled task",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Task"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth",
          "api-key"
        ]
      }
    },
    "/providers": {
      "get": {
        "tags": [
          "Providers"
        ],
        "summary": "List providers",
        "security": [],
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "exchange",
                "blockchain",
                "wallet",
                "service",
                "csv",
                "custom"
              ]
            }
          },
          {
            "name": "featured",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "isWorking",
            "in": "query",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Provider list",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "providers": {
                              "type": "array",
                              "items": {
                                "$ref": "#/components/schemas/Provider"
                              }
                            },
                            "pagination": {
                              "$ref": "#/components/schemas/IntegrationPagination"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "public"
        ]
      }
    },
    "/providers/{id}": {
      "get": {
        "tags": [
          "Providers"
        ],
        "summary": "Get provider by ID",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Provider detail",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Provider"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "public"
        ]
      }
    },
    "/integrations": {
      "get": {
        "tags": [
          "Integrations"
        ],
        "summary": "List integrations",
        "parameters": [
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          },
          {
            "name": "providerId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "providerType",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "exchange",
                "blockchain",
                "wallet",
                "service",
                "aggregator",
                "custom"
              ]
            },
            "description": "Filter by the provider's type. `custom` is not a provider type — it matches integrations flagged `isCustomWallet` instead."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated account statuses to include, e.g. `active,pending`. Values: pending, active, inactive (archived), suspended, error."
          },
          {
            "name": "excludeStatus",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated account statuses to exclude, e.g. `inactive`. Combinable with `status`."
          },
          {
            "name": "syncStatus",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "completed",
                "partially_synced",
                "in_progress",
                "failed",
                "cancelled",
                "deletion_queued",
                "delete_in_progress",
                "deletion_stranded"
              ]
            },
            "description": "Filter by sync state. `in_progress` means the integration's *latest* sync (within the last 24h) is still non-terminal, read live off the sync history and matching the `latestSync` returned on the row. The terminal values — `completed`, `partially_synced`, `failed`, `cancelled` — report the last *finished* sync and exclude anything currently syncing, so they never overlap `in_progress`. An integration that has never synced matches none of them.\n\nThe deletion values describe an account whose delete was requested but hasn't finished, read live off its delete task: `deletion_queued` is waiting to be picked up, `delete_in_progress` is being wiped, and `deletion_stranded` is a delete that will never finish on its own — the worker died mid-wipe, or the job was never queued — and needs an operator, since nothing retries a delete."
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Case-insensitive substring match on alias, integration id, provider id/name/public name, wallet address or account name (credentials), and connection addresses."
          },
          {
            "name": "hasMissingBalance",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "When true, returns only integrations with at least one calculated-vs-reported balance mismatch. Filters rows out; to flag them instead, read the `hasMissingBalance` field on each item."
          },
          {
            "name": "sortBy",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "alias",
                "addedOn",
                "createdAt",
                "updatedAt",
                "lastSyncedAt",
                "netValue",
                "txnCount"
              ],
              "default": "createdAt"
            },
            "description": "`netValue` and `txnCount` sort on the precomputed client_metadata values, so integrations not yet recomputed sort as null. `lastSyncedAt` places never-synced integrations LAST in both directions (changed: `sortOrder=desc` previously returned them first, on Postgres's default NULLS FIRST). Every sort is tie-broken by `id desc` so pagination is stable."
          },
          {
            "name": "sortOrder",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "fields",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "summary"
              ]
            },
            "description": "When set to 'summary', returns a trimmed shape per integration (id, alias, providerId, providerName, providerPublicName, logo, transactionCount, address) instead of the full record — for lightweight menu/dropdown listings."
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Integration list",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "integrations": {
                              "type": "array",
                              "items": {
                                "$ref": "#/components/schemas/Integration"
                              }
                            },
                            "pagination": {
                              "$ref": "#/components/schemas/IntegrationPagination"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      },
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Create integration (auto-triggers sync for API integrations)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId",
                  "credentialKind"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace that will own the integration.",
                    "example": "ws_3f9a2c"
                  },
                  "providerId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "ID of the provider (exchange/blockchain/wallet) to connect. Required unless isCustomWallet is true — custom wallets are attached to a sentinel provider automatically.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "alias": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "nullable": true,
                    "description": "Unique, human-friendly name for this integration within the workspace (optional).",
                    "example": "Binance Main"
                  },
                  "credentialKind": {
                    "type": "string",
                    "description": "Authentication method used to connect — determines the shape of `credentialData`. api_key: key/secret pair; address: read-only on-chain address; account_name: username (+ optional password); csv: CSV-file import; none: no credentials.",
                    "enum": [
                      "api_key",
                      "address",
                      "account_name",
                      "csv",
                      "none"
                    ],
                    "example": "api_key"
                  },
                  "credentialData": {
                    "description": "Credential payload — shape MUST match `credentialKind`. Omit (or `{}`) for csv/none.",
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/ApiKeyCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AddressCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AccountNameCredential"
                      },
                      {
                        "type": "object",
                        "description": "Empty object for csv / none kinds"
                      }
                    ]
                  },
                  "config": {
                    "$ref": "#/components/schemas/IntegrationConfig"
                  },
                  "isCustomWallet": {
                    "type": "boolean",
                    "default": false,
                    "description": "Mark this as a user-defined custom (manual) wallet integration."
                  },
                  "skipInitialSync": {
                    "type": "boolean",
                    "default": false,
                    "description": "When true, do not auto-trigger a sync on creation (API integrations only)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Integration created. `data` is the integration, plus a `sync` field carrying the auto-triggered sync (null when no sync ran, e.g. skipInitialSync or non-API).",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "allOf": [
                            {
                              "$ref": "#/components/schemas/Integration"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "sync": {
                                  "nullable": true,
                                  "allOf": [
                                    {
                                      "$ref": "#/components/schemas/Sync"
                                    }
                                  ]
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Validation error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/sync-status": {
      "get": {
        "tags": [
          "Integrations"
        ],
        "summary": "Most recent sync time for a workspace",
        "parameters": [
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Most recent lastSyncedAt in scope",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "lastSyncedAt": {
                              "type": "string",
                              "format": "date-time",
                              "nullable": true,
                              "description": "Null if nothing has synced yet."
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/integrations/test-credentials": {
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Test credentials before creating an integration (pre-create flow)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "providerId",
                  "credential"
                ],
                "properties": {
                  "providerId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Provider to validate the credential against.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "credential": {
                    "description": "Credential payload to test. Must be one of the secret credential shapes (api_key / address / account_name) — empty objects not accepted here.",
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/ApiKeyCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AddressCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AccountNameCredential"
                      }
                    ]
                  },
                  "chainId": {
                    "type": "string",
                    "description": "Required for chain-parameterised providers (e.g. EVM).",
                    "example": "1"
                  },
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "If provided, the credential is checked against existing integrations in this workspace for the same provider — a matching credential (same address / accountName / apiKey) returns 409 instead of validating. Omit to skip the duplicate check.",
                    "example": "ws_3f9a2c"
                  },
                  "skipDuplicateCheck": {
                    "type": "boolean",
                    "description": "Set true to bypass the duplicate-credential check even when workspaceId is provided.",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "error": {
                      "type": "string"
                    },
                    "details": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "An integration with these credentials already exists in the given workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "example": "CREDENTIALS_ALREADY_EXISTS"
                    },
                    "existingIntegrationId": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/batch-delete": {
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Delete multiple integrations in one request",
        "description": "Soft-deletes (marks `deleting`) each integration and publishes a cleanup task to the delete-worker. If publishing fails for an integration, it is reported in `failed` (not `deleted`) — the account is marked deleting but cleanup was not queued.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId",
                  "integrationIds"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "example": "ws_3f9a2c"
                  },
                  "integrationIds": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "type": "string"
                    }
                  },
                  "maxBatchSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 50,
                    "default": 50,
                    "description": "Request is rejected if integrationIds exceeds this size."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Batch delete result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "deleted": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "integrationId": {
                                "type": "string"
                              },
                              "alias": {
                                "type": "string"
                              }
                            }
                          }
                        },
                        "failed": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "integrationId": {
                                "type": "string"
                              },
                              "alias": {
                                "type": "string"
                              },
                              "error": {
                                "type": "string"
                              }
                            }
                          }
                        },
                        "total": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed, or batch exceeds maxBatchSize"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/{id}": {
      "get": {
        "tags": [
          "Integrations"
        ],
        "summary": "Get integration by ID",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Integration detail",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Integration"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      },
      "patch": {
        "tags": [
          "Integrations"
        ],
        "summary": "Update integration",
        "description": "Alias changes are processed asynchronously via a pub/sub worker — the response returns immediately with a taskId instead of the updated integration. All other fields update synchronously as before.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the integration.",
                    "example": "ws_3f9a2c"
                  },
                  "alias": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "New unique alias for the integration. If it differs from the current alias, the update runs asynchronously — see the 202 response.",
                    "example": "Binance Main"
                  },
                  "syncEnabled": {
                    "type": "boolean",
                    "description": "Enable or disable scheduled/automatic syncs."
                  },
                  "accountStatus": {
                    "type": "string",
                    "description": "Override the integration lifecycle status.",
                    "enum": [
                      "pending",
                      "active",
                      "inactive",
                      "suspended",
                      "deleting",
                      "deleted",
                      "error"
                    ],
                    "example": "active"
                  },
                  "config": {
                    "$ref": "#/components/schemas/IntegrationConfig"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated integration",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "$ref": "#/components/schemas/Integration"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      },
      "delete": {
        "tags": [
          "Integrations"
        ],
        "summary": "Delete integration (soft delete, triggers data wipe worker)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/{id}/test-credentials": {
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Test credentials for existing integration (post-create flow)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the integration.",
                    "example": "ws_3f9a2c"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Validation result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "error": {
                      "type": "string"
                    },
                    "details": {
                      "type": "object",
                      "properties": {
                        "oauthRefreshed": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The stored OAuth grant is revoked or expired (`code: REAUTH_REQUIRED`) — the user must reconnect the integration. Distinct from a 500, which means the refresh failed on our side and reconnecting would not help.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string",
                      "example": "REAUTH_REQUIRED"
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/{id}/sync": {
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Trigger incremental sync for an integration",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the integration.",
                    "example": "ws_3f9a2c"
                  },
                  "syncKind": {
                    "type": "string",
                    "description": "Kind of sync to run. api: live API fetch; csv: CSV ingestion; prices: price refresh.",
                    "enum": [
                      "api",
                      "csv",
                      "prices"
                    ],
                    "default": "api"
                  },
                  "triggerSource": {
                    "type": "string",
                    "description": "What initiated the sync (used for auditing/telemetry).",
                    "enum": [
                      "create_account",
                      "manual",
                      "retry",
                      "csv_upload",
                      "scheduled",
                      "reconnect"
                    ],
                    "default": "manual"
                  },
                  "syncMode": {
                    "type": "string",
                    "description": "Sync strategy. incremental: resume from latest ledger. resync_from_start: delete this integration's prior data, then re-fetch from scratch. resync: accepted for backward compatibility, normalized to incremental. Defaults to incremental when omitted.",
                    "enum": [
                      "incremental",
                      "resync",
                      "resync_from_start"
                    ],
                    "default": "incremental"
                  },
                  "functions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Sync only these provider functions (e.g. one). Empty/omitted = all enabled. Unknown names → 400.",
                    "example": [
                      "spot_trades"
                    ]
                  },
                  "startTime": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Unix ms window start (override).",
                    "example": 1704067200000
                  },
                  "endTime": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Unix ms window end (defaults to now).",
                    "example": 1735689600000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Sync job queued",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Sync"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Unknown function name(s) for this provider"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/integrations/{id}/resync": {
      "post": {
        "tags": [
          "Integrations"
        ],
        "summary": "Resync an integration (incremental by default; from scratch or over a given time range on request)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the integration.",
                    "example": "ws_3f9a2c"
                  },
                  "syncMode": {
                    "type": "string",
                    "enum": [
                      "incremental",
                      "resync",
                      "resync_from_start"
                    ],
                    "default": "incremental",
                    "description": "incremental resumes from latest ledger. resync_from_start deletes prior data then re-fetches — destructive, so it must be asked for explicitly and is no longer this endpoint's default. resync is accepted for backward compatibility and normalized to incremental."
                  },
                  "startTime": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Unix ms — replaces the per-function incremental cursor rather than flooring it, so it can reach back behind data already stored. This is the non-destructive way to backfill a gap; resync_from_start wipes first.",
                    "example": 1704067200000
                  },
                  "endTime": {
                    "type": "integer",
                    "minimum": 0,
                    "description": "Unix ms — defaults to now.",
                    "example": 1735689600000
                  },
                  "functions": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "minItems": 1,
                    "description": "Narrow to specific provider functions (must be non-empty if provided).",
                    "example": [
                      "spot_trades"
                    ]
                  },
                  "triggerSource": {
                    "type": "string",
                    "description": "What initiated the resync (used for auditing/telemetry).",
                    "enum": [
                      "create_account",
                      "manual",
                      "retry",
                      "csv_upload",
                      "scheduled",
                      "reconnect",
                      "webhook"
                    ],
                    "example": "manual"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Resync job queued",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Sync"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid syncMode or functions"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/credentials/validate": {
      "post": {
        "tags": [
          "Credentials"
        ],
        "summary": "Validate credentials without saving",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId",
                  "providerId",
                  "credentialKind",
                  "credentialData"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace context for the validation.",
                    "example": "ws_3f9a2c"
                  },
                  "providerId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Provider to validate the credential against.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "credentialKind": {
                    "type": "string",
                    "description": "Authentication method — determines the shape of `credentialData`.",
                    "enum": [
                      "api_key",
                      "address",
                      "account_name",
                      "csv",
                      "none"
                    ],
                    "example": "api_key"
                  },
                  "credentialData": {
                    "description": "Credential payload — shape MUST match `credentialKind` (`{}` for csv/none).",
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/ApiKeyCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AddressCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AccountNameCredential"
                      },
                      {
                        "type": "object",
                        "description": "Empty object for csv / none kinds"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The credentials work",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "valid": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "example": "Credentials are valid"
                        },
                        "details": {
                          "type": "object",
                          "additionalProperties": true,
                          "description": "Provider-specific detail, when there is any."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/credentials/{integrationId}": {
      "put": {
        "tags": [
          "Credentials"
        ],
        "summary": "Update credentials for an integration (validates before storing)",
        "parameters": [
          {
            "name": "integrationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId",
                  "credentialKind",
                  "credentialData"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the integration.",
                    "example": "ws_3f9a2c"
                  },
                  "credentialKind": {
                    "type": "string",
                    "description": "Authentication method — determines the shape of `credentialData`.",
                    "enum": [
                      "api_key",
                      "address",
                      "account_name",
                      "csv",
                      "none"
                    ],
                    "example": "api_key"
                  },
                  "credentialData": {
                    "description": "New credential payload — shape MUST match `credentialKind` (`{}` for csv/none).",
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/ApiKeyCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AddressCredential"
                      },
                      {
                        "$ref": "#/components/schemas/AccountNameCredential"
                      },
                      {
                        "type": "object",
                        "description": "Empty object for csv / none kinds"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Credentials saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "message": {
                          "type": "string",
                          "example": "Credentials updated successfully"
                        },
                        "credentialId": {
                          "type": "string",
                          "format": "uuid"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid credentials"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/credentials/chains": {
      "get": {
        "tags": [
          "Credentials"
        ],
        "summary": "Detect active EVM chains for a wallet address",
        "description": "Detects the EVM chains a wallet address has activity on. Takes the address directly — no integration lookup required.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          },
          {
            "name": "address",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Wallet address to detect chains for"
          },
          {
            "name": "chain",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional chain id to exclude from results"
          }
        ],
        "responses": {
          "200": {
            "description": "Detected chains",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "chains": {
                              "type": "array",
                              "items": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/credentials/{integrationId}/status": {
      "get": {
        "tags": [
          "Credentials"
        ],
        "summary": "Check credential validity / expiry status",
        "parameters": [
          {
            "name": "integrationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          }
        ],
        "responses": {
          "200": {
            "description": "Credential status",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "status": {
                              "type": "string",
                              "enum": [
                                "valid",
                                "expired",
                                "invalid"
                              ]
                            },
                            "expired": {
                              "type": "boolean"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/csv/upload": {
      "post": {
        "tags": [
          "CSV"
        ],
        "summary": "Upload one or more CSV/TSV/XLSX files or ZIPs (storage only — does NOT start processing)",
        "description": "Stores the uploaded file(s) and records each as `uploaded`. Processing/ingestion is NOT triggered here — call `POST /csv/sync` with the returned uploadIds to start it. Files are stored independently, so one bad file is reported in `failures` without sinking the rest of the batch.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "files",
                  "workspaceId",
                  "integrationId",
                  "providerId"
                ],
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    },
                    "description": "One or more CSV, TSV, XLS or XLSX files, or ZIPs of them (field name `files`, max 100 MB each, default max 20 files — configurable via CSV_MAX_FILES). A TSV is stored as CSV; a ZIP becomes one upload per CSV/TSV/Excel file inside (at most 20, 100 MB unpacked); a ZIP that cannot be read is reported in `failures`."
                  },
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace that will own the uploaded files.",
                    "example": "ws_3f9a2c"
                  },
                  "integrationId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "CSV integration the files belong to.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "providerId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Provider whose CSV format these files use.",
                    "example": "7a2e1d3c-5b4a-4f1e-8c2a-2f3e4d5c6b7a"
                  },
                  "timezone": {
                    "type": "string",
                    "default": "UTC",
                    "description": "IANA timezone used to parse dates in the CSV rows.",
                    "example": "Europe/London"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "File(s) stored (not yet processing)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "uploads": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "uploadId": {
                                    "type": "string"
                                  },
                                  "fileName": {
                                    "type": "string"
                                  },
                                  "fileSize": {
                                    "type": "integer"
                                  },
                                  "fileType": {
                                    "type": "string",
                                    "example": "csv"
                                  },
                                  "status": {
                                    "type": "string",
                                    "example": "uploaded"
                                  }
                                }
                              }
                            },
                            "failures": {
                              "type": "array",
                              "description": "Per-file storage failures (the rest still succeeded)",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "fileName": {
                                    "type": "string"
                                  },
                                  "error": {
                                    "type": "string"
                                  }
                                }
                              }
                            },
                            "message": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid file(s), too many files, or missing fields"
          },
          "413": {
            "description": "File too large"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/upload-url": {
      "post": {
        "tags": [
          "CSV"
        ],
        "summary": "Get a signed URL to upload one CSV/XLS/XLSX file without multipart",
        "description": "Upload in three steps, for clients that send the file to storage themselves: (1) this call returns a 15-minute signed PUT URL for a server-chosen path in the integration’s upload folder; (2) PUT the file to `uploadUrl` with header `Content-Type: <contentType>`; (3) call `POST /csv/uploads/register` with `filePath`. Size is checked at register (`maxBytes`).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "integrationId",
                  "fileName"
                ],
                "properties": {
                  "integrationId": {
                    "type": "string",
                    "description": "Integration the file belongs to (must be in the workspace)."
                  },
                  "fileName": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "File name ending in .csv, .xls or .xlsx. Directories and characters outside [A-Za-z0-9._-] are dropped.",
                    "example": "binance-trades-2024.xlsx"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signed PUT URL",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "uploadUrl": {
                              "type": "string"
                            },
                            "filePath": {
                              "type": "string",
                              "example": "csv-uploads/ws_3f9a2c/8b1f6c2e/1760270000000-binance-trades-2024.xlsx"
                            },
                            "contentType": {
                              "type": "string"
                            },
                            "maxBytes": {
                              "type": "integer"
                            },
                            "expiresAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "fileName is not .csv, .xls or .xlsx (`INVALID_FILE_TYPE`)"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/uploads/register": {
      "post": {
        "tags": [
          "CSV"
        ],
        "summary": "Record a file PUT to a /csv/upload-url URL as an upload",
        "description": "Creates the same `uploaded` record as `POST /csv/upload` for a file already in storage. Processing is not triggered — call `POST /csv/sync` with the returned uploadId.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "integrationId",
                  "providerId",
                  "filePath"
                ],
                "properties": {
                  "integrationId": {
                    "type": "string"
                  },
                  "providerId": {
                    "type": "string",
                    "description": "The integration's provider, or 'bulk' for a Kryptos bulk-format file."
                  },
                  "filePath": {
                    "type": "string",
                    "description": "Exactly as returned by POST /csv/upload-url."
                  },
                  "timezone": {
                    "type": "string",
                    "example": "Europe/London"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Upload recorded (same shape as POST /csv/upload)",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "uploads": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "uploadId": {
                                    "type": "string"
                                  },
                                  "fileName": {
                                    "type": "string"
                                  },
                                  "fileSize": {
                                    "type": "integer"
                                  },
                                  "fileType": {
                                    "type": "string",
                                    "enum": [
                                      "csv",
                                      "xls",
                                      "xlsx"
                                    ]
                                  },
                                  "status": {
                                    "type": "string",
                                    "example": "uploaded"
                                  }
                                }
                              }
                            },
                            "failures": {
                              "type": "array",
                              "items": {
                                "type": "object"
                              }
                            },
                            "message": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "filePath is not in this integration’s upload folder (`INVALID_FILE_PATH`), the file is over the size cap (`FILE_TOO_LARGE`), or the provider does not match (`PROVIDER_MISMATCH`)"
          },
          "404": {
            "description": "Integration not found, or nothing was uploaded to filePath"
          },
          "409": {
            "description": "filePath is already registered (`ALREADY_REGISTERED`)"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/sync": {
      "post": {
        "tags": [
          "CSV"
        ],
        "summary": "Trigger processing of already-uploaded CSV files",
        "description": "Starts parsing/ingestion for the given uploadIds as a single `csv`-kind sync. Creates one sync row that groups the batch (poll via `GET /sync/{syncId}`) and links every upload to it. Only files in `uploaded` status are accepted — re-triggering already-processed files is rejected to avoid duplicate ingestion. Files handed to `POST /csv/ai-convert` are refused (400 `UPLOAD_NOT_CONVERTED`) until that conversion completes.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId",
                  "integrationId",
                  "uploadIds"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the uploads.",
                    "example": "ws_3f9a2c"
                  },
                  "integrationId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "CSV integration the uploads belong to.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "uploadIds": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "minLength": 1
                    },
                    "description": "Upload IDs (returned by POST /csv/upload) to process. Must be non-empty; all must be in `uploaded` status.",
                    "example": [
                      "up_1a2b3c",
                      "up_4d5e6f"
                    ]
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Optional IANA timezone override applied to the batch before processing. Not applied to files converted by POST /csv/ai-convert: their timezone was taken at upload and their dates are already UTC.",
                    "example": "Europe/London"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "CSV sync created and queued",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "syncId": {
                              "type": "string"
                            },
                            "status": {
                              "type": "string",
                              "example": "queued"
                            },
                            "syncKind": {
                              "type": "string",
                              "example": "csv"
                            },
                            "uploads": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "uploadId": {
                                    "type": "string"
                                  },
                                  "fileName": {
                                    "type": "string"
                                  },
                                  "status": {
                                    "type": "string",
                                    "example": "queued"
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Validation failed — unknown/missing uploadIds, uploads not in `uploaded` status, integration mismatch, or sync gate failed"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/resync": {
      "post": {
        "tags": [
          "CSV"
        ],
        "summary": "Replay a past CSV sync (destructive)",
        "description": "Deletes the transactions a previous `csv`-kind sync produced, then re-parses the exact same files from storage. Use it after a parser fix, or when an import came out wrong.\n\nScope is **that sync run only** — API-fetched data and other CSV imports on the same integration are untouched. Legs the transfer detector consumed into a merged Transfer are included: on a transfer shared with another integration, only this import’s leg is removed and the surviving side is relabelled from what remains, so it re-pairs once the files are back in.\n\nEvery file linked to the sync is replayed, including ones that previously ended `failed` or `partial` — that is usually the reason to resync at all.\n\nReturns a NEW syncId to poll via `GET /sync/{syncId}`; the old run is linked as `retryOfSyncId` and its deletion counts land on the new sync’s `deletionReport`. The delete runs in the worker ahead of the re-parse, so a 202 means queued, not finished.\n\nUser-owned fields (label, fiat value, notes, comments, tags, per-leg price overrides, COA journals) are carried across the replay and re-applied to the re-imported rows.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "integrationId",
                  "syncId"
                ],
                "properties": {
                  "integrationId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Integration the sync belongs to.",
                    "example": "8b1f6c2e-4d3a-4e1b-9c2a-1f2e3d4c5b6a"
                  },
                  "syncId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The past `csv`-kind sync to replay. Its linked uploads are the files that get re-parsed.",
                    "example": "sync_7c4e1b"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "CSV resync queued",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "syncId": {
                              "type": "string",
                              "description": "The new sync run. Poll this one."
                            },
                            "retryOfSyncId": {
                              "type": "string",
                              "description": "The sync being replaced."
                            },
                            "status": {
                              "type": "string",
                              "example": "queued"
                            },
                            "syncKind": {
                              "type": "string",
                              "example": "csv"
                            },
                            "uploads": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "uploadId": {
                                    "type": "string"
                                  },
                                  "fileName": {
                                    "type": "string"
                                  },
                                  "status": {
                                    "type": "string",
                                    "example": "queued"
                                  }
                                }
                              }
                            },
                            "message": {
                              "type": "string"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Not replayable. `SYNC_KIND_MISMATCH` (not a csv sync), `SYNC_INTEGRATION_MISMATCH`, `NO_UPLOADS_FOR_SYNC` (nothing linked — e.g. a legacy single-file upload), or `SOURCE_FILE_MISSING` (a source file is no longer in storage, so nothing is deleted and the request is refused)."
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "`SYNC_ALREADY_IN_PROGRESS` — the integration has a sync running; a resync deletes before it writes, so it must not race one. `UNATTRIBUTABLE_DETECTION_ROWS` — the wallet holds detector-produced transfer/swap legs written before per-sync attribution existed (no `sync_id`, no `trxs_merged`), which no per-sync delete can reach; replaying past them would duplicate them, so re-sync the integration from start once to rewrite them, then retry."
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/uploads": {
      "get": {
        "tags": [
          "CSV"
        ],
        "summary": "List CSV upload history",
        "parameters": [
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "uploaded",
                "queued",
                "processing",
                "success",
                "partial",
                "failed",
                "skipped",
                "deleted"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Upload history, newest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "uploads": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/CsvUpload"
                          }
                        },
                        "pagination": {
                          "$ref": "#/components/schemas/IntegrationPagination"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/csv/uploads/{uploadId}": {
      "get": {
        "tags": [
          "CSV"
        ],
        "summary": "Get upload status",
        "parameters": [
          {
            "name": "uploadId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The upload and its parse result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/CsvUpload"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "errorFilePath": {
                              "type": "string",
                              "nullable": true,
                              "description": "Set when some rows failed: download them with GET /csv/uploads/{uploadId}/errors."
                            },
                            "uploadedBy": {
                              "type": "string",
                              "nullable": true
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      },
      "delete": {
        "tags": [
          "CSV"
        ],
        "summary": "Delete a CSV upload",
        "parameters": [
          {
            "name": "uploadId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/csv/uploads/{uploadId}/errors": {
      "get": {
        "tags": [
          "CSV"
        ],
        "summary": "Get signed URL to download parse-error CSV (404 if no errors)",
        "parameters": [
          {
            "name": "uploadId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Signed download URL",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "url": {
                              "type": "string"
                            },
                            "expiresAt": {
                              "type": "string",
                              "format": "date-time"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth"
        ]
      }
    },
    "/sync": {
      "get": {
        "tags": [
          "Sync"
        ],
        "summary": "List sync history",
        "parameters": [
          {
            "$ref": "#/components/parameters/IntegrationWorkspaceId"
          },
          {
            "name": "integrationId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "pending",
                "queued",
                "in_progress",
                "completed",
                "failed",
                "cancelled",
                "partially_synced"
              ]
            }
          },
          {
            "name": "syncKind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "api",
                "csv",
                "prices"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Page"
          },
          {
            "$ref": "#/components/parameters/Limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Sync history",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "syncs": {
                              "type": "array",
                              "items": {
                                "allOf": [
                                  {
                                    "$ref": "#/components/schemas/Sync"
                                  },
                                  {
                                    "type": "object",
                                    "properties": {
                                      "fileTypes": {
                                        "type": "array",
                                        "items": {
                                          "type": "string",
                                          "enum": [
                                            "csv",
                                            "xls",
                                            "xlsx"
                                          ]
                                        },
                                        "nullable": true,
                                        "description": "Formats of the file(s) a file import parsed — `syncKind` is 'csv' for every file import, Excel included. Resyncs report the same files as the import they replay. Null for non-file syncs; empty when the upload was deleted or was never linked to a sync.",
                                        "example": [
                                          "xlsx"
                                        ]
                                      }
                                    }
                                  }
                                ]
                              }
                            },
                            "pagination": {
                              "$ref": "#/components/schemas/IntegrationPagination"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/sync/{syncId}": {
      "get": {
        "tags": [
          "Sync"
        ],
        "summary": "Get sync job status",
        "parameters": [
          {
            "name": "syncId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sync status",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/IntegrationSuccessEnvelope"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "$ref": "#/components/schemas/Sync"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "connect",
          "oauth",
          "api-key"
        ]
      }
    },
    "/sync/{syncId}/cancel": {
      "post": {
        "tags": [
          "Sync"
        ],
        "summary": "Cancel a running sync",
        "parameters": [
          {
            "name": "syncId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "workspaceId"
                ],
                "properties": {
                  "workspaceId": {
                    "type": "string",
                    "minLength": 1,
                    "description": "Workspace owning the sync job to cancel.",
                    "example": "ws_3f9a2c"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Sync cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "success": {
                          "type": "boolean",
                          "example": true
                        },
                        "message": {
                          "type": "string",
                          "example": "Sync cancelled successfully"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        },
        "x-kryptos-credentials": [
          "workspace-token",
          "oauth"
        ]
      }
    },
    "/developer/workspaces": {
      "post": {
        "summary": "Create an Integrations API workspace",
        "description": "Creates a workspace for one of your customers and returns a 24-hour access token for it. The workspace syncs and stores data only: Kryptos computes no balances, cost basis or gains on it. See the Integrations API quickstart.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "example": "Customer 42"
                  },
                  "country_code": {
                    "type": "string",
                    "example": "US"
                  },
                  "base_currency_code": {
                    "type": "string",
                    "example": "USD"
                  },
                  "timezone": {
                    "type": "string",
                    "example": "UTC"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Workspace created, with a 24-hour access token.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "workspace_id": {
                          "type": "string",
                          "example": "ws_3f9a1c7e2b"
                        },
                        "grant_id": {
                          "type": "string",
                          "example": "grant_8d2e4b1a9c"
                        },
                        "access_token": {
                          "type": "string",
                          "example": "cat_5b7c…",
                          "description": "Bearer token for this workspace only. Lasts 24 hours; get fresh ones with POST /developer/workspaces/{workspace_id}/token."
                        },
                        "token_type": {
                          "type": "string",
                          "example": "Bearer"
                        },
                        "expires_in": {
                          "type": "integer",
                          "example": 86400,
                          "description": "Seconds until the token expires (24 hours)."
                        },
                        "scope": {
                          "type": "string",
                          "example": "integrations:read integrations:write portfolios:read transactions:read transactions:write",
                          "description": "Space-separated scopes, set by Kryptos."
                        },
                        "transaction_limit": {
                          "type": "integer",
                          "example": 100000,
                          "description": "Most transactions this workspace can hold."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "SANDBOX_CLIENT, API_WORKSPACES_NOT_ENABLED or WORKSPACE_LIMIT_REACHED",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "…"
                    },
                    "code": {
                      "type": "string",
                      "example": "WORKSPACE_LIMIT_REACHED"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Too many workspace creates for this client",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "…"
                    },
                    "code": {
                      "type": "string",
                      "example": "RATE_LIMITED"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Workspace management"
        ],
        "servers": [
          {
            "url": "https://connect-api.kryptos.io",
            "description": "Connect service"
          }
        ],
        "security": [
          {
            "clientId": [],
            "clientSecret": []
          }
        ],
        "x-kryptos-credentials": [
          "client-credentials"
        ]
      }
    },
    "/developer/workspaces/{workspace_id}/token": {
      "post": {
        "summary": "Issue a fresh workspace token",
        "description": "A new 24-hour access token for one of your Integrations API workspaces. Earlier tokens keep working until they expire; `revoke_existing: true` ends them now (a suspected leak). Any workspace your client did not create, or has revoked, returns 404.",
        "parameters": [
          {
            "name": "workspace_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "example": "ws_3f9a1c7e2b"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "revoke_existing": {
                    "type": "boolean",
                    "example": false,
                    "description": "Also end every other live token of this workspace now."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "A fresh token",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "workspace_id": {
                          "type": "string",
                          "example": "ws_3f9a1c7e2b"
                        },
                        "grant_id": {
                          "type": "string",
                          "example": "grant_8d2e4b1a9c"
                        },
                        "access_token": {
                          "type": "string",
                          "example": "cat_9a1d…",
                          "description": "Bearer token for this workspace. Lasts 24 hours."
                        },
                        "token_type": {
                          "type": "string",
                          "example": "Bearer"
                        },
                        "expires_in": {
                          "type": "integer",
                          "example": 86400
                        },
                        "scope": {
                          "type": "string",
                          "example": "integrations:read integrations:write portfolios:read transactions:read transactions:write connect:api"
                        },
                        "revoked_tokens": {
                          "type": "integer",
                          "example": 0,
                          "description": "Other tokens ended by revoke_existing."
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Not an Integrations API workspace of this client",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "…"
                    },
                    "code": {
                      "type": "string",
                      "example": "WORKSPACE_NOT_FOUND"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Over 120 tokens this minute",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "…"
                    },
                    "code": {
                      "type": "string",
                      "example": "RATE_LIMITED"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Workspace management"
        ],
        "servers": [
          {
            "url": "https://connect-api.kryptos.io",
            "description": "Connect service"
          }
        ],
        "security": [
          {
            "clientId": [],
            "clientSecret": []
          }
        ],
        "x-kryptos-credentials": [
          "client-credentials"
        ]
      }
    },
    "/developer/grants/{grantId}/transaction-limit": {
      "patch": {
        "summary": "Update a grant's transaction limit",
        "parameters": [
          {
            "name": "grantId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "transactionLimit": {
                    "type": "integer"
                  },
                  "enableLimiter": {
                    "type": "boolean"
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Limit updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "grant_id": {
                          "type": "string",
                          "example": "grant_8d2e4b1a9c"
                        },
                        "user_id": {
                          "type": "string",
                          "example": "ws_3f9a1c7e2b"
                        },
                        "transaction_limit": {
                          "type": "integer",
                          "example": 50000,
                          "nullable": true
                        },
                        "enable_limiter": {
                          "type": "boolean",
                          "nullable": true,
                          "example": true
                        },
                        "previous_transaction_limit": {
                          "type": "integer",
                          "example": 100000,
                          "nullable": true
                        },
                        "previous_enable_limiter": {
                          "type": "boolean",
                          "nullable": true,
                          "example": true
                        },
                        "resync": {
                          "nullable": true,
                          "description": "Null when nothing changed. Otherwise the syncs this change queued: poll GET /v1/sync/{syncId} for each.",
                          "type": "object",
                          "properties": {
                            "triggered": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "integration_id": {
                                    "type": "string",
                                    "example": "9b0c…"
                                  },
                                  "sync_id": {
                                    "type": "string",
                                    "example": "4e1d…"
                                  }
                                }
                              }
                            },
                            "failed": {
                              "type": "array",
                              "items": {
                                "type": "object",
                                "properties": {
                                  "integration_id": {
                                    "type": "string",
                                    "example": "9b0c…"
                                  },
                                  "error": {
                                    "type": "string",
                                    "example": "…"
                                  }
                                }
                              }
                            },
                            "skipped": {
                              "type": "integer",
                              "example": 0
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "LIMIT_ABOVE_CEILING (Integrations API workspaces)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "…"
                    },
                    "code": {
                      "type": "string",
                      "example": "LIMIT_ABOVE_CEILING"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Workspace management"
        ],
        "servers": [
          {
            "url": "https://connect-api.kryptos.io",
            "description": "Connect service"
          }
        ],
        "security": [
          {
            "clientId": [],
            "clientSecret": []
          }
        ],
        "x-kryptos-credentials": [
          "client-credentials"
        ]
      }
    },
    "/token/grants": {
      "get": {
        "summary": "List your active grants",
        "responses": {
          "200": {
            "description": "Your active grants, one per workspace",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "grants": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "grant_id": {
                                "type": "string",
                                "example": "grant_8d2e4b1a9c"
                              },
                              "workspace_id": {
                                "type": "string",
                                "example": "ws_3f9a1c7e2b"
                              },
                              "scopes": {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                },
                                "example": [
                                  "integrations:read",
                                  "transactions:read"
                                ]
                              },
                              "created_at": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2026-11-20T10:15:00.000Z"
                              },
                              "expires_at": {
                                "type": "string",
                                "format": "date-time",
                                "nullable": true,
                                "example": "2041-11-16T10:15:00.000Z"
                              }
                            }
                          }
                        },
                        "count": {
                          "type": "integer",
                          "example": 1
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Workspace management"
        ],
        "servers": [
          {
            "url": "https://connect-api.kryptos.io",
            "description": "Connect service"
          }
        ],
        "security": [
          {
            "clientId": [],
            "clientSecret": []
          }
        ],
        "x-kryptos-credentials": [
          "client-credentials"
        ]
      }
    },
    "/token/revoke": {
      "post": {
        "summary": "Revoke a grant",
        "description": "The grant's access token stops working on its next request.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "grant_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "grant_id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Grant revoked (also returned when it was already revoked or expired)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Grant revoked successfully"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "The grant belongs to another client",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "error": {
                      "type": "string",
                      "example": "Grant does not belong to this client"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Workspace management"
        ],
        "servers": [
          {
            "url": "https://connect-api.kryptos.io",
            "description": "Connect service"
          }
        ],
        "security": [
          {
            "clientId": [],
            "clientSecret": []
          }
        ],
        "x-kryptos-credentials": [
          "client-credentials"
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The workspace token returned by POST /developer/workspaces."
      },
      "clientId": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Client-Id"
      },
      "clientSecret": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Client-Secret"
      }
    },
    "schemas": {
      "Contact": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "example": "Acme Corp"
          },
          "type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ],
            "nullable": true
          },
          "socials": {
            "type": "object",
            "nullable": true,
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              },
              "telegram": {
                "type": "string"
              }
            }
          },
          "residentialAddress": {
            "type": "object",
            "nullable": true,
            "properties": {
              "country": {
                "type": "string"
              },
              "state": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "postcode": {
                "type": "string"
              },
              "address1": {
                "type": "string"
              },
              "address2": {
                "type": "string"
              }
            }
          },
          "mobileNumber": {
            "type": "string",
            "nullable": true
          },
          "vat": {
            "type": "string",
            "nullable": true
          },
          "terms": {
            "type": "object",
            "nullable": true,
            "properties": {
              "payment": {
                "type": "string"
              },
              "overduesInterest": {
                "type": "number"
              }
            }
          },
          "transactionCount": {
            "type": "integer",
            "description": "Interaction count: Σ of linked counter-parties’ transaction counts (stored, recomputed)"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ContactChainAddress": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "contactId": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "address": {
            "type": "string",
            "description": "Original casing (display)"
          },
          "addressNormalized": {
            "type": "string",
            "description": "Lower-cased matching key"
          },
          "chainName": {
            "type": "string",
            "example": "ethereum"
          },
          "chainPublicName": {
            "type": "string",
            "nullable": true
          },
          "chainLogo": {
            "type": "string",
            "nullable": true
          },
          "transactionCount": {
            "type": "integer",
            "description": "Interaction count for this address — the linked counter-party’s stored distinct-transaction count (0 if none)"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CounterParty": {
        "type": "object",
        "description": "System-detected other side of a transaction. Append-created; ref-counted on delete.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "addressNormalized": {
            "type": "string"
          },
          "chainName": {
            "type": "string",
            "example": "ethereum"
          },
          "chainPublicName": {
            "type": "string",
            "nullable": true
          },
          "chainLogo": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string",
            "nullable": true,
            "description": "Exchange/protocol/contact name"
          },
          "logo": {
            "type": "string",
            "nullable": true
          },
          "isExchangeAddress": {
            "type": "boolean"
          },
          "platformExchangeId": {
            "type": "string",
            "nullable": true
          },
          "isSmartContract": {
            "type": "boolean"
          },
          "platformSmartContractId": {
            "type": "string",
            "nullable": true
          },
          "identified": {
            "type": "boolean"
          },
          "ignored": {
            "type": "boolean"
          },
          "isLinkedToContact": {
            "type": "boolean"
          },
          "contactId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "previousState": {
            "type": "object",
            "nullable": true,
            "description": "Pre-contact-link snapshot restored on unassign",
            "properties": {
              "name": {
                "type": "string",
                "nullable": true
              },
              "identified": {
                "type": "boolean"
              }
            }
          },
          "transactionCount": {
            "type": "integer",
            "description": "Interaction count: distinct transactions referencing this address (stored, recomputed)"
          },
          "firstSeenAt": {
            "type": "string",
            "format": "date-time"
          },
          "lastSeenAt": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ContactCreate": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "type": {
            "type": "string",
            "enum": [
              "individual",
              "company"
            ]
          },
          "socials": {
            "$ref": "#/components/schemas/Contact/properties/socials"
          },
          "residentialAddress": {
            "$ref": "#/components/schemas/Contact/properties/residentialAddress"
          },
          "mobileNumber": {
            "type": "string",
            "maxLength": 30
          },
          "vat": {
            "type": "string",
            "maxLength": 50
          },
          "terms": {
            "$ref": "#/components/schemas/Contact/properties/terms"
          }
        }
      },
      "AssignChainAddress": {
        "type": "object",
        "required": [
          "address",
          "chainName"
        ],
        "properties": {
          "address": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255
          },
          "chainName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50,
            "example": "ethereum"
          },
          "chainPublicName": {
            "type": "string",
            "maxLength": 100
          },
          "chainLogo": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "FullSearchResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "address": {
            "type": "string",
            "nullable": true
          },
          "type": {
            "type": "string",
            "enum": [
              "contact",
              "counterParty",
              "wallet"
            ]
          }
        }
      },
      "SuccessEnvelope": {
        "type": "object",
        "required": [
          "success"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "description": "Payload — shape depends on the endpoint"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "GraphResponse": {
        "type": "object",
        "required": [
          "success",
          "data",
          "range",
          "granularity",
          "currency"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "timestamp": {
                  "type": "integer",
                  "description": "Bucket START instant, epoch ms UTC",
                  "example": 1753747200000
                },
                "totalValue": {
                  "type": "number",
                  "example": 12345.67
                },
                "costBasis": {
                  "type": "number",
                  "example": 9000.12
                }
              }
            }
          },
          "range": {
            "type": "string",
            "enum": [
              "1D",
              "1W",
              "1M",
              "3M",
              "1Y",
              "ALL"
            ]
          },
          "granularity": {
            "type": "string",
            "enum": [
              "1h",
              "1d"
            ],
            "description": "Actual spacing of the returned points. May be coarser than the range prefers when hourly history does not cover the whole range."
          },
          "currency": {
            "type": "string",
            "description": "The workspace's base currency the values are denominated in",
            "example": "USD"
          }
        }
      },
      "AssetGraphResponse": {
        "type": "object",
        "required": [
          "success",
          "data",
          "range",
          "granularity",
          "currency"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "timestamp": {
                  "type": "integer",
                  "description": "Bucket START instant, epoch ms UTC",
                  "example": 1753747200000
                },
                "value": {
                  "type": "number",
                  "description": "This asset's held quantity across the workspace × price at this point",
                  "example": 4200.5
                },
                "costBasis": {
                  "type": "number",
                  "description": "This asset's accumulated cost basis across the workspace at this point",
                  "example": 3000
                }
              }
            }
          },
          "range": {
            "type": "string",
            "enum": [
              "1H",
              "1D",
              "1M",
              "3M",
              "YTD",
              "1Y",
              "ALL"
            ]
          },
          "granularity": {
            "type": "string",
            "enum": [
              "5m",
              "1h",
              "1d"
            ],
            "description": "Actual spacing of the returned points. '5m' only for range=1H (its own 5-minute CMC grid); '1h'/'1d' for every other range."
          },
          "currency": {
            "type": "string",
            "description": "The workspace's base currency the values are denominated in",
            "example": "USD"
          }
        }
      },
      "ErrorEnvelope": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "Pagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "Country": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string",
            "example": "AU"
          },
          "name": {
            "type": "string",
            "example": "Australia"
          },
          "timezone": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "Australia/Sydney"
            ]
          },
          "capital": {
            "type": "string",
            "example": "Canberra"
          },
          "baseCurrencyCode": {
            "type": "string",
            "nullable": true,
            "example": "AUD"
          },
          "defaultCostBasisMethod": {
            "type": "string",
            "example": "FIFO"
          },
          "supportedCostBasisMethods": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "FIFO",
              "LIFO",
              "HIFO",
              "ACB"
            ]
          },
          "fiscalStart": {
            "type": "string",
            "example": "01/07"
          },
          "fiscalEnd": {
            "type": "string",
            "example": "30/06"
          },
          "guideLink": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "isTLHApplicable": {
            "type": "boolean",
            "example": true,
            "description": "Whether tax-loss harvesting applies in this country."
          }
        }
      },
      "CountryDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Country"
          },
          {
            "type": "object",
            "properties": {
              "advancedTxSettings": {
                "$ref": "#/components/schemas/AdvancedTxSettings"
              },
              "tags": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              },
              "taxInfo": {
                "type": "object",
                "nullable": true
              },
              "costBasisOptions": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/CostBasisMethod"
                }
              },
              "effectiveAdvancedTxSettings": {
                "$ref": "#/components/schemas/AdvancedTxSettings"
              },
              "settingsSchema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/AdvancedTxSettingDefinition"
                }
              }
            }
          }
        ]
      },
      "DefiProtocol": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "uniswap3"
          },
          "chain": {
            "type": "string",
            "example": "eth"
          },
          "chainName": {
            "type": "string",
            "nullable": true,
            "example": "Ethereum"
          },
          "chainLogo": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string",
            "example": "Uniswap V3"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true
          },
          "siteUrl": {
            "type": "string",
            "nullable": true,
            "example": "https://uniswap.org"
          },
          "tvl": {
            "type": "number",
            "nullable": true,
            "description": "Total Value Locked in USD"
          },
          "totalUserUsd": {
            "type": "number",
            "nullable": true
          },
          "lockUsd": {
            "type": "number",
            "nullable": true
          },
          "lockUnderlyingUsd": {
            "type": "number",
            "nullable": true
          },
          "activeUserCount24h": {
            "type": "integer",
            "nullable": true
          },
          "contractCallCount24h": {
            "type": "integer",
            "nullable": true
          },
          "totalContractCount": {
            "type": "integer",
            "nullable": true
          },
          "totalUserCount": {
            "type": "integer",
            "nullable": true
          },
          "portfolioUserCount": {
            "type": "integer",
            "nullable": true
          },
          "isSupportPortfolio": {
            "type": "boolean",
            "nullable": true
          },
          "isVisible": {
            "type": "boolean",
            "nullable": true
          },
          "isStable": {
            "type": "boolean",
            "nullable": true
          },
          "isTvl": {
            "type": "boolean",
            "nullable": true
          },
          "isSiteDown": {
            "type": "boolean",
            "nullable": true
          },
          "priority": {
            "type": "integer",
            "nullable": true
          },
          "tagIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true,
            "example": [
              "dex",
              "amm"
            ]
          },
          "platformTokenChain": {
            "type": "string",
            "nullable": true
          },
          "platformTokenId": {
            "type": "string",
            "nullable": true
          },
          "daoId": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CostBasisMethod": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "example": "FIFO"
          },
          "name": {
            "type": "string",
            "example": "FIFO"
          },
          "description": {
            "type": "string"
          },
          "countryLocked": {
            "type": "boolean"
          },
          "lockedForCountries": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true
          }
        }
      },
      "TransactionLabelInfo": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "example": "Buy"
          },
          "type": {
            "type": "string",
            "nullable": true,
            "enum": [
              "deposit",
              "withdrawal",
              "trade",
              "transfer",
              "payment"
            ],
            "description": "Transaction type this label maps to. null for the common labels (Ignore/Failed/Unknown) that apply to every type.",
            "example": "trade"
          },
          "taxEvent": {
            "type": "string",
            "nullable": true,
            "enum": [
              "CAPITAL_GAIN",
              "INCOME",
              "LOST",
              "VAULT"
            ],
            "description": "Tax event this label triggers, or null when it has none.",
            "example": "CAPITAL_GAIN"
          },
          "description": {
            "type": "string",
            "nullable": true,
            "description": "Human-readable explanation of what this label means, for UI display.",
            "example": "You bought digital assets. Establishes the cost basis for the asset acquired."
          }
        }
      },
      "TransactionTypeInfo": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "deposit",
              "withdrawal",
              "trade",
              "transfer",
              "payment"
            ],
            "example": "trade"
          },
          "labels": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Canonical labels applicable to this type (the common labels Ignore/Failed/Unknown/Spam are included in every type).",
            "example": [
              "Ignore",
              "Failed",
              "Unknown",
              "Spam",
              "Trade",
              "Buy",
              "Sell"
            ]
          }
        }
      },
      "AssetSearchItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "name": {
            "type": "string",
            "example": "Bitcoin"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true
          },
          "type": {
            "type": "string",
            "enum": [
              "crypto",
              "fiat",
              "nft",
              "stablecoin"
            ],
            "example": "crypto"
          },
          "category": {
            "type": "string",
            "nullable": true,
            "example": "coin"
          },
          "cmcRank": {
            "type": "integer",
            "nullable": true,
            "example": 1
          },
          "chains": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "chainId": {
                  "type": "string",
                  "example": "ethereum"
                },
                "contractAddress": {
                  "type": "string"
                }
              }
            }
          },
          "score": {
            "type": "number",
            "description": "Relevance 0–1 (0.7·text match + 0.3·CMC popularity). Present only in fuzzy mode (q set).",
            "example": 0.972
          }
        }
      },
      "AdvancedTxSettings": {
        "type": "object",
        "properties": {
          "fork": {
            "type": "boolean"
          },
          "mining": {
            "type": "boolean"
          },
          "rewards": {
            "type": "boolean"
          },
          "airdrops": {
            "type": "boolean"
          },
          "crypto_to_crypto": {
            "type": "boolean"
          },
          "lp_tokens": {
            "type": "boolean"
          },
          "fee_in_cg": {
            "type": "boolean"
          },
          "transfer_fees": {
            "type": "boolean"
          },
          "lost_transactions": {
            "type": "boolean"
          },
          "ltcg_taxable": {
            "type": "boolean"
          },
          "othergains_in_cg": {
            "type": "boolean"
          },
          "cost_basis_per_wallet": {
            "type": "boolean"
          }
        }
      },
      "AdvancedTxSettingDefinition": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "defaultValue": {
            "type": "boolean"
          }
        }
      },
      "Workspace": {
        "type": "object",
        "properties": {
          "wid": {
            "type": "string",
            "example": "ws_abc123"
          },
          "workspaceName": {
            "type": "string",
            "example": "My Workspace"
          },
          "type": {
            "type": "string",
            "enum": [
              "enterprise",
              "retail",
              "connect-anonymous",
              "investigation-case"
            ]
          },
          "countryCode": {
            "type": "string",
            "example": "AU"
          },
          "costBasisMethod": {
            "type": "string",
            "example": "FIFO"
          },
          "timezone": {
            "type": "string",
            "example": "Australia/Sydney"
          },
          "baseCurrencyCode": {
            "type": "string",
            "example": "AUD"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkspaceLimits": {
        "type": "object",
        "description": "The workspace's transaction-ingestion cap. `transactionLimit`/`enableLimiter` are the raw per-workspace overrides and are null when unset (the workspace inherits the system default); `effectiveTransactionLimit` is the cap actually enforced, and is the only value worth comparing against a count. Returned on the single-workspace read only.",
        "properties": {
          "transactionLimit": {
            "type": "integer",
            "nullable": true,
            "example": 5000
          },
          "enableLimiter": {
            "type": "boolean",
            "nullable": true,
            "example": true
          },
          "effectiveTransactionLimit": {
            "type": "integer",
            "nullable": true,
            "description": "Null when the workspace is uncapped (`enableLimiter: false`).",
            "example": 5000
          },
          "currentTransactionCount": {
            "type": "integer",
            "description": "Saved rows plus the rows a running sync has in flight.",
            "example": 4871
          },
          "remainingTransactions": {
            "type": "integer",
            "nullable": true,
            "description": "Headroom before ingestion stops. Null when uncapped.",
            "example": 129
          }
        }
      },
      "WorkspaceTaxSettings": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "advancedTxSettings": {
            "$ref": "#/components/schemas/AdvancedTxSettings"
          },
          "tagsException": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkspaceTaxInformation": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "personalTaxId": {
            "type": "string",
            "nullable": true
          },
          "phoneCountryCode": {
            "type": "string",
            "nullable": true
          },
          "phoneNumber": {
            "type": "string",
            "nullable": true
          },
          "postalCode": {
            "type": "string",
            "nullable": true
          },
          "city": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Member": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "userId": {
            "type": "string"
          },
          "roleId": {
            "type": "string",
            "example": "owner"
          },
          "customScopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "revokedScopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "suspended",
              "pending"
            ]
          },
          "notes": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Task": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "operationType": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "running",
              "completed",
              "failed",
              "cancelled"
            ]
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "progressMessage": {
            "type": "string",
            "nullable": true
          },
          "result": {
            "type": "object",
            "nullable": true
          },
          "parameters": {
            "type": "object",
            "nullable": true
          },
          "createdBy": {
            "type": "string",
            "nullable": true
          },
          "idempotencyKey": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RawAsset": {
        "type": "object",
        "description": "A raw, un-matched asset descriptor used inside transaction asset legs.",
        "required": [
          "symbol"
        ],
        "properties": {
          "symbol": {
            "type": "string",
            "minLength": 1,
            "description": "Ticker symbol (required).",
            "example": "ETH"
          },
          "tokenId": {
            "type": "string",
            "description": "NFT token id (when type is 'nft').",
            "example": "1234"
          },
          "publicName": {
            "type": "string",
            "description": "Human-readable asset name.",
            "example": "Ethereum"
          },
          "logoUrl": {
            "type": "string",
            "format": "uri",
            "description": "Asset logo image URL."
          },
          "type": {
            "type": "string",
            "enum": [
              "crypto",
              "fiat",
              "nft",
              "stablecoin"
            ],
            "description": "Asset class. Used to drive matching and tax treatment.",
            "example": "crypto"
          },
          "chainId": {
            "type": "string",
            "description": "Chain identifier the asset lives on.",
            "example": "ethereum"
          },
          "contractAddress": {
            "type": "string",
            "description": "Token contract address (for on-chain tokens / NFTs).",
            "example": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
          }
        }
      },
      "AccountType": {
        "type": "object",
        "description": "The wallet / exchange account an asset leg moves from, to, or pays a fee from.",
        "required": [
          "provider"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "minLength": 1,
            "description": "Provider / integration slug (required).",
            "example": "metamask"
          },
          "providerPublicName": {
            "type": "string",
            "description": "Display name of the provider.",
            "example": "MetaMask"
          },
          "publicAddress": {
            "type": "string",
            "description": "Public wallet address for this account.",
            "example": "0xabc123..."
          },
          "walletId": {
            "type": "string",
            "description": "Internal integration account id this leg is attributed to."
          },
          "logoUrl": {
            "type": "string",
            "format": "uri",
            "description": "Provider logo image URL."
          },
          "isContract": {
            "type": "boolean",
            "description": "True if the address is a smart contract rather than an EOA."
          },
          "alias": {
            "type": "string",
            "description": "User-defined alias for the account."
          }
        }
      },
      "PriceModel": {
        "type": "object",
        "description": "A point-in-time price for an asset leg, in the given base currency.",
        "required": [
          "price",
          "baseCurrency",
          "timestamp",
          "source"
        ],
        "properties": {
          "price": {
            "type": "number",
            "description": "Unit price in baseCurrency — never a line total. Multiply by the leg quantity to get its fiat value (the API already does this for the leg `value` and for `netValue`).",
            "example": 3200.55
          },
          "baseCurrency": {
            "type": "string",
            "minLength": 1,
            "description": "ISO currency code the price is denominated in.",
            "example": "USD"
          },
          "timestamp": {
            "type": "number",
            "description": "Unix epoch (ms) the price was observed.",
            "example": 1718800000000
          },
          "source": {
            "type": "string",
            "minLength": 1,
            "description": "Pricing source identifier. `custom` marks a workspace price override; `derived` marks a price inferred from the priced side of a two-sided trade by value conservation (counter-value ÷ quantity) rather than quoted by a provider.",
            "example": "coingecko"
          }
        }
      },
      "IncomingAsset": {
        "type": "object",
        "description": "An asset leg flowing INTO the workspace (received). `type` must be 'incoming'.",
        "required": [
          "asset",
          "quantity",
          "type",
          "toAccount"
        ],
        "properties": {
          "asset": {
            "$ref": "#/components/schemas/RawAsset"
          },
          "quantity": {
            "type": "number",
            "description": "Amount received.",
            "example": 1.5
          },
          "price": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "baseCurrency": {
            "type": "string",
            "description": "Override base currency for this leg.",
            "example": "USD"
          },
          "type": {
            "type": "string",
            "enum": [
              "incoming"
            ],
            "example": "incoming"
          },
          "fromAccount": {
            "$ref": "#/components/schemas/AccountType"
          },
          "toAccount": {
            "$ref": "#/components/schemas/AccountType"
          },
          "internalLabel": {
            "type": "string",
            "description": "Internal sub-label for the leg."
          },
          "transactionPlatformId": {
            "type": "string",
            "description": "Source-platform id this leg belongs to."
          }
        }
      },
      "OutgoingAsset": {
        "type": "object",
        "description": "An asset leg flowing OUT of the workspace (sent). `type` must be 'outgoing'.",
        "required": [
          "asset",
          "quantity",
          "type",
          "fromAccount"
        ],
        "properties": {
          "asset": {
            "$ref": "#/components/schemas/RawAsset"
          },
          "quantity": {
            "type": "number",
            "description": "Amount sent.",
            "example": 0.25
          },
          "price": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "baseCurrency": {
            "type": "string",
            "description": "Override base currency for this leg.",
            "example": "USD"
          },
          "type": {
            "type": "string",
            "enum": [
              "outgoing"
            ],
            "example": "outgoing"
          },
          "fromAccount": {
            "$ref": "#/components/schemas/AccountType"
          },
          "toAccount": {
            "$ref": "#/components/schemas/AccountType"
          },
          "internalLabel": {
            "type": "string",
            "description": "Internal sub-label for the leg."
          },
          "transactionPlatformId": {
            "type": "string",
            "description": "Source-platform id this leg belongs to."
          }
        }
      },
      "FeeAsset": {
        "type": "object",
        "description": "A fee asset leg. `type` must be 'fee'.",
        "required": [
          "asset",
          "quantity",
          "type",
          "feeAccount"
        ],
        "properties": {
          "asset": {
            "$ref": "#/components/schemas/RawAsset"
          },
          "quantity": {
            "type": "number",
            "description": "Fee amount.",
            "example": 0.001
          },
          "price": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "baseCurrency": {
            "type": "string",
            "description": "Override base currency for this leg.",
            "example": "USD"
          },
          "type": {
            "type": "string",
            "enum": [
              "fee"
            ],
            "example": "fee"
          },
          "feeAccount": {
            "$ref": "#/components/schemas/AccountType"
          }
        }
      },
      "TransactionLedgerLeg": {
        "type": "object",
        "description": "A ledger row as returned inside a transaction response (incomingAssets / outgoingAssets / fee). This is the persisted ledger shape (with the resolved asset joined in) — distinct from the IncomingAsset/OutgoingAsset/FeeAsset request schemas used to CREATE a transaction. Numeric columns are serialized as strings.",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "transactionId": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "walletId": {
            "type": "string",
            "description": "Owning integration account id (authoritative source for the leg)."
          },
          "syncId": {
            "type": "string",
            "nullable": true,
            "description": "Sync run that produced this leg."
          },
          "timestamp": {
            "type": "integer",
            "format": "int64",
            "description": "epoch ms"
          },
          "type": {
            "type": "string",
            "enum": [
              "incoming",
              "outgoing",
              "fee"
            ]
          },
          "assetId": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Resolved asset id; null while asset resolution is pending."
          },
          "assetRaw": {
            "allOf": [
              {
                "$ref": "#/components/schemas/RawAsset"
              }
            ],
            "nullable": true,
            "description": "Raw parser asset descriptor, kept for deferred resolution."
          },
          "asset": {
            "type": "object",
            "nullable": true,
            "description": "Resolved asset (joined from assets); null when assetId is unresolved.",
            "properties": {
              "symbol": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "logoUrl": {
                "type": "string",
                "nullable": true
              },
              "type": {
                "type": "string"
              }
            }
          },
          "quantity": {
            "type": "string",
            "description": "numeric"
          },
          "baseCurrency": {
            "type": "string",
            "example": "USD"
          },
          "price": {
            "allOf": [
              {
                "$ref": "#/components/schemas/PriceModel"
              }
            ],
            "nullable": true,
            "description": "null when the leg has no price."
          },
          "value": {
            "type": "number",
            "nullable": true,
            "description": "Fiat value of this leg = quantity × price, in baseCurrency. Derived at read time; null when the leg has no price."
          },
          "label": {
            "type": "string",
            "nullable": true
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "fromAccount": {
            "allOf": [
              {
                "$ref": "#/components/schemas/AccountType"
              }
            ],
            "nullable": true
          },
          "toAccount": {
            "allOf": [
              {
                "$ref": "#/components/schemas/AccountType"
              }
            ],
            "nullable": true
          },
          "beforeBalance": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "afterBalance": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "isMissingPurchase": {
            "type": "boolean",
            "description": "Set by the balance recompute: this outgoing/fee leg drove its (wallet, asset) running balance to a new negative low (missing purchase history). False until the (wallet, asset) pair of this leg is recomputed; legs of Spam/Ignore transactions keep their last value."
          },
          "costbasis": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "proceeds": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "profit": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "internalLabel": {
            "type": "string",
            "nullable": true
          },
          "transactionPlatformId": {
            "type": "string",
            "nullable": true
          },
          "isEdited": {
            "type": "boolean",
            "description": "True when a user manually edited this leg."
          },
          "debitCoaCode": {
            "type": "string",
            "nullable": true,
            "description": "Enterprise only — GL code posted to on the debit side."
          },
          "creditCoaCode": {
            "type": "string",
            "nullable": true,
            "description": "Enterprise only — GL code posted to on the credit side."
          },
          "isDebitCoaEdited": {
            "type": "boolean",
            "description": "True when the debit code was manually set (COA re-run skips it)."
          },
          "isCreditCoaEdited": {
            "type": "boolean",
            "description": "True when the credit code was manually set (COA re-run skips it)."
          },
          "coaRuleAppliedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When a rule last (re)assigned this leg. Null on manual/default-map codes."
          },
          "debitCoaRuleId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "creditCoaRuleId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "TransactionWithLedgers": {
        "type": "object",
        "description": "Transaction with its ledger entries (key fields shown; additional fields may be present). Shared shape for GET /transactions (list) and GET /transactions/{id} (detail) — the only difference is coaJournal.lines, which is populated only on the detail endpoint.",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string",
            "example": "ws_…"
          },
          "transactionPlatformId": {
            "type": "string",
            "nullable": true,
            "description": "Exchange/on-chain transaction hash or platform-assigned id."
          },
          "timestamp": {
            "type": "integer",
            "format": "int64",
            "description": "Event time (Unix ms)."
          },
          "label": {
            "type": "string",
            "example": "Transfer"
          },
          "type": {
            "type": "string",
            "nullable": true,
            "enum": [
              "deposit",
              "withdrawal",
              "trade",
              "transfer",
              "payment"
            ],
            "description": "Canonical type derived from the label; null when the label has none."
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "comments": {
            "type": "array",
            "description": "Comment thread appended via POST /transactions/{id}/comments.",
            "items": {
              "type": "object",
              "properties": {
                "text": {
                  "type": "string"
                },
                "timestamp": {
                  "type": "integer",
                  "format": "int64"
                },
                "author": {
                  "type": "string"
                }
              }
            }
          },
          "isManual": {
            "type": "boolean"
          },
          "isEdited": {
            "type": "boolean"
          },
          "isDefiTrx": {
            "type": "boolean"
          },
          "isNFTTrx": {
            "type": "boolean"
          },
          "isMissingTransaction": {
            "type": "boolean",
            "description": "Set by the balance stage when the running balance went negative (missing purchase history)."
          },
          "coaStatus": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CoaStatus"
              }
            ],
            "description": "Enterprise only — COA tag + ERP-sync summary. Absent for retail workspaces."
          },
          "coaJournal": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CoaJournal"
              }
            ],
            "nullable": true,
            "description": "Enterprise only — COA journal header (null when untagged). Absent for retail. Includes `lines` only on GET /transactions/{id}; the list endpoint returns the header only."
          },
          "explorerLinkSrc": {
            "type": "string",
            "nullable": true,
            "enum": [
              "sender",
              "receiver"
            ],
            "description": "For detected transfers: which side to build the blockchain explorer link from."
          },
          "explorerLink": {
            "type": "string",
            "nullable": true,
            "description": "Blockchain explorer URL for this transaction’s on-chain hash. Null when the tx has no known chain explorer (e.g. a CEX trade) or no hash."
          },
          "isSplitted": {
            "type": "boolean",
            "description": "True when recovered from a split; excluded from transfer re-detection."
          },
          "isMergedTrx": {
            "type": "boolean",
            "description": "True only when the user merged this transaction by hand via POST /transactions/merge. Auto-detected Transfers / Bridge Transfers / Swaps leave it false — check `trxsMerged` to tell whether a row was formed from other transactions, regardless of who merged them."
          },
          "trxsMerged": {
            "type": "array",
            "nullable": true,
            "description": "Snapshots (without id) of the deposit + withdrawal consumed to form this transfer/swap; used to restore the originals on split.",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          },
          "netValue": {
            "type": "object",
            "nullable": true,
            "description": "Fiat value of the transaction = sum of `quantity × unit price` over ONE side of its value-bearing legs — the incoming side when present, otherwise the outgoing side. Both sides are never summed (that would double-count a trade), and fee legs are excluded. `fiatValue` is null when ANY incoming/outgoing leg has no usable price, so the total is never a partial sum or a misleading 0; a transaction with no incoming/outgoing legs at all is 0. Merged transactions carry the value inherited from their members (summed for same-side merges, taken from one side for deposit+withdrawal merges) rather than a recompute over the merged legs.",
            "properties": {
              "fiatValue": {
                "type": "number",
                "nullable": true,
                "description": "null when any incoming/outgoing leg is unpriced. Denominated in `currency` below, which is taken from the transaction's own legs on reprice paths and falls back to the workspace base currency."
              },
              "currency": {
                "type": "string",
                "example": "USD"
              }
            }
          },
          "incomingAssets": {
            "type": "array",
            "description": "Incoming ledger legs (persisted shape, not the create-request shape).",
            "items": {
              "$ref": "#/components/schemas/TransactionLedgerLeg"
            }
          },
          "outgoingAssets": {
            "type": "array",
            "description": "Outgoing ledger legs (persisted shape, not the create-request shape).",
            "items": {
              "$ref": "#/components/schemas/TransactionLedgerLeg"
            }
          },
          "fee": {
            "type": "array",
            "description": "Fee ledger legs (persisted shape, not the create-request shape).",
            "items": {
              "$ref": "#/components/schemas/TransactionLedgerLeg"
            }
          }
        }
      },
      "BatchTransaction": {
        "type": "object",
        "description": "A fully-formed transaction record for bulk import via /transactions/batch.",
        "required": [
          "timestamp",
          "label",
          "isManual",
          "isEdited",
          "isDefiTrx",
          "isNFTTrx"
        ],
        "properties": {
          "timestamp": {
            "type": "number",
            "description": "Unix epoch (ms).",
            "example": 1718800000000
          },
          "transactionPlatformId": {
            "type": "string",
            "description": "Source-platform transaction id (for dedupe)."
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "description": "Transaction label.",
            "example": "Trade"
          },
          "description": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "importSource": {
            "type": "object",
            "description": "Provenance of the imported transaction.",
            "required": [
              "type",
              "importedAt"
            ],
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "API",
                  "CSV",
                  "Manual"
                ],
                "description": "How the transaction entered the system.",
                "example": "CSV"
              },
              "importedAt": {
                "type": "number",
                "description": "Import time as Unix epoch (ms).",
                "example": 1718800000000
              },
              "walletId": {
                "type": "string",
                "description": "Integration account id the row came from."
              },
              "csvLink": {
                "type": "string",
                "description": "Storage link to the source CSV."
              },
              "syncId": {
                "type": "string",
                "description": "Sync run id that produced this row."
              },
              "functionName": {
                "type": "string",
                "description": "Parser/function that produced this row."
              }
            }
          },
          "isManual": {
            "type": "boolean",
            "description": "Manually entered (not synced).",
            "example": false
          },
          "isEdited": {
            "type": "boolean",
            "description": "Edited after import.",
            "example": false
          },
          "isDefiTrx": {
            "type": "boolean",
            "description": "Is a DeFi transaction.",
            "example": false
          },
          "isNFTTrx": {
            "type": "boolean",
            "description": "Is an NFT transaction.",
            "example": false
          },
          "protocol": {
            "type": "object",
            "description": "DeFi protocol metadata (when applicable).",
            "properties": {
              "functionName": {
                "type": "string",
                "description": "Contract function invoked."
              },
              "protocolId": {
                "type": "string",
                "description": "Protocol identifier."
              },
              "protocolName": {
                "type": "string",
                "description": "Protocol display name.",
                "example": "Uniswap V3"
              },
              "protocolLogoUrl": {
                "type": "string",
                "format": "uri",
                "description": "Protocol logo URL."
              }
            }
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Free-form tags."
          },
          "incomingAssets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IncomingAsset"
            },
            "default": [],
            "description": "Asset legs received."
          },
          "outgoingAssets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OutgoingAsset"
            },
            "default": [],
            "description": "Asset legs sent."
          },
          "fee": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FeeAsset"
            },
            "default": [],
            "description": "Fee legs."
          }
        }
      },
      "BulkReprocessUpdate": {
        "type": "object",
        "description": "A single transaction update for bulk update + reprocess. All fields except id are optional.",
        "required": [
          "id"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Transaction id to update."
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "description": "New label.",
            "example": "Trade"
          },
          "description": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "incomingAssets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IncomingAsset"
            }
          },
          "outgoingAssets": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OutgoingAsset"
            }
          },
          "fee": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FeeAsset"
            }
          }
        }
      },
      "WorkspaceInvite": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "wsi_abc123"
          },
          "workspaceId": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "roleId": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "editor",
              "viewer",
              "accountant"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "revoked",
              "expired"
            ]
          },
          "invitedBy": {
            "type": "string",
            "description": "UID of the inviting user"
          },
          "invitedByPlatformAdmin": {
            "type": "string",
            "nullable": true,
            "enum": [
              "platform_admin"
            ],
            "description": "Set when the invite was sent by a Kryptos platform administrator supporting the workspace, rather than by one of its own members. Null for an ordinary member invite."
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "InvitePreview": {
        "type": "object",
        "properties": {
          "workspaceId": {
            "type": "string"
          },
          "workspaceName": {
            "type": "string"
          },
          "workspaceType": {
            "type": "string",
            "enum": [
              "enterprise",
              "retail"
            ]
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "roleId": {
            "type": "string"
          },
          "roleName": {
            "type": "string",
            "example": "Admin"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "revoked",
              "expired"
            ]
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "MyPendingInvite": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "wsi_abc123"
          },
          "workspaceId": {
            "type": "string"
          },
          "workspaceName": {
            "type": "string"
          },
          "workspaceType": {
            "type": "string",
            "enum": [
              "enterprise",
              "retail"
            ]
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "roleId": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "editor",
              "viewer",
              "accountant"
            ]
          },
          "roleName": {
            "type": "string",
            "example": "Admin"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending"
            ]
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Organization": {
        "type": "object",
        "properties": {
          "orgId": {
            "type": "string",
            "example": "org_ab12cd34ef56"
          },
          "name": {
            "type": "string",
            "example": "Acme Inc."
          },
          "slug": {
            "type": "string",
            "example": "acme-inc"
          },
          "ownerId": {
            "type": "string",
            "description": "UID of the org owner"
          },
          "plan": {
            "type": "string",
            "enum": [
              "enterprise",
              "enterprise_plus"
            ],
            "example": "enterprise"
          },
          "stripeCustomerId": {
            "type": "string",
            "nullable": true,
            "description": "The org's Stripe customer — the billing identity all of its Enterprise workspace subscriptions bill to. Null until provisioned.",
            "example": "cus_ABC123"
          },
          "billingEmail": {
            "type": "string",
            "format": "email",
            "nullable": true,
            "description": "Billing contact for invoices/receipts. Falls back to the owner's email."
          },
          "tenantType": {
            "type": "string",
            "enum": [
              "enterprise",
              "cpa",
              "investigator"
            ],
            "description": "Which platform the org belongs to. 'cpa' = a CPA firm; 'investigator' = an investigator org, whose workspaces are investigation cases."
          },
          "cpaVerifiedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "CPA firms: when a platform admin verified the firm — a trust badge, not a gate. Kryptos Hub visibility is gated by listing review instead."
          },
          "cpaVerifiedBy": {
            "type": "string",
            "nullable": true
          },
          "config": {
            "type": "object",
            "nullable": true,
            "properties": {
              "maxWorkspaces": {
                "type": "integer"
              },
              "maxMembers": {
                "type": "integer"
              },
              "logo": {
                "type": "string",
                "description": "CPA firms: public URL of the uploaded logo (set via the logo endpoints)."
              },
              "trademark": {
                "type": "string",
                "description": "CPA firms"
              },
              "contactAddress": {
                "type": "string",
                "description": "CPA firms"
              },
              "contactPhone": {
                "type": "string",
                "description": "CPA firms"
              },
              "contactEmail": {
                "type": "string",
                "format": "email",
                "description": "CPA firms: shared inbox — notified of client invites. Not used by the firm lookup (unverified)."
              }
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrgMember": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "orgId": {
            "type": "string"
          },
          "userId": {
            "type": "string"
          },
          "roleId": {
            "type": "string",
            "enum": [
              "owner",
              "admin",
              "member",
              "org_read"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "suspended",
              "pending"
            ]
          },
          "invitedBy": {
            "type": "string",
            "nullable": true
          },
          "invitedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrgInvite": {
        "type": "object",
        "description": "Org invite record. The raw token is never returned — only its hash is stored.",
        "properties": {
          "id": {
            "type": "string"
          },
          "orgId": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "roleId": {
            "type": "string",
            "enum": [
              "admin",
              "member",
              "org_read"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "accepted",
              "revoked",
              "expired"
            ]
          },
          "invitedBy": {
            "type": "string",
            "description": "UID of the inviting user"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "acceptedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "acceptedBy": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OrgWorkspaceSummary": {
        "type": "object",
        "properties": {
          "wid": {
            "type": "string"
          },
          "workspaceName": {
            "type": "string"
          },
          "baseCurrencyCode": {
            "type": "string",
            "example": "AUD"
          },
          "lastSyncTime": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "memberCount": {
            "type": "integer",
            "example": 3
          }
        }
      },
      "OrgSummary": {
        "type": "object",
        "properties": {
          "org": {
            "$ref": "#/components/schemas/Organization"
          },
          "workspaces": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrgWorkspaceSummary"
            }
          },
          "totals": {
            "type": "object",
            "properties": {
              "workspaceCount": {
                "type": "integer"
              },
              "memberCount": {
                "type": "integer"
              }
            }
          }
        }
      },
      "HoldingItem": {
        "type": "object",
        "properties": {
          "assetId": {
            "type": "string"
          },
          "asset": {
            "$ref": "#/components/schemas/RawAsset"
          },
          "totalQuantity": {
            "type": "number"
          },
          "costBasis": {
            "type": "number",
            "description": "Total cost basis in USD"
          },
          "baseCurrency": {
            "type": "string",
            "example": "USD"
          },
          "assetDistribution": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "integrationId": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number"
                },
                "account": {
                  "type": "object"
                },
                "allocationPercentage": {
                  "type": "number",
                  "description": "Asset-wide allocation (wallet value / total asset value), sorted descending."
                },
                "transactionCount": {
                  "type": "number"
                },
                "portfolioName": {
                  "type": "string",
                  "nullable": true
                }
              }
            }
          },
          "marketPrice": {
            "type": "number"
          },
          "marketValue": {
            "type": "number"
          },
          "costPerUnit": {
            "type": "number",
            "description": "Average cost per unit (costBasis / totalQuantity). 0 when no cost basis."
          },
          "unrealizedPnL": {
            "type": "number"
          },
          "roiPercentage": {
            "type": "number",
            "nullable": true,
            "description": "ROI as a percentage of cost basis. null when cost basis is 0 — distinguishes 'no basis' from '0% return'."
          },
          "change24h": {
            "type": "number"
          },
          "change24hPercentage": {
            "type": "number"
          },
          "isSpam": {
            "type": "boolean",
            "description": "Marked as spam by user or global spam list."
          },
          "transactionCount": {
            "type": "integer",
            "description": "Workspace-wide count of transactions touching this asset."
          }
        }
      },
      "DashboardTotals": {
        "type": "object",
        "properties": {
          "totalNetWorth": {
            "type": "number",
            "description": "Grand total: liquid token holdings + NFT floor value + DeFi net value."
          },
          "liquidHoldings": {
            "type": "number",
            "description": "Token holdings value only (excludes NFT and DeFi)."
          },
          "costBasis": {
            "type": "number"
          },
          "unrealizedGains": {
            "type": "number",
            "description": "Token-only unrealized gains (liquidHoldings − costBasis)."
          },
          "change24Hour": {
            "type": "number"
          },
          "change24HourPercentage": {
            "type": "number"
          },
          "baseCurrency": {
            "type": "string",
            "example": "USD"
          }
        }
      },
      "DashboardSummary": {
        "allOf": [
          {
            "$ref": "#/components/schemas/DashboardTotals"
          },
          {
            "type": "object",
            "properties": {
              "totalHoldingsCount": {
                "type": "integer"
              },
              "totalNFTsBalance": {
                "type": "number"
              },
              "overview": {
                "type": "object",
                "properties": {
                  "totalTransactionsCount": {
                    "type": "integer"
                  },
                  "integrationsCount": {
                    "type": "integer"
                  },
                  "nftCount": {
                    "type": "integer"
                  },
                  "defiPositionsCount": {
                    "type": "integer"
                  }
                }
              },
              "tokenAllocation": {
                "type": "object",
                "properties": {
                  "topHoldings": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "asset": {
                          "$ref": "#/components/schemas/RawAsset"
                        },
                        "totalQuantity": {
                          "type": "number"
                        },
                        "marketValue": {
                          "type": "number"
                        },
                        "allocationPercentage": {
                          "type": "number",
                          "description": "Percentage of liquidHoldings (token book only)."
                        }
                      }
                    }
                  },
                  "others": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "type": "number"
                      },
                      "count": {
                        "type": "integer"
                      },
                      "percentage": {
                        "type": "number"
                      }
                    }
                  }
                }
              },
              "portfolioDistribution": {
                "type": "object",
                "properties": {
                  "byType": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "type": {
                          "type": "string"
                        },
                        "walletCount": {
                          "type": "integer"
                        },
                        "totalValue": {
                          "type": "number"
                        },
                        "percentage": {
                          "type": "number"
                        }
                      }
                    }
                  },
                  "defiPositions": {
                    "type": "object",
                    "properties": {
                      "value": {
                        "type": "number"
                      },
                      "count": {
                        "type": "integer"
                      }
                    }
                  }
                }
              },
              "topAccounts": {
                "type": "array",
                "items": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/AccountType"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "totalValue": {
                          "type": "number"
                        },
                        "type": {
                          "type": "string",
                          "enum": [
                            "exchange",
                            "blockchain",
                            "wallet",
                            "service"
                          ]
                        },
                        "portfolioName": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        ]
      },
      "Saft": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "projectName": {
            "type": "string",
            "nullable": true
          },
          "projectWebsite": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "tokenSymbol": {
            "type": "string",
            "nullable": true
          },
          "tokenContractAddress": {
            "type": "string",
            "nullable": true
          },
          "tokenChainInfo": {
            "type": "object",
            "nullable": true,
            "properties": {
              "name": {
                "type": "string"
              },
              "address": {
                "type": "string",
                "nullable": true
              },
              "chainId": {
                "type": "number",
                "nullable": true
              },
              "logo_url": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "tokenKryptosId": {
            "type": "string",
            "nullable": true
          },
          "investedAmount": {
            "type": "number",
            "nullable": true,
            "description": "USD amount invested"
          },
          "tokenAllocation": {
            "type": "number",
            "nullable": true
          },
          "fdv": {
            "type": "number",
            "nullable": true,
            "description": "Fully diluted valuation at time of investment"
          },
          "totalTokenSupply": {
            "type": "number",
            "nullable": true
          },
          "category": {
            "type": "string",
            "nullable": true
          },
          "riskLevel": {
            "type": "string",
            "enum": [
              "Low",
              "Medium",
              "High"
            ],
            "nullable": true
          },
          "investedDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "tgeDate": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "unlockAtTGE": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "nullable": true,
            "description": "Percentage unlocked at TGE"
          },
          "cliffMonths": {
            "type": "number",
            "minimum": 0,
            "nullable": true
          },
          "cadence": {
            "type": "string",
            "enum": [
              "Per second",
              "Per minute",
              "Per hour",
              "Per day",
              "Per week",
              "Per month",
              "Quarterly",
              "Annually"
            ],
            "nullable": true
          },
          "releaseAtCliffEnd": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "nullable": true
          },
          "vestingCondition": {
            "type": "string",
            "enum": [
              "Linear"
            ],
            "nullable": true
          },
          "vestingEnd": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "tokenUrl": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "vestingPortalLink": {
            "type": "string",
            "format": "uri",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "walletIntegration": {
            "type": "string",
            "nullable": true
          },
          "source": {
            "type": "string",
            "enum": [
              "Manual Entry",
              "Team Finance",
              "PDF Upload",
              "Sablier"
            ],
            "nullable": true
          },
          "status": {
            "type": "string",
            "enum": [
              "Agreement Signed",
              "Token Warrant",
              "Launching Soon",
              "Cliff in Progress",
              "Vesting in Progress",
              "Vesting Completed"
            ],
            "nullable": true
          },
          "progress": {
            "type": "number",
            "nullable": true,
            "description": "Vesting progress 0–100"
          },
          "roi": {
            "type": "number",
            "nullable": true
          },
          "tokenCurrentValue": {
            "type": "number",
            "nullable": true
          },
          "unrealizedGain": {
            "type": "number",
            "nullable": true
          },
          "nextUnlock": {
            "type": "object",
            "nullable": true,
            "properties": {
              "date": {
                "type": "string",
                "format": "date-time"
              },
              "amount": {
                "type": "number"
              },
              "percentage": {
                "type": "number"
              },
              "cadence": {
                "type": "string"
              },
              "timeUntilUnlock": {
                "type": "string"
              },
              "timeUntilUnlockFormatted": {
                "type": "string"
              },
              "vestingEvent": {
                "type": "string",
                "nullable": true
              },
              "type": {
                "type": "string"
              }
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SaftClaim": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "saftId": {
            "type": "string",
            "format": "uuid"
          },
          "userId": {
            "type": "string"
          },
          "claimDate": {
            "type": "string",
            "format": "date-time"
          },
          "tokenAmount": {
            "type": "number"
          },
          "claimPriceUsd": {
            "type": "number",
            "nullable": true
          },
          "chainInfo": {
            "type": "object",
            "nullable": true,
            "properties": {
              "chainId": {
                "type": "number"
              },
              "chainName": {
                "type": "string"
              },
              "address": {
                "type": "string"
              }
            }
          },
          "transactionHash": {
            "type": "string",
            "nullable": true
          },
          "kryptosTrxId": {
            "type": "string",
            "nullable": true
          },
          "claimTokenSymbol": {
            "type": "string",
            "nullable": true
          },
          "claimTokenAddress": {
            "type": "string",
            "nullable": true
          },
          "claimTokenKryptosId": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SaftFile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "bucketPath": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AccountingSettings": {
        "type": "object",
        "description": "Resolved engine config for the workspace (method + fiscal + toggles).",
        "properties": {
          "method": {
            "type": "string",
            "example": "FIFO",
            "description": "Cost-basis method."
          },
          "baseCurrency": {
            "type": "string",
            "example": "USD"
          },
          "timezone": {
            "type": "string",
            "example": "Australia/Sydney"
          },
          "fiscalStart": {
            "type": "string",
            "example": "01/07",
            "description": "DD/MM"
          },
          "fiscalEnd": {
            "type": "string",
            "example": "30/06",
            "description": "DD/MM"
          },
          "countryCode": {
            "type": "string",
            "nullable": true,
            "example": "AU"
          },
          "advancedTxSettings": {
            "$ref": "#/components/schemas/AdvancedTxSettings"
          },
          "tagsException": {
            "type": "object",
            "nullable": true,
            "additionalProperties": {
              "type": "string"
            },
            "description": "Per-label tax-event overrides."
          }
        }
      },
      "AccountingTaxReport": {
        "type": "object",
        "description": "Per fiscal-year × method capital-gains report.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "fiscalYear": {
            "type": "integer",
            "example": 2024
          },
          "method": {
            "type": "string",
            "example": "FIFO"
          },
          "baseCurrency": {
            "type": "string",
            "example": "USD"
          },
          "totalProceeds": {
            "type": "number",
            "description": "Sum of disposal proceeds."
          },
          "totalCostBasis": {
            "type": "number"
          },
          "totalGains": {
            "type": "number",
            "description": "Realized = proceeds − cost basis."
          },
          "disposalsCount": {
            "type": "integer"
          },
          "missingPurchaseCount": {
            "type": "integer",
            "description": "Disposals priced zero/oversell (missing purchase history)."
          },
          "summary": {
            "type": "object",
            "nullable": true,
            "description": "TaxCalculation: capitalGain/Loss + ST/LT split when applicable, plus otherGains."
          },
          "breakdown": {
            "type": "object",
            "nullable": true,
            "description": "{ currencyWise } — per-asset gains. SOY/EOY open lots are NOT stored here; read them from the /reports/{year}/lots endpoint (checkpoints)."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DisposalLot": {
        "type": "object",
        "description": "One acquisition↔disposal lot match (default kind='disposal').",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "disposal",
              "transfer",
              "fee",
              "other_gain"
            ],
            "description": "Row kind; the disposals endpoint returns kind='disposal'."
          },
          "disposalLedgerId": {
            "type": "string",
            "format": "uuid"
          },
          "acquisitionLedgerId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "qty": {
            "type": "number"
          },
          "costBasis": {
            "type": "number"
          },
          "proceeds": {
            "type": "number",
            "nullable": true
          },
          "profit": {
            "type": "number",
            "nullable": true
          },
          "acquiredTs": {
            "type": "number",
            "nullable": true,
            "description": "Original acquisition (Unix ms); null for a pool slice / missing purchase."
          },
          "disposedTs": {
            "type": "number",
            "description": "Unix ms."
          },
          "isZeroCost": {
            "type": "boolean"
          },
          "assetId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "assetSymbol": {
            "type": "string",
            "nullable": true,
            "example": "BTC"
          }
        }
      },
      "AccountingPeriodLock": {
        "type": "object",
        "description": "A filed/frozen fiscal period (blocks edits within it).",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "periodEnd": {
            "type": "number",
            "description": "Period-end boundary (Unix ms)."
          },
          "periodKind": {
            "type": "string",
            "enum": [
              "quarter",
              "year"
            ]
          },
          "method": {
            "type": "string",
            "example": "FIFO"
          },
          "lockedBy": {
            "type": "string",
            "nullable": true
          },
          "reportRef": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "BreakdownEntry": {
        "type": "object",
        "description": "One aggregated line in a derived breakdown (per label × asset).",
        "properties": {
          "label": {
            "type": "string",
            "example": "Staking Rewards"
          },
          "assetId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "currency": {
            "type": "string",
            "example": "ETH"
          },
          "value": {
            "type": "number"
          },
          "count": {
            "type": "integer"
          }
        }
      },
      "DerivedBreakdown": {
        "type": "object",
        "description": "On-read breakdown — NOT persisted; recomputed from ledgers each call (§7.1).",
        "properties": {
          "income": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BreakdownEntry"
            }
          },
          "expenses": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BreakdownEntry"
            }
          },
          "giftDonationsLost": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BreakdownEntry"
            }
          },
          "otherGains": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BreakdownEntry"
            }
          },
          "unmatched": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BreakdownEntry"
            }
          }
        }
      },
      "LotSnapshotPosition": {
        "type": "object",
        "description": "One aggregated open position (cost basis only) at a point in time.",
        "properties": {
          "assetId": {
            "type": "string",
            "format": "uuid"
          },
          "walletId": {
            "type": "string",
            "nullable": true,
            "description": "Present only in per-wallet mode."
          },
          "quantity": {
            "type": "number"
          },
          "costBasis": {
            "type": "number"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "name": {
            "type": "string"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true
          },
          "chainId": {
            "type": "string",
            "nullable": true,
            "description": "Best-effort, from one representative holding."
          },
          "contractAddress": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "LotSnapshot": {
        "type": "object",
        "description": "Aggregated open lots as of an instant (from the nearest checkpoint ≤ asOf).",
        "properties": {
          "asOf": {
            "type": "number",
            "description": "The instant requested (Unix ms)."
          },
          "boundaryTs": {
            "type": "number",
            "nullable": true,
            "description": "boundary_ts of the checkpoint used; null when none exists ≤ asOf."
          },
          "mode": {
            "type": "string",
            "enum": [
              "universal",
              "per_wallet"
            ]
          },
          "totalCostBasis": {
            "type": "number"
          },
          "positions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LotSnapshotPosition"
            }
          }
        }
      },
      "YearLotSnapshots": {
        "type": "object",
        "description": "Start-of-year + end-of-year open-lot snapshots for a fiscal year.",
        "properties": {
          "year": {
            "type": "integer",
            "example": 2024
          },
          "method": {
            "type": "string",
            "example": "FIFO"
          },
          "mode": {
            "type": "string",
            "enum": [
              "universal",
              "per_wallet"
            ]
          },
          "soy": {
            "$ref": "#/components/schemas/LotSnapshot"
          },
          "eoy": {
            "$ref": "#/components/schemas/LotSnapshot"
          }
        }
      },
      "DeviceToken": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "userId": {
            "type": "string"
          },
          "fcmToken": {
            "type": "string"
          },
          "deviceId": {
            "type": "string",
            "nullable": true
          },
          "deviceName": {
            "type": "string",
            "nullable": true
          },
          "os": {
            "type": "string",
            "nullable": true
          },
          "appVersion": {
            "type": "string",
            "nullable": true
          },
          "active": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CoaAccount": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "platform": {
            "type": "string",
            "enum": [
              "xero",
              "quickbooks",
              "softledger",
              "custom",
              "default"
            ]
          },
          "code": {
            "type": "string",
            "example": "4000",
            "description": "GL account code (alphanumeric)"
          },
          "class": {
            "type": "string",
            "enum": [
              "ASSET",
              "EQUITY",
              "EXPENSE",
              "LIABILITY",
              "REVENUE"
            ],
            "example": "REVENUE"
          },
          "name": {
            "type": "string",
            "example": "Crypto Revenue"
          },
          "description": {
            "type": "string"
          },
          "archived": {
            "type": "boolean"
          },
          "isSyncedToIntegration": {
            "type": "boolean"
          },
          "lastSyncTime": {
            "type": "integer",
            "nullable": true,
            "description": "epoch ms"
          },
          "taxInfo": {
            "type": "object",
            "nullable": true
          },
          "rawData": {
            "type": "object",
            "nullable": true,
            "description": "raw ERP account payload"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Notification": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "userId": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "price_alert",
              "tax_report",
              "sync_complete",
              "sync_error",
              "account_activity",
              "workspace_invite",
              "product_announcement",
              "system"
            ]
          },
          "title": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "nullable": true,
            "description": "Arbitrary payload metadata"
          },
          "read": {
            "type": "boolean"
          },
          "readAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UserPreferences": {
        "type": "object",
        "properties": {
          "channels": {
            "type": "object",
            "additionalProperties": {
              "type": "boolean"
            },
            "description": "e.g. { push: true, email: false, in_app: true }"
          },
          "topics": {
            "type": "object",
            "additionalProperties": {
              "type": "boolean"
            },
            "description": "e.g. { price_alerts: true, tax_reports: false }"
          },
          "quietHours": {
            "type": "object",
            "nullable": true,
            "properties": {
              "start": {
                "type": "string",
                "example": "22:00"
              },
              "end": {
                "type": "string",
                "example": "08:00"
              },
              "timezone": {
                "type": "string",
                "example": "Australia/Sydney"
              }
            }
          }
        }
      },
      "RegisterDeviceRequest": {
        "type": "object",
        "required": [
          "fcmToken"
        ],
        "properties": {
          "fcmToken": {
            "type": "string",
            "minLength": 1,
            "description": "FCM device token"
          },
          "deviceId": {
            "type": "string",
            "description": "Unique device identifier"
          },
          "deviceName": {
            "type": "string",
            "description": "Human-readable device name"
          },
          "os": {
            "type": "string",
            "description": "e.g. ios, android, web"
          },
          "appVersion": {
            "type": "string",
            "description": "App version string"
          }
        }
      },
      "RemoveDeviceRequest": {
        "type": "object",
        "properties": {
          "fcmToken": {
            "type": "string",
            "description": "FCM token to remove"
          },
          "deviceId": {
            "type": "string",
            "description": "Device ID to remove by"
          }
        },
        "description": "Provide fcmToken or deviceId (at least one required)"
      },
      "TopicSubscribeRequest": {
        "type": "object",
        "required": [
          "topic"
        ],
        "properties": {
          "topic": {
            "type": "string",
            "minLength": 1,
            "description": "FCM topic name"
          },
          "tokens": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Specific tokens to (un)subscribe. Defaults to all active tokens."
          }
        }
      },
      "CoaRule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "category": {
            "type": "string",
            "enum": [
              "DEFAULT_RULES",
              "ASSET_RULES",
              "CUSTOM_RULES"
            ]
          },
          "ruleName": {
            "type": "string",
            "example": "Staking Rewards"
          },
          "coa": {
            "type": "string",
            "nullable": true,
            "description": "GL code assigned on match; null if the referenced account was removed"
          },
          "rank": {
            "type": "integer",
            "description": "lower rank matches first"
          },
          "isWorking": {
            "type": "boolean",
            "description": "false = soft-deleted/disabled"
          },
          "ledgerType": {
            "type": "string",
            "nullable": true,
            "enum": [
              "Incoming",
              "Outgoing",
              "All"
            ]
          },
          "assets": {
            "nullable": true,
            "description": "AssetRef[] or the literal 'All Assets'",
            "oneOf": [
              {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/AssetRef"
                }
              },
              {
                "type": "string",
                "enum": [
                  "All Assets"
                ]
              }
            ]
          },
          "label": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/LabelRef"
            }
          },
          "accounts": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/AccountRef"
            }
          },
          "counterParty": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/AccountRef"
            }
          },
          "comment": {
            "type": "string",
            "nullable": true
          },
          "assetAmount": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "netValue": {
            "type": "string",
            "nullable": true,
            "description": "numeric"
          },
          "conditions": {
            "$ref": "#/components/schemas/RuleConditions"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AssetRef": {
        "type": "object",
        "required": [
          "id",
          "symbol"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "name": {
            "type": "string"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true,
            "description": "Resolved on read from the assets table; null when unmatched"
          }
        }
      },
      "LabelRef": {
        "type": "object",
        "required": [
          "label"
        ],
        "properties": {
          "label": {
            "type": "string",
            "example": "Deposit"
          }
        }
      },
      "AccountRef": {
        "type": "object",
        "properties": {
          "alias": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "address": {
            "type": "string"
          },
          "walletId": {
            "type": "string"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true,
            "description": "Resolved on read — by walletId (integration provider logo) for accounts[], by address (counter_parties.logo) for counterParty[]; null when unmatched"
          }
        }
      },
      "RuleConditions": {
        "type": "object",
        "nullable": true,
        "description": "Per-field match operators (IN/NOT_IN for sets; comparators for amounts)",
        "properties": {
          "Assets": {
            "type": "string",
            "enum": [
              "IN",
              "NOT_IN"
            ]
          },
          "Label": {
            "type": "string",
            "enum": [
              "IN",
              "NOT_IN"
            ]
          },
          "accounts": {
            "type": "string",
            "enum": [
              "IN",
              "NOT_IN"
            ]
          },
          "counterParty": {
            "type": "string",
            "enum": [
              "IN",
              "NOT_IN"
            ]
          },
          "comment": {
            "type": "string",
            "enum": [
              "IN",
              "NOT_IN"
            ]
          },
          "assetAmount": {
            "type": "string",
            "enum": [
              "EQUAL_TO",
              "LESS_THAN",
              "GREATER_THAN",
              "LESS_THAN_OR_EQUAL_TO",
              "GREATER_THAN_OR_EQUAL_TO"
            ]
          },
          "netValue": {
            "type": "string",
            "enum": [
              "EQUAL_TO",
              "LESS_THAN",
              "GREATER_THAN",
              "LESS_THAN_OR_EQUAL_TO",
              "GREATER_THAN_OR_EQUAL_TO"
            ]
          }
        }
      },
      "CoaJournal": {
        "type": "object",
        "description": "A journal is a 1-1 extension of a transaction, keyed by transactionId (no separate id). Shared shape for GET /coa/journals and the coaJournal field on the transactions endpoints — workspaceId/timestampOfTransaction/createdAt/updatedAt are only populated by GET /coa/journals.",
        "properties": {
          "transactionId": {
            "type": "string",
            "format": "uuid",
            "description": "Primary key (the transaction)"
          },
          "workspaceId": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "isTitleEdited": {
            "type": "boolean"
          },
          "transactionAmount": {
            "type": "string",
            "description": "numeric (dollars)"
          },
          "baseCurrency": {
            "type": "string",
            "description": "The journal's reporting currency (default USD). Only on GET /coa/journals."
          },
          "timestampOfTransaction": {
            "type": "integer",
            "description": "epoch ms — the parent transaction timestamp (joined)"
          },
          "syncedToERP": {
            "type": "boolean",
            "description": "Whether these amounts are in the ERP."
          },
          "syncedVia": {
            "type": "string",
            "enum": [
              "journal",
              "rollup"
            ],
            "nullable": true,
            "description": "HOW it got there. `journal` — pushed on its own, and it holds its own ERP id. `rollup` — posted as part of a period close, which holds the ERP id; this journal's own id columns are null and that is correct. `null` — not in the ERP.\n\nDerived from `syncedToERP` + `rollupId`. Without it a close-posted row reads as 'synced' while holding no ERP id anywhere, which looks like a bug."
          },
          "rollupId": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "The period close this journal belongs to, or null. Written when the close is CREATED, so it can be set while `syncedToERP` is still false — the close exists but has not been pushed. A journal carrying this is excluded from new closes, and an explicit push of it is rejected with COVERED_BY_ROLLUP."
          },
          "erpError": {
            "type": "string",
            "nullable": true
          },
          "xeroJournalId": {
            "type": "string",
            "nullable": true
          },
          "softledgerJournalId": {
            "type": "string",
            "nullable": true
          },
          "quickBookJournalCreds": {
            "type": "object",
            "nullable": true,
            "properties": {
              "quickBooksJournalId": {
                "type": "string"
              },
              "syncToken": {
                "type": "string"
              }
            }
          },
          "rollup": {
            "type": "object",
            "nullable": true,
            "description": "The close named by `rollupId`, hydrated — carrying the CLOSE's ERP ids, not this journal's. When `syncedVia` is `rollup` these are the only ids that resolve to anything in the ERP, so render from here rather than fetching the close separately. Null when the journal belongs to no close. Populated only by the transactions endpoints, not GET /coa/journals.",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "title": {
                "type": "string"
              },
              "journalDate": {
                "type": "integer",
                "description": "epoch ms — the date the close posts under"
              },
              "syncedToERP": {
                "type": "boolean"
              },
              "isDirty": {
                "type": "boolean",
                "description": "The journals under this close have changed since it was pushed, so the ERP copy is stale."
              },
              "xeroJournalId": {
                "type": "string",
                "nullable": true
              },
              "softledgerJournalId": {
                "type": "string",
                "nullable": true
              },
              "quickBookJournalCreds": {
                "type": "object",
                "nullable": true,
                "properties": {
                  "quickBooksJournalId": {
                    "type": "string"
                  },
                  "syncToken": {
                    "type": "string"
                  }
                }
              },
              "erpError": {
                "type": "string",
                "nullable": true
              }
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lines": {
            "type": "array",
            "description": "Present on GET /coa/journals when includeLines=true, and unconditionally on GET /transactions/{id} (enterprise). Absent from GET /coa/journals otherwise and from the GET /transactions list endpoint (header only).",
            "items": {
              "$ref": "#/components/schemas/CoaLine"
            }
          }
        }
      },
      "CoaLine": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "transactionId": {
            "type": "string",
            "format": "uuid",
            "description": "Parent journal/transaction"
          },
          "label": {
            "type": "string",
            "enum": [
              "CREDIT",
              "DEBIT"
            ]
          },
          "amount": {
            "type": "string",
            "description": "numeric (dollars)"
          },
          "baseCurrency": {
            "type": "string",
            "description": "The line's reporting currency (default USD). Only on GET /coa/journals."
          },
          "coaCode": {
            "type": "string"
          },
          "timestamp": {
            "type": "integer",
            "description": "epoch ms"
          },
          "title": {
            "type": "string"
          },
          "createdThrough": {
            "type": "string"
          },
          "coaAccount": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CoaLineAccount"
              }
            ],
            "nullable": true,
            "description": "The account this line resolves to (name/class/etc). Populated on GET /transactions/{id} and on GET /coa/journals when includeLines=true; null when the code no longer resolves to an account."
          }
        }
      },
      "CoaRollup": {
        "type": "object",
        "description": "A rollup journal — ONE summary journal standing in for every per-transaction journal in a date range, with one line per GL account carrying that account's net (debits minus credits). Unlike a journal it has its own id and its own date, because it spans many transactions and owns none of them. Immutable: it is never regenerated. A rollup CLAIMS the journals it covered, so those transactions are excluded from later rollups and from individual ERP pushes. When the rollup is PUSHED, those covered journals are marked `syncedToERP` too — their amounts really are in the ERP, by way of the rollup. Deleting a pushed rollup releases the claims and puts that flag back down.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "isTitleEdited": {
            "type": "boolean"
          },
          "startTime": {
            "type": "integer",
            "description": "epoch ms — start of the rolled-up range"
          },
          "endTime": {
            "type": "integer",
            "description": "epoch ms — end of the rolled-up range"
          },
          "journalDate": {
            "type": "integer",
            "description": "epoch ms — the date stamped on the ERP journal. Defaults to endTime."
          },
          "totalAmount": {
            "type": "string",
            "description": "numeric (dollars) — the journal total"
          },
          "roundingAdjustment": {
            "type": "string",
            "description": "numeric (dollars), signed. The residual (ΣDebit − ΣCredit) across the covered journals BEFORE it was plugged into the Small Errors account. Non-zero means the source journals did not balance among themselves — surfaced rather than hidden."
          },
          "coveredCount": {
            "type": "integer",
            "description": "How many per-transaction journals this rollup absorbed."
          },
          "baseCurrency": {
            "type": "string"
          },
          "syncedToERP": {
            "type": "boolean"
          },
          "erpError": {
            "type": "string",
            "nullable": true
          },
          "xeroJournalId": {
            "type": "string",
            "nullable": true
          },
          "softledgerJournalId": {
            "type": "string",
            "nullable": true
          },
          "quickBookJournalCreds": {
            "type": "object",
            "nullable": true,
            "properties": {
              "quickBooksJournalId": {
                "type": "string"
              },
              "syncToken": {
                "type": "string"
              }
            }
          },
          "filters": {
            "type": "object",
            "nullable": true,
            "description": "The transaction filters that selected this rollup's members, as sent. Answers 'which transactions did this represent, and why those' from the row alone, and can be replayed into POST /coa/rollups/preview to top up the same selection after a backfill. Null on rollups created before filters existed (a plain range)."
          },
          "diagnostics": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/CoaRollupIssue"
            },
            "description": "The warnings accepted when this rollup was created — an imbalance plugged into Small Errors, a journal date outside the period. Blocking issues can never appear here. Stored rather than recomputed: the journals underneath keep changing after a rollup is posted, so a recomputed answer would describe today's data."
          },
          "createdBy": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "lines": {
            "type": "array",
            "description": "Populated on GET /coa/rollups/{id}, and on the list when includeLines=true.",
            "items": {
              "$ref": "#/components/schemas/CoaRollupLine"
            }
          },
          "coveredTransactionIds": {
            "type": "array",
            "description": "Deprecated — no longer returned. Replay `filters` against GET /transactions.",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "CoaRollupLine": {
        "type": "object",
        "description": "One GL account's net across the rolled-up period. `amount` is always positive — the side is in `label`.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceId": {
            "type": "string"
          },
          "rollupId": {
            "type": "string",
            "format": "uuid",
            "description": "Parent rollup"
          },
          "label": {
            "type": "string",
            "enum": [
              "CREDIT",
              "DEBIT"
            ]
          },
          "amount": {
            "type": "string",
            "description": "numeric (dollars), always positive"
          },
          "baseCurrency": {
            "type": "string"
          },
          "coaCode": {
            "type": "string"
          },
          "timestamp": {
            "type": "integer",
            "description": "epoch ms — the rollup's journalDate"
          },
          "title": {
            "type": "string"
          },
          "createdThrough": {
            "type": "string",
            "example": "Rollup"
          },
          "coaAccount": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CoaLineAccount"
              }
            ],
            "nullable": true,
            "description": "null when the code no longer resolves to an account."
          }
        }
      },
      "CoaRollupIssue": {
        "type": "object",
        "description": "One problem found while computing a rollup. Reported rather than thrown, so the whole set can be shown at once.",
        "properties": {
          "code": {
            "type": "string",
            "enum": [
              "UNTAGGED_TRANSACTIONS",
              "MIXED_BASE_CURRENCY",
              "NO_SMALL_ERRORS_ACCOUNT",
              "DEBIT_CREDIT_MISMATCH",
              "NOTHING_ELIGIBLE",
              "SYNCED_FILTER_EXCLUDES_ALL",
              "TOO_FEW_LINES",
              "JOURNAL_DATE_OUTSIDE_RANGE",
              "PERIOD_ALREADY_CLOSED",
              "PERIOD_NOT_FULLY_COVERED"
            ]
          },
          "severity": {
            "type": "string",
            "enum": [
              "blocking",
              "warning"
            ],
            "description": "`blocking` refuses POST /coa/rollups (409 ROLLUP_BLOCKED). `warning` is allowed through and stored on the rollup's `diagnostics`."
          },
          "message": {
            "type": "string",
            "description": "Ready to show to the user."
          },
          "count": {
            "type": "integer",
            "description": "Transactions affected, when the issue is a count."
          },
          "amount": {
            "type": "string",
            "description": "The amount at stake, when it is a money issue."
          },
          "transactionIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Up to 50 offending transactions, for linking straight to them."
          },
          "details": {
            "type": "object",
            "description": "Issue-specific extras (currencies found, …)."
          }
        }
      },
      "CoaRollupDraft": {
        "type": "object",
        "description": "The computed rollup returned by POST /coa/rollups/preview — exactly what creating it would persist, nothing written. `transactionIds` is deliberately omitted (a quarter covers tens of thousands); use `coveredCount`.",
        "properties": {
          "startTime": {
            "type": "integer"
          },
          "endTime": {
            "type": "integer"
          },
          "journalDate": {
            "type": "integer"
          },
          "journalDateFormatted": {
            "type": "string",
            "example": "2024-01-31",
            "description": "The exact date string that will reach the ERP, rendered in the workspace timezone. Shown because an epoch-ms range built from UTC midnights renders a day late for any workspace ahead of UTC — which would post the period into the next month."
          },
          "title": {
            "type": "string"
          },
          "baseCurrency": {
            "type": "string"
          },
          "coveredCount": {
            "type": "integer"
          },
          "totalAmount": {
            "type": "string"
          },
          "roundingAdjustment": {
            "type": "string"
          },
          "filters": {
            "type": "object",
            "description": "The selection this draft was built from, echoed back so it can be replayed."
          },
          "diagnostics": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CoaRollupIssue"
            },
            "description": "Everything wrong with this rollup. Empty means it is ready to create. Any entry with `severity: blocking` means POST /coa/rollups will refuse it."
          },
          "lines": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label": {
                  "type": "string",
                  "enum": [
                    "CREDIT",
                    "DEBIT"
                  ]
                },
                "coaCode": {
                  "type": "string"
                },
                "amount": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CoaLineAccount": {
        "type": "object",
        "description": "Curated coa_accounts details attached to a journal line for display.",
        "properties": {
          "code": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "class": {
            "type": "string",
            "description": "e.g. ASSET, REVENUE, EXPENSE"
          },
          "description": {
            "type": "string"
          },
          "taxInfo": {
            "type": "object",
            "nullable": true,
            "properties": {
              "percentageRate": {
                "type": "number"
              },
              "taxRuleName": {
                "type": "string"
              }
            }
          },
          "platform": {
            "type": "string",
            "enum": [
              "xero",
              "quickbooks",
              "softledger",
              "custom",
              "default"
            ]
          },
          "archived": {
            "type": "boolean"
          },
          "isSyncedToIntegration": {
            "type": "boolean"
          }
        }
      },
      "CoaLedger": {
        "type": "object",
        "description": "A ledger row with its assigned COA codes (subset of the ledgers table)",
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "transactionId": {
            "type": "string"
          },
          "assetId": {
            "type": "string",
            "nullable": true
          },
          "type": {
            "type": "string",
            "enum": [
              "incoming",
              "outgoing",
              "fee"
            ]
          },
          "label": {
            "type": "string",
            "nullable": true
          },
          "quantity": {
            "type": "string",
            "nullable": true
          },
          "debitCoaCode": {
            "type": "string",
            "nullable": true
          },
          "creditCoaCode": {
            "type": "string",
            "nullable": true
          },
          "isDebitCoaEdited": {
            "type": "boolean"
          },
          "isCreditCoaEdited": {
            "type": "boolean"
          },
          "debitCoaRuleId": {
            "type": "string",
            "format": "uuid",
            "nullable": true,
            "description": "Rule that set the debit code (null = manual edit or default-map code)"
          },
          "creditCoaRuleId": {
            "type": "string",
            "format": "uuid",
            "nullable": true
          },
          "coaRuleAppliedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "When a rule last (re)assigned this ledger"
          },
          "timestamp": {
            "type": "integer",
            "description": "epoch ms"
          }
        }
      },
      "CoaStatus": {
        "type": "object",
        "description": "Per-transaction COA tag + ERP-sync summary (enterprise only).",
        "properties": {
          "tagStatus": {
            "type": "string",
            "enum": [
              "tagged",
              "partial",
              "untagged"
            ],
            "description": "tagged = every ledger carries the COA side(s) its transaction type requires (both for deposit/withdrawal/payment, one for trade/transfer legs, always both for a fee leg); partial = some work is done and something is still missing; untagged = nothing is done. Progress is judged on non-fee legs, falling back to fee legs on a fee-only transaction."
          },
          "syncedToERP": {
            "type": "boolean"
          }
        }
      },
      "ErpIntegration": {
        "type": "object",
        "description": "A supported ERP integration from the catalog (erp_platforms). Returned by GET /coa/erps.",
        "properties": {
          "platform": {
            "type": "string",
            "enum": [
              "xero",
              "quickbooks",
              "softledger",
              "custom"
            ],
            "description": "Slug; the frontend maps this to its bundled logo."
          },
          "displayName": {
            "type": "string",
            "example": "Xero"
          },
          "description": {
            "type": "string"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true,
            "description": "Null when the frontend uses its bundled icon; a CDN URL for a future ERP."
          },
          "enabled": {
            "type": "boolean",
            "description": "Only enabled entries are returned by GET /coa/erps."
          },
          "isConnected": {
            "type": "boolean",
            "description": "Whether the CURRENT workspace has this ERP connected. The frontend renders isConnected=true under 'Connected' and the rest under 'We also support'. Always false for `custom` (CSV import, no connection)."
          }
        }
      },
      "ErpConnectionStatus": {
        "type": "object",
        "properties": {
          "isConnected": {
            "type": "boolean"
          },
          "tenantInfo": {
            "type": "object",
            "nullable": true
          },
          "tenantList": {
            "type": "array",
            "nullable": true,
            "items": {
              "type": "object"
            }
          },
          "baseCurrency": {
            "type": "string",
            "nullable": true,
            "example": "USD"
          },
          "defaultLocationId": {
            "type": "integer",
            "nullable": true
          },
          "defaultLocationName": {
            "type": "string",
            "nullable": true
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "lastSyncAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "CMCStatus": {
        "type": "object",
        "properties": {
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "example": "2026-06-24T08:24:14.354Z"
          },
          "error_code": {
            "type": "integer",
            "example": 0
          },
          "error_message": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "elapsed": {
            "type": "integer",
            "example": 6
          },
          "credit_count": {
            "type": "integer",
            "example": 1
          },
          "total_count": {
            "type": "integer",
            "example": 8114
          },
          "notice": {
            "type": "string",
            "nullable": true,
            "example": null
          }
        }
      },
      "CMCQuoteUSD": {
        "type": "object",
        "properties": {
          "price": {
            "type": "number",
            "example": 62570.66
          },
          "volume_24h": {
            "type": "number",
            "example": 27660726016.31
          },
          "volume_change_24h": {
            "type": "number",
            "example": 0.93
          },
          "cex_volume_24h": {
            "type": "number",
            "example": 27616815497.42
          },
          "dex_volume_24h": {
            "type": "number",
            "example": 43910518.89
          },
          "percent_change_1h": {
            "type": "number",
            "example": -0.096
          },
          "percent_change_24h": {
            "type": "number",
            "example": 0.245
          },
          "percent_change_7d": {
            "type": "number",
            "example": -4.148
          },
          "percent_change_30d": {
            "type": "number",
            "example": -18.992
          },
          "percent_change_60d": {
            "type": "number",
            "example": -19.342
          },
          "percent_change_90d": {
            "type": "number",
            "example": -10.37
          },
          "market_cap": {
            "type": "number",
            "example": 1254372247995
          },
          "market_cap_dominance": {
            "type": "number",
            "example": 58.45
          },
          "fully_diluted_market_cap": {
            "type": "number",
            "example": 1313983945355
          },
          "tvl": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "last_updated": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CMCCoinListing": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Bitcoin"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "slug": {
            "type": "string",
            "example": "bitcoin"
          },
          "cmc_rank": {
            "type": "integer",
            "example": 1
          },
          "num_market_pairs": {
            "type": "integer",
            "example": 12662
          },
          "circulating_supply": {
            "type": "number",
            "example": 20047290
          },
          "total_supply": {
            "type": "number",
            "example": 20047290
          },
          "max_supply": {
            "type": "number",
            "nullable": true,
            "example": 21000000
          },
          "infinite_supply": {
            "type": "boolean",
            "example": false
          },
          "date_added": {
            "type": "string",
            "format": "date-time",
            "example": "2010-07-13T00:00:00.000Z"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "mineable",
              "pow",
              "sha-256"
            ]
          },
          "platform": {
            "type": "object",
            "nullable": true,
            "example": null
          },
          "self_reported_circulating_supply": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "self_reported_market_cap": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "minted_market_cap": {
            "type": "number",
            "nullable": true,
            "example": 1254372247995
          },
          "tvl_ratio": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "last_updated": {
            "type": "string",
            "format": "date-time"
          },
          "quote": {
            "type": "object",
            "properties": {
              "USD": {
                "$ref": "#/components/schemas/CMCQuoteUSD"
              }
            }
          }
        }
      },
      "CMCCoinDetail": {
        "type": "object",
        "description": "Merged coin metadata (from /cryptocurrency/info) + current USD quote (from /cryptocurrency/quotes/latest)",
        "properties": {
          "id": {
            "type": "integer",
            "example": 1
          },
          "name": {
            "type": "string",
            "example": "Bitcoin"
          },
          "symbol": {
            "type": "string",
            "example": "BTC"
          },
          "slug": {
            "type": "string",
            "example": "bitcoin"
          },
          "category": {
            "type": "string",
            "example": "coin"
          },
          "description": {
            "type": "string",
            "example": "Bitcoin (BTC) is a cryptocurrency launched in 2010..."
          },
          "logo": {
            "type": "string",
            "format": "uri",
            "example": "https://s2.coinmarketcap.com/static/img/coins/64x64/1.png"
          },
          "subreddit": {
            "type": "string",
            "example": "bitcoin"
          },
          "notice": {
            "type": "string",
            "example": ""
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "mineable",
              "pow",
              "sha-256"
            ]
          },
          "urls": {
            "type": "object",
            "properties": {
              "website": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "twitter": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "message_board": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "chat": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "explorer": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "reddit": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "technical_doc": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "source_code": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "announcement": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "platform": {
            "type": "object",
            "nullable": true,
            "example": null
          },
          "date_added": {
            "type": "string",
            "format": "date-time",
            "example": "2010-07-13T00:00:00.000Z"
          },
          "date_launched": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "example": "2010-07-13T00:00:00.000Z"
          },
          "twitter_username": {
            "type": "string",
            "example": ""
          },
          "is_hidden": {
            "type": "integer",
            "example": 0
          },
          "contract_address": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "example": []
          },
          "infinite_supply": {
            "type": "boolean",
            "example": false
          },
          "num_market_pairs": {
            "type": "integer",
            "example": 12662
          },
          "self_reported_circulating_supply": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "self_reported_market_cap": {
            "type": "number",
            "nullable": true,
            "example": null
          },
          "cmc_rank": {
            "type": "integer",
            "example": 1
          },
          "circulating_supply": {
            "type": "number",
            "example": 20047290
          },
          "total_supply": {
            "type": "number",
            "example": 20047290
          },
          "max_supply": {
            "type": "number",
            "nullable": true,
            "example": 21000000
          },
          "last_updated": {
            "type": "string",
            "format": "date-time"
          },
          "quote": {
            "type": "object",
            "properties": {
              "USD": {
                "$ref": "#/components/schemas/CMCQuoteUSD"
              }
            }
          }
        }
      },
      "Provider": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "publicName": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "exchange",
              "blockchain",
              "wallet",
              "service",
              "csv",
              "custom"
            ]
          },
          "featured": {
            "type": "boolean"
          },
          "isWorking": {
            "type": "boolean"
          },
          "logoUrl": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "Integration": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "providerId": {
            "type": "string"
          },
          "alias": {
            "type": "string",
            "nullable": true
          },
          "accountStatus": {
            "type": "string",
            "enum": [
              "pending",
              "active",
              "inactive",
              "suspended",
              "deleting",
              "deleted",
              "error"
            ]
          },
          "credentialKind": {
            "type": "string",
            "enum": [
              "api_key",
              "address",
              "account_name",
              "csv",
              "none"
            ]
          },
          "canResync": {
            "type": "boolean",
            "description": "Whether a resync can be triggered right now — use this to gate Resync actions. True when the account is sync-enabled, is in a resyncable status, is not a custom wallet, and has either a live credential of a syncable kind (api_key/address/account_name) or an enabled connection. False for CSV, custom and credential-less integrations. Computed at read time, not from `credentialKind` (which is a write-once snapshot that records csv as `none`), so it follows credentials being added or revoked. Omitted from `?fields=summary` list responses."
          },
          "credentialValidationStatus": {
            "type": "string",
            "enum": [
              "valid",
              "invalid",
              "expired",
              "pending"
            ],
            "nullable": true
          },
          "importMethod": {
            "type": "string",
            "enum": [
              "api",
              "csv"
            ],
            "nullable": true
          },
          "syncEnabled": {
            "type": "boolean"
          },
          "isCustomWallet": {
            "type": "boolean"
          },
          "lastSyncId": {
            "type": "string",
            "nullable": true
          },
          "lastSyncedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "deletedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "latestSync": {
            "description": "Most recent sync (any status). Populated on GET responses; null if never synced.",
            "nullable": true,
            "allOf": [
              {
                "$ref": "#/components/schemas/Sync"
              }
            ]
          },
          "credentials": {
            "type": "object",
            "nullable": true,
            "description": "Populated on GET responses for address/account_name integrations only (secrets masked); null for secret kinds.",
            "properties": {
              "credentialKind": {
                "type": "string"
              },
              "data": {
                "type": "object"
              }
            }
          },
          "csvUploads": {
            "type": "array",
            "description": "Upload history for CSV-type integrations, most recent first. Empty for non-CSV integrations. Populated on GET /integrations/{id} only. Same shape as GET /csv/uploads.",
            "items": {
              "type": "object",
              "properties": {
                "uploadId": {
                  "type": "string"
                },
                "integrationId": {
                  "type": "string"
                },
                "fileName": {
                  "type": "string"
                },
                "filePath": {
                  "type": "string",
                  "description": "GCS object path — pass this to the signed-URL endpoint to download the file."
                },
                "fileSize": {
                  "type": "integer"
                },
                "fileType": {
                  "type": "string",
                  "nullable": true
                },
                "status": {
                  "type": "string"
                },
                "rowCount": {
                  "type": "integer",
                  "nullable": true
                },
                "summary": {
                  "type": "object"
                },
                "uploadedAt": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            }
          },
          "txnCounts": {
            "type": "object",
            "nullable": true,
            "description": "Per-integration transaction counts (from client_metadata, refreshed by the recompute pipeline). Null until first computed. Per-asset breakdown is at GET /integrations/{id}/assets.",
            "properties": {
              "total": {
                "type": "integer"
              },
              "byType": {
                "type": "object",
                "additionalProperties": {
                  "type": "integer"
                }
              }
            }
          },
          "netValue": {
            "type": "number",
            "nullable": true,
            "description": "Net holdings value of the integration in the workspace base currency."
          },
          "baseCurrency": {
            "type": "string",
            "nullable": true
          },
          "metadataUpdatedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "hasMissingBalance": {
            "type": "boolean",
            "description": "True if any asset's calculated (ledger-derived) balance differs from the provider-reported balance by more than 0.01 — same query as the `hasMissingBalance` filter and GET /integrations/{id}/missing-balances, so all three agree. Evaluated live per request, so it never lags the filter it accompanies. Only integrations that actually report balances are compared: a CSV/manual integration has no provider-reported holdings, so it is treated as unverifiable (false) rather than as reporting zero."
          },
          "assetLogos": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 5,
            "description": "Up to 5 distinct asset logo URLs held by this integration. Populated in list responses"
          },
          "assetCount": {
            "type": "integer",
            "description": "Total distinct (non-spam, unless includeSpam) assets held by this integration — use with assetLogos to render a '+N' overflow badge beyond the 5-logo cap. Populated in list responses."
          },
          "txnCount": {
            "type": "integer",
            "description": "Total distinct transactions for this integration (`txnCounts.total`)."
          }
        }
      },
      "Sync": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "integrationId": {
            "type": "string"
          },
          "workspaceId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "queued",
              "in_progress",
              "completed",
              "failed",
              "cancelled",
              "partially_synced"
            ]
          },
          "syncKind": {
            "type": "string",
            "enum": [
              "api",
              "csv",
              "prices"
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "incremental",
              "resync",
              "resync_from_start"
            ],
            "nullable": true
          },
          "triggerSource": {
            "type": "string",
            "nullable": true
          },
          "triggerType": {
            "type": "string",
            "enum": [
              "manual",
              "automated"
            ],
            "description": "Collapses triggerSource into manual/automated. 'automated' only for the scheduled auto-sync worker; every other source (manual trigger, retry, reconnect, webhook, initial account setup) is manual."
          },
          "progressPercent": {
            "type": "integer",
            "nullable": true
          },
          "message": {
            "type": "string",
            "nullable": true
          },
          "limitReached": {
            "type": "boolean",
            "description": "True when the run stopped early because the workspace hit its transaction limit: rows fetched before the cut are saved, the rest were never read — so this wallet's history is incomplete. `status: partially_synced` alone does NOT mean this (a failed connector function produces the same status), which is why this is a separate field. Raising the cap does not backfill anything on its own: an incremental sync resumes from the last transaction it wrote, so the integration must be re-synced with `syncMode: resync_from_start`. This is the v2 replacement for v1's `limitExceeded`."
          },
          "recordsProcessed": {
            "type": "integer",
            "nullable": true
          },
          "recordsFailed": {
            "type": "integer",
            "nullable": true
          },
          "transactionsDeletedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Set once the transactions this run imported were deleted via `DELETE /sync/{syncId}/transactions`. The row stays in history."
          },
          "startedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "completedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SyncSummary": {
        "type": "object",
        "required": [
          "summary",
          "windowStart"
        ],
        "description": "Answers 'did all my integrations actually sync' — counts over every synced integration (API and CSV; only custom wallets excluded), each bucketed by its latest finished sync. Window = `period`, else the workspace plan's auto-sync interval (daily → 24h, weekly → 7d; 24h with no plan) widened by the 2h auto-sync tolerance. Per-integration rows: `GET /sync/summary/integrations`.",
        "properties": {
          "summary": {
            "type": "object",
            "required": [
              "completed",
              "partial",
              "failed",
              "notSynced",
              "total"
            ],
            "description": "Exhaustive and mutually exclusive: completed + partial + failed + notSynced === total. notSynced = never synced, or latest sync predates the window.",
            "properties": {
              "completed": {
                "type": "integer"
              },
              "partial": {
                "type": "integer"
              },
              "failed": {
                "type": "integer"
              },
              "notSynced": {
                "type": "integer"
              },
              "total": {
                "type": "integer"
              }
            }
          },
          "windowStart": {
            "type": "string",
            "format": "date-time",
            "description": "Start of the window the counts cover (ends now)."
          }
        }
      },
      "SyncSummaryIntegrations": {
        "type": "object",
        "required": [
          "integrations",
          "windowStart",
          "pagination"
        ],
        "description": "One row per synced integration behind `GET /sync/summary` (API AND CSV; custom wallets appear once a file has been uploaded and processed), same filter (so `pagination.total` equals `summary.total` without `search`). Reports each integration's TRUE last-known status/syncedAt always, even when it falls outside the window — see `inWindow`. Only a genuine absence of any recorded sync outcome is `not_synced`.",
        "properties": {
          "integrations": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "integrationId",
                "integration",
                "status",
                "syncKind",
                "triggerType",
                "recordsProcessed",
                "syncedAt",
                "canResync",
                "inWindow"
              ],
              "properties": {
                "integrationId": {
                  "type": "string"
                },
                "integration": {
                  "type": "object",
                  "properties": {
                    "alias": {
                      "type": "string",
                      "nullable": true
                    },
                    "providerName": {
                      "type": "string",
                      "nullable": true
                    },
                    "providerLogo": {
                      "type": "string",
                      "nullable": true
                    },
                    "extra": {
                      "type": "object",
                      "nullable": true,
                      "additionalProperties": {
                        "type": "string"
                      },
                      "description": "The integration's `config.extra` (e.g. `default_chain_logo` for the chain logo shown next to the provider logo)."
                    }
                  }
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "completed",
                    "partially_synced",
                    "failed",
                    "cancelled",
                    "not_synced"
                  ],
                  "description": "'not_synced' means no sync outcome was ever recorded for this integration — never synced, or its last sync recorded no status at all. A real outcome is reported here even when it's outside the window (see `inWindow`) — 'not_synced' is never used to mean 'synced a while ago'."
                },
                "syncKind": {
                  "type": "string",
                  "enum": [
                    "api",
                    "csv",
                    "prices"
                  ],
                  "nullable": true,
                  "description": "The kind of the sync this row reports. Present because `last_sync_*` is stamped by whichever kind finished last: a CSV upload can be what makes an API integration read 'completed'. Null when status is not_synced, or when the sync row is no longer resolvable."
                },
                "triggerType": {
                  "type": "string",
                  "enum": [
                    "manual",
                    "automated"
                  ],
                  "nullable": true,
                  "description": "Null when status is not_synced, and also when the backing sync row is no longer resolvable (an older account row may carry a sync timestamp with no sync id)."
                },
                "recordsProcessed": {
                  "type": "integer",
                  "nullable": true,
                  "description": "Approximate — the connector-fetched count, not a confirmed net-new-insert count (overlapping incremental syncs can dedup some away silently). Null on the same conditions as triggerType."
                },
                "syncedAt": {
                  "type": "string",
                  "format": "date-time",
                  "nullable": true,
                  "description": "Null when status is not_synced. The true last-sync time otherwise, regardless of `inWindow`."
                },
                "inWindow": {
                  "type": "boolean",
                  "description": "Whether `syncedAt` falls inside the summary window (same window as GET /sync/summary's counts). False on a real (non-not_synced) status means this integration genuinely last synced, just not recently — distinct from never having synced."
                },
                "canResync": {
                  "type": "boolean",
                  "description": "Whether a NEW sync can be triggered on this row right now — false for CSV-only integrations (no live credential to run one). Independent of `status`: a row can be shown here with real sync history and still have canResync: false."
                }
              }
            }
          },
          "windowStart": {
            "type": "string",
            "format": "date-time"
          },
          "pagination": {
            "$ref": "#/components/schemas/IntegrationPagination"
          }
        }
      },
      "ApiKeyCredential": {
        "type": "object",
        "description": "Credential shape for credentialKind `api_key`.",
        "required": [
          "apiKey",
          "secretKey"
        ],
        "properties": {
          "apiKey": {
            "type": "string",
            "minLength": 1,
            "description": "Exchange-issued API key.",
            "example": "AKIA1234567890ABCDEF"
          },
          "secretKey": {
            "type": "string",
            "minLength": 1,
            "description": "Exchange-issued API secret.",
            "example": "s3cr3tK3yVALUE"
          },
          "passphrase": {
            "type": "string",
            "description": "The passphrase field for providers that need one (OKX, KuCoin, Bitget, OKCoin, Coinbase Pro/Prime, Poloniex Futures).",
            "example": "my-passphrase"
          },
          "password": {
            "type": "string",
            "description": "Legacy alias for `passphrase` — accepted for backwards compatibility with older clients, normalized into `passphrase` server-side.",
            "example": "my-passphrase"
          },
          "address": {
            "type": "string",
            "description": "IDEX only: the wallet address credential field."
          },
          "privateKey": {
            "type": "string",
            "description": "IDEX only: the wallet's private key (hex), required alongside apiKey/secret/address."
          },
          "memo": {
            "type": "string",
            "description": "Bitmart only: sub-account memo."
          },
          "username": {
            "type": "string",
            "description": "CEX.IO only: the account username."
          },
          "privateKeyPem": {
            "type": "string",
            "description": "Fireblocks-only: RSA private key (PEM), used instead of secretKey."
          }
        }
      },
      "AddressCredential": {
        "type": "object",
        "description": "Credential shape for credentialKind `address` (read-only on-chain address).",
        "required": [
          "address"
        ],
        "properties": {
          "address": {
            "type": "string",
            "minLength": 1,
            "description": "Public wallet/blockchain address.",
            "example": "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"
          }
        }
      },
      "AccountNameCredential": {
        "type": "object",
        "description": "Credential shape for credentialKind `account_name`.",
        "required": [
          "accountName"
        ],
        "properties": {
          "accountName": {
            "type": "string",
            "minLength": 1,
            "description": "Account username / identifier.",
            "example": "my-account"
          },
          "password": {
            "type": "string",
            "description": "Optional account password.",
            "example": "hunter2"
          }
        }
      },
      "IntegrationConfig": {
        "type": "object",
        "description": "Optional provider sync configuration.",
        "properties": {
          "userFunctions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "User-selected provider functions to run. Omit to run all enabled functions.",
            "example": [
              "spot_trades",
              "deposits"
            ]
          },
          "startTime": {
            "type": "integer",
            "minimum": 1,
            "description": "Default sync start time (Unix ms, positive). Overrides incremental sync.",
            "example": 1704067200000
          },
          "endTime": {
            "type": "integer",
            "minimum": 1,
            "description": "Default sync end time (Unix ms, positive). Caps every sync window for this account, resync_from_start included. Must not be before startTime.",
            "example": 1735689600000
          },
          "timezone": {
            "type": "string",
            "description": "IANA timezone used for CSV date parsing.",
            "example": "Europe/London"
          },
          "extra": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Extra provider-specific string key-value config."
          }
        }
      },
      "IntegrationSuccessEnvelope": {
        "type": "object",
        "required": [
          "success"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "description": "Response payload"
          }
        }
      },
      "IntegrationErrorEnvelope": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "details": {
            "type": "object"
          }
        }
      },
      "IntegrationPagination": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "totalPages": {
            "type": "integer"
          }
        }
      },
      "User": {
        "type": "object",
        "properties": {
          "uid": {
            "type": "string",
            "description": "Firebase UID"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "firstName": {
            "type": "string",
            "nullable": true
          },
          "lastName": {
            "type": "string",
            "nullable": true
          },
          "clientType": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "preferredLanguage": {
            "type": "string",
            "enum": [
              "en",
              "de",
              "es",
              "fr",
              "hi",
              "it",
              "pl",
              "pt",
              "sv"
            ],
            "description": "Preferred UI-locale language. Defaults to `en`.",
            "example": "en"
          },
          "active": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "description": "API key metadata. `key` (the plain key) is present ONLY on create/rotate responses.",
        "properties": {
          "id": {
            "type": "string"
          },
          "keyPrefix": {
            "type": "string",
            "example": "sk_live_abcd1234...wxyz"
          },
          "createdBy": {
            "type": "string",
            "description": "uid of the user who created the key. Only they can rotate it."
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "revoked",
              "suspended",
              "expired"
            ]
          },
          "createdAt": {
            "type": "integer",
            "description": "epoch ms"
          },
          "lastUsedAt": {
            "type": "integer",
            "nullable": true,
            "description": "epoch ms"
          },
          "expiresAt": {
            "type": "integer",
            "nullable": true,
            "description": "epoch ms"
          },
          "allowedIPs": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rateLimit": {
            "type": "integer",
            "nullable": true
          },
          "key": {
            "type": "string",
            "description": "Plain key — returned ONCE on create/rotate only"
          }
        }
      },
      "UserSuccessEnvelope": {
        "type": "object",
        "required": [
          "success"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "data": {
            "description": "Response payload"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "CsvUpload": {
        "type": "object",
        "properties": {
          "uploadId": {
            "type": "string",
            "format": "uuid"
          },
          "integrationId": {
            "type": "string",
            "format": "uuid"
          },
          "fileName": {
            "type": "string",
            "example": "binance-trades-2025.csv"
          },
          "fileSize": {
            "type": "integer",
            "example": 48213,
            "description": "Bytes."
          },
          "fileType": {
            "type": "string",
            "example": "csv"
          },
          "status": {
            "type": "string",
            "enum": [
              "uploaded",
              "queued",
              "processing",
              "success",
              "partial",
              "failed",
              "skipped",
              "deleted"
            ]
          },
          "rowCount": {
            "type": "integer",
            "example": 812,
            "nullable": true
          },
          "summary": {
            "type": "object",
            "nullable": true,
            "additionalProperties": true,
            "description": "Parse result: rows imported, skipped and failed."
          },
          "uploadedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "DefiPosition": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "defi_9c1e…"
          },
          "owner": {
            "$ref": "#/components/schemas/AccountType"
          },
          "protocolId": {
            "type": "string",
            "example": "aave3"
          },
          "protocolName": {
            "type": "string",
            "example": "Aave V3"
          },
          "protocolLogoUrl": {
            "type": "string",
            "nullable": true
          },
          "chain": {
            "type": "string",
            "example": "eth"
          },
          "positionName": {
            "type": "string",
            "nullable": true,
            "example": "Lending"
          },
          "detailTypes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "lending"
            ]
          },
          "category": {
            "type": "string",
            "example": "lending",
            "description": "staking, lending, farming, …"
          },
          "pool": {
            "type": "object",
            "additionalProperties": true,
            "nullable": true
          },
          "portfolio": {
            "type": "object",
            "additionalProperties": true,
            "description": "The position as the protocol reports it: supplied, borrowed and reward tokens."
          },
          "totalValue": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "debtValue": {
            "$ref": "#/components/schemas/PriceModel",
            "nullable": true
          },
          "netValue": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "positionTimestamp": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "isActive": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "NftItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "nft_4a7b…"
          },
          "assetId": {
            "type": "string",
            "nullable": true
          },
          "contractAddress": {
            "type": "string",
            "example": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
          },
          "tokenId": {
            "type": "string",
            "example": "42"
          },
          "chain": {
            "type": "string",
            "example": "eth"
          },
          "assetRaw": {
            "type": "object",
            "additionalProperties": true,
            "description": "Name, image and attributes as reported."
          },
          "price": {
            "$ref": "#/components/schemas/PriceModel"
          },
          "collection": {
            "type": "object",
            "additionalProperties": true
          },
          "lastSale": {
            "type": "object",
            "additionalProperties": true,
            "nullable": true
          },
          "source": {
            "$ref": "#/components/schemas/AccountType"
          },
          "isSpam": {
            "type": "boolean",
            "example": false
          }
        }
      }
    },
    "parameters": {
      "WorkspaceId": {
        "name": "wid",
        "in": "query",
        "required": false,
        "schema": {
          "type": "string"
        },
        "description": "Not needed: the workspace comes from your token. If you send it, it must be your `workspace_id`."
      },
      "Page": {
        "name": "page",
        "in": "query",
        "schema": {
          "type": "integer",
          "default": 1
        }
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "schema": {
          "type": "integer",
          "default": 50,
          "maximum": 100
        }
      },
      "IntegrationWorkspaceId": {
        "name": "workspaceId",
        "in": "query",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "Your `workspace_id`: the workspace your token belongs to (returned when you created it). Any other value is refused with 403."
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid auth token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Not permitted (e.g. COA requires an enterprise workspace — ENTERPRISE_REQUIRED)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "InternalError": {
        "description": "Internal server error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "CoaRollupBlocked": {
        "description": "`ROLLUP_BLOCKED` — the rollup carries at least one `blocking` diagnostic. `error.diagnostics[]` holds every problem found, identical to what POST /coa/rollups/preview returned, so the FE can render the full checklist rather than one problem at a time. See `CoaRollupIssue` for the codes.\n\n`JOURNALS_REGENERATING` — a COA recompute is still in flight, so the totals would be stale.\n\n`PERIOD_ALREADY_CLOSED` (inside `diagnostics`) — a close already pushed to an ERP overlaps this period; closing it again would post those amounts twice.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "BadRequest": {
        "description": "Validation failed, invalid/expired code, or wrong current password",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "Conflict": {
        "description": "Email address is already in use",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "success": {
                  "type": "boolean",
                  "example": false
                },
                "error": {
                  "type": "string"
                },
                "retryAfter": {
                  "type": "integer",
                  "description": "Seconds until the limit resets"
                }
              }
            }
          }
        }
      },
      "UserUnauthorized": {
        "description": "Missing or invalid Firebase auth token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "UserForbidden": {
        "description": "Operation requires an end-user (Firebase) session, not a machine/OIDC token",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      },
      "UserNotFound": {
        "description": "User not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorEnvelope"
            }
          }
        }
      }
    }
  },
  "x-tagGroups": [
    {
      "name": "Workspace management",
      "tags": [
        "Workspace management"
      ]
    },
    {
      "name": "Integrations & syncs",
      "tags": [
        "Providers",
        "Integrations",
        "Sync",
        "CSV",
        "Credentials"
      ]
    },
    {
      "name": "Transactions",
      "tags": [
        "Transactions",
        "Ledgers",
        "Labels & Types"
      ]
    },
    {
      "name": "Holdings & positions",
      "tags": [
        "Holdings",
        "Portfolio"
      ]
    },
    {
      "name": "Workspace & reference data",
      "tags": [
        "Tasks",
        "Assets"
      ]
    }
  ]
}
