{
  "openapi": "3.1.0",
  "info": {
    "title": "Capout API",
    "description": "Programmatic REST, WebSocket, and SSE API for uploading documents, tracking processing status, and reading claim balances.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.capout.ai",
      "description": "Public API"
    }
  ],
  "paths": {
    "/upload-url": {
      "post": {
        "tags": [
          "Staged Uploads"
        ],
        "summary": "Create Upload Url",
        "description": "Create a short staged PUT URL for MCP/local clients.\n\nThe returned ``s3_path`` is already in the organization's protected\n``pdf-intake`` path and can be submitted to ``POST /upload`` after the\ncaller uploads the PDF bytes to ``friendly_upload_url``.",
        "operationId": "create_upload_url_upload_url_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UploadUrlRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadUrlResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/u/{friendly_slug}": {
      "put": {
        "tags": [
          "Staged Uploads"
        ],
        "summary": "Upload Friendly Shortlink",
        "description": "Accept a direct PDF upload through a friendly staged-upload short link.",
        "operationId": "upload_friendly_shortlink_u__friendly_slug__put",
        "parameters": [
          {
            "name": "friendly_slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Friendly Slug"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/{document_id}.esx": {
      "get": {
        "tags": [
          "ESX Downloads"
        ],
        "summary": "Download Esx",
        "description": "Authorize an organization and redirect to a freshly signed ESX object.",
        "operationId": "download_esx__document_id__esx_get",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "document_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "description": "Capout document ID, without the .esx suffix",
              "title": "Document Id"
            },
            "description": "Capout document ID, without the .esx suffix"
          },
          {
            "name": "profile",
            "in": "query",
            "required": false,
            "schema": {
              "enum": [
                "contractor",
                "carrier"
              ],
              "type": "string",
              "description": "ESX profile to download. Contractor (8D) is the default; Carrier uses 5L.",
              "default": "contractor",
              "title": "Profile"
            },
            "description": "ESX profile to download. Contractor (8D) is the default; Carrier uses 5L."
          }
        ],
        "responses": {
          "307": {
            "description": "Redirect to a fresh signed S3 download URL"
          },
          "401": {
            "description": "A valid capout-api-key header is required"
          },
          "404": {
            "description": "Document is unknown or inaccessible, or the requested ESX profile was not found"
          },
          "409": {
            "description": "The ESX export is not ready to download"
          },
          "502": {
            "description": "The signed download URL could not be issued"
          },
          "503": {
            "description": "Durable download lookup is unavailable"
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/upload": {
      "post": {
        "tags": [
          "Upload"
        ],
        "summary": "Upload Document",
        "description": "Upload a PDF document for processing.\n\nExactly one of ``file_base64``, ``url``, or ``s3_path`` must be provided.",
        "operationId": "upload_document_upload_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UploadRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/upload/json": {
      "post": {
        "tags": [
          "Upload"
        ],
        "summary": "Upload Json",
        "description": "Upload a structured JSON estimate for catalog resolution, validation, and ESX generation.",
        "operationId": "upload_json_upload_json_post",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Idempotency-Key"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StructuredEstimateV1"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/upload/csv": {
      "post": {
        "tags": [
          "Upload"
        ],
        "summary": "Upload Csv",
        "description": "Upload a CSV estimate for catalog resolution, validation, and ESX generation.",
        "operationId": "upload_csv_upload_csv_post",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Idempotency-Key"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/Body_upload_csv_upload_csv_post"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/status/{document_id}": {
      "get": {
        "tags": [
          "Status"
        ],
        "summary": "Get Document Status",
        "description": "Get the current processing status of a document (one-shot poll).",
        "operationId": "get_document_status_status__document_id__get",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "document_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Document Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentStatusResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/documents": {
      "get": {
        "tags": [
          "Status"
        ],
        "summary": "List Documents",
        "description": "List all API-submitted documents for the authenticated organization.",
        "operationId": "list_documents_documents_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentListResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/claims": {
      "get": {
        "tags": [
          "Claims"
        ],
        "summary": "Get Claims",
        "description": "Check claim balance for the authenticated organization.",
        "operationId": "get_claims_claims_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimsResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/organization-api-keys/primary": {
      "post": {
        "tags": [
          "Organization API Keys"
        ],
        "summary": "Set Primary Organization Api Key",
        "description": "Pin a single organization API key for MCP traffic and clear the rest.",
        "operationId": "set_primary_organization_api_key_organization_api_keys_primary_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SelectPrimaryOrganizationApiKeyRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SelectPrimaryOrganizationApiKeyResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/xactimate-addresses": {
      "get": {
        "tags": [
          "Xactimate Addresses"
        ],
        "summary": "Get Xactimate Addresses",
        "description": "List saved Xactimate/XactNet addresses for the authenticated organization.",
        "operationId": "get_xactimate_addresses_xactimate_addresses_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XactimateAddressesResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      },
      "post": {
        "tags": [
          "Xactimate Addresses"
        ],
        "summary": "Create Xactimate Address",
        "description": "Create or return a saved Xactimate/XactNet address for the organization.",
        "operationId": "create_xactimate_address_xactimate_addresses_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/XactimateAddressRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XactimateAddressMutationResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/xactimate-addresses/{address_id}/profile-code": {
      "patch": {
        "tags": [
          "Xactimate Addresses"
        ],
        "summary": "Update Xactimate Address Profile Code",
        "description": "Update the profile code for a saved Xactimate/XactNet address.",
        "operationId": "update_xactimate_address_profile_code_xactimate_addresses__address_id__profile_code_patch",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "address_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Address Id"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/XactimateAddressProfileCodeUpdateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XactimateAddressMutationResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/xactimate-addresses/{address_id}": {
      "delete": {
        "tags": [
          "Xactimate Addresses"
        ],
        "summary": "Delete Xactimate Address",
        "description": "Delete a saved Xactimate/XactNet address for the organization.",
        "operationId": "delete_xactimate_address_xactimate_addresses__address_id__delete",
        "security": [
          {
            "CapoutApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "address_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Address Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XactimateAddressMutationResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/ws/token": {
      "post": {
        "tags": [
          "WebSocket"
        ],
        "summary": "Create Realtime Ws Token",
        "description": "Mint a short-lived realtime token for WebSocket or SSE authentication.\n\nConnection flow:\n\n1. Call `POST /ws/token` with your `capout-api-key`.\n2. Read `token`, `ws_url`, and `sse_url` from the response.\n3. Connect to `wss://api.capout.ai/ws/status?token=<token>` for WebSocket updates,\n   or `https://api.capout.ai/sse/status?token=<token>` for Server-Sent Events.\n4. Optionally scope the initial subscription with either:\n   - `&document_id=<document_id>` repeated one or more times\n   - `&recent=10` to subscribe to the most recent organization-owned documents\n\nWebSocket example:\n\n`wss://api.capout.ai/ws/status?token=<token>&document_id=doc_123`\n\nSSE example:\n\n`https://api.capout.ai/sse/status?token=<token>&recent=10`\n\nAfter a WebSocket connection is established, clients can send JSON commands such as:\n\n`{\"action\":\"subscribe\",\"document_ids\":[\"doc_123\"]}`",
        "operationId": "create_realtime_ws_token_ws_token_post",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RealtimeTokenResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "CapoutApiKey": []
          }
        ]
      }
    },
    "/sse/status": {
      "get": {
        "tags": [
          "SSE"
        ],
        "summary": "Sse Status",
        "description": "SSE endpoint for streaming one or more documents' status updates.\n\nRequires a valid realtime ``token`` query param plus either one or more\n`document_id` values, or `recent=10`.",
        "operationId": "sse_status_sse_status_get",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "description": "DB-backed realtime token returned by POST /ws/token",
              "title": "Token"
            },
            "description": "DB-backed realtime token returned by POST /ws/token"
          },
          {
            "name": "document_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "default": [],
              "title": "Document Id"
            }
          },
          {
            "name": "recent",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Recent"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {}
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Body_upload_csv_upload_csv_post": {
        "properties": {
          "file": {
            "type": "string",
            "contentMediaType": "application/octet-stream",
            "title": "File"
          },
          "estimate_metadata": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Estimate Metadata"
          }
        },
        "type": "object",
        "required": [
          "file"
        ],
        "title": "Body_upload_csv_upload_csv_post"
      },
      "ClaimBucket": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "source_type": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Source Type"
          },
          "quantity": {
            "type": "integer",
            "title": "Quantity"
          },
          "claims_remaining": {
            "type": "integer",
            "title": "Claims Remaining"
          },
          "expires_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Expires At"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created At"
          }
        },
        "type": "object",
        "required": [
          "id",
          "quantity",
          "claims_remaining"
        ],
        "title": "ClaimBucket"
      },
      "ClaimsResponse": {
        "properties": {
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "available_claims": {
            "type": "integer",
            "title": "Available Claims"
          },
          "expiring_claims_in_30_days": {
            "type": "integer",
            "title": "Expiring Claims In 30 Days",
            "default": 0
          },
          "total_granted_claims": {
            "type": "integer",
            "title": "Total Granted Claims",
            "default": 0
          },
          "total_used_claims": {
            "type": "integer",
            "title": "Total Used Claims",
            "default": 0
          },
          "buckets": {
            "items": {
              "$ref": "#/components/schemas/ClaimBucket"
            },
            "type": "array",
            "title": "Buckets",
            "default": []
          }
        },
        "type": "object",
        "required": [
          "organization_id",
          "available_claims"
        ],
        "title": "ClaimsResponse",
        "description": "Response body for GET /claims."
      },
      "DocumentDetailResponse": {
        "properties": {
          "document_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Document Id"
          },
          "file_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "File Name"
          },
          "source_type": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Source Type"
          },
          "status": {
            "type": "string",
            "title": "Status"
          },
          "progress": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DocumentProgress"
              },
              {
                "type": "null"
              }
            ]
          },
          "workflow_complete": {
            "type": "boolean",
            "title": "Workflow Complete",
            "default": false
          },
          "billing": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Billing"
          },
          "export": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Export"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created At"
          },
          "completed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Completed At"
          },
          "exported_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Exported At"
          }
        },
        "type": "object",
        "required": [
          "status"
        ],
        "title": "DocumentDetailResponse",
        "description": "Document detail returned in GET /documents list."
      },
      "DocumentExportResponse": {
        "properties": {
          "status": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Status"
          },
          "claims_used": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Claims Used"
          },
          "line_item_count": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "Line Item Count"
          },
          "exported_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Exported At"
          },
          "download_url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Download Url"
          },
          "contractor_download_url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Contractor Download Url"
          },
          "carrier_download_url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Carrier Download Url"
          }
        },
        "type": "object",
        "title": "DocumentExportResponse",
        "description": "Export state attached to a document status response."
      },
      "DocumentListResponse": {
        "properties": {
          "documents": {
            "items": {
              "$ref": "#/components/schemas/DocumentDetailResponse"
            },
            "type": "array",
            "title": "Documents"
          },
          "total": {
            "type": "integer",
            "title": "Total"
          }
        },
        "type": "object",
        "required": [
          "documents",
          "total"
        ],
        "title": "DocumentListResponse",
        "description": "Response body for GET /documents."
      },
      "DocumentProgress": {
        "properties": {
          "ocr": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Ocr"
          },
          "structure": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Structure"
          },
          "actions": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Actions"
          },
          "trades": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Trades"
          },
          "categories": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Categories"
          }
        },
        "type": "object",
        "title": "DocumentProgress"
      },
      "DocumentStatusResponse": {
        "properties": {
          "document_id": {
            "type": "string",
            "title": "Document Id",
            "description": "Public document ID for status polling, realtime subscriptions, and ESX downloads."
          },
          "status": {
            "type": "string",
            "title": "Status"
          },
          "terminal": {
            "type": "boolean",
            "title": "Terminal",
            "default": false
          },
          "progress": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DocumentProgress"
              },
              {
                "type": "null"
              }
            ]
          },
          "workflow_complete": {
            "type": "boolean",
            "title": "Workflow Complete",
            "default": false
          },
          "file_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "File Name"
          },
          "source_type": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Source Type"
          },
          "structured_import_issues": {
            "anyOf": [
              {
                "items": {
                  "type": "string"
                },
                "type": "array"
              },
              {
                "type": "null"
              }
            ],
            "title": "Structured Import Issues"
          },
          "error": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Error"
          },
          "export": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DocumentExportResponse"
              },
              {
                "type": "null"
              }
            ]
          },
          "completed_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Completed At"
          },
          "updated_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Updated At"
          }
        },
        "type": "object",
        "required": [
          "document_id",
          "status"
        ],
        "title": "DocumentStatusResponse",
        "description": "Response body for GET /status/{document_id}."
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "OrganizationApiKeySelectionItem": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "key_prefix": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Key Prefix"
          },
          "name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Name"
          },
          "kind": {
            "type": "string",
            "enum": [
              "live",
              "test"
            ],
            "title": "Kind"
          },
          "status": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Status"
          },
          "expires_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Expires At"
          },
          "last_used_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Last Used At"
          },
          "mcp": {
            "type": "boolean",
            "title": "Mcp",
            "default": true
          }
        },
        "type": "object",
        "required": [
          "id",
          "organization_id",
          "kind"
        ],
        "title": "OrganizationApiKeySelectionItem",
        "description": "Selected organization API key metadata returned by the API."
      },
      "RealtimeTokenResponse": {
        "properties": {
          "token": {
            "type": "string",
            "title": "Token",
            "description": "Short-lived realtime token for query-param auth"
          },
          "organization_id": {
            "type": "string",
            "title": "Organization Id",
            "description": "Organization bound to this realtime token"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "title": "Expires At",
            "description": "UTC expiration time for the realtime token"
          },
          "ws_url": {
            "type": "string",
            "title": "Ws Url",
            "description": "WebSocket path to connect to with `?token=<token>`",
            "default": "/ws/status"
          },
          "sse_url": {
            "type": "string",
            "title": "Sse Url",
            "description": "SSE path to connect to with `?token=<token>`",
            "default": "/sse/status"
          }
        },
        "type": "object",
        "required": [
          "token",
          "organization_id",
          "expires_at"
        ],
        "title": "RealtimeTokenResponse",
        "description": "Response body for POST /ws/token."
      },
      "SelectPrimaryOrganizationApiKeyRequest": {
        "properties": {
          "api_key_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Api Key Id"
          },
          "key_kind": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "live",
                  "test",
                  "prod"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Key Kind"
          }
        },
        "type": "object",
        "title": "SelectPrimaryOrganizationApiKeyRequest",
        "description": "Request body for POST /organization-api-keys/primary."
      },
      "SelectPrimaryOrganizationApiKeyResponse": {
        "properties": {
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "selected_api_key": {
            "$ref": "#/components/schemas/OrganizationApiKeySelectionItem"
          },
          "updated_api_key_ids": {
            "items": {
              "type": "string"
            },
            "type": "array",
            "title": "Updated Api Key Ids",
            "default": []
          }
        },
        "type": "object",
        "required": [
          "organization_id",
          "selected_api_key"
        ],
        "title": "SelectPrimaryOrganizationApiKeyResponse",
        "description": "Response body for POST /organization-api-keys/primary."
      },
      "StructuredEstimateV1": {
        "properties": {
          "schema_version": {
            "type": "string",
            "const": "1",
            "title": "Schema Version",
            "description": "Contract schema version, must be '1'",
            "default": "1"
          },
          "file_name": {
            "type": "string",
            "minLength": 1,
            "title": "File Name",
            "description": "Source filename"
          },
          "estimate_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Estimate Name",
            "description": "Display project or estimate name"
          },
          "claim_number": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Claim Number",
            "description": "Insurance claim number"
          },
          "policy_number": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Policy Number",
            "description": "Insurance policy number"
          },
          "insured_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Insured Name",
            "description": "Insured client name"
          },
          "property_address": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Property Address",
            "description": "Property address"
          },
          "date_of_loss": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Date Of Loss",
            "description": "Date of loss (ISO format)"
          },
          "carrier_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Carrier Name",
            "description": "Insurance carrier name"
          },
          "price_list": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Price List",
            "description": "Target Xactimate price list binding code"
          },
          "line_items": {
            "items": {
              "$ref": "#/components/schemas/StructuredLineItemV1"
            },
            "type": "array",
            "minItems": 1,
            "title": "Line Items",
            "description": "Nonempty ordered list of line items"
          }
        },
        "type": "object",
        "required": [
          "file_name",
          "line_items"
        ],
        "title": "StructuredEstimateV1",
        "description": "Version 1 typed contract for structured estimate imports."
      },
      "StructuredLineItemV1": {
        "properties": {
          "id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Id",
            "description": "Optional customer row identifier, unique within the estimate"
          },
          "cat": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Cat",
            "description": "Xactimate category code (e.g. RFG, DRY)"
          },
          "sel": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Sel",
            "description": "Xactimate selector code (e.g. 3TAB, 1/2)"
          },
          "description": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Description",
            "description": "Item description for catalog resolution"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": 0.0,
            "title": "Quantity",
            "description": "Required finite number greater than zero"
          },
          "unit": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Unit",
            "description": "Unit of measure (e.g. EA, SF, LF, SQ)"
          },
          "activity": {
            "type": "string",
            "title": "Activity",
            "description": "Activity symbol (+, -, &, R, I, M) or supported activity name",
            "default": "+"
          },
          "unit_price": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Unit Price",
            "description": "Custom base unit price (non-negative)"
          },
          "line_item_total": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Line Item Total",
            "description": "Base whole-line total"
          },
          "tax": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Tax",
            "description": "Sales tax dollar amount"
          },
          "rcv": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Rcv",
            "description": "Replacement cost value"
          },
          "acv": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Acv",
            "description": "Actual cash value"
          },
          "depreciation": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Depreciation",
            "description": "Depreciation dollar amount"
          },
          "depreciation_applicable": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "title": "Depreciation Applicable",
            "description": "Whether depreciation applies to this line"
          },
          "depreciation_recoverable": {
            "type": "boolean",
            "title": "Depreciation Recoverable",
            "description": "True if depreciation is recoverable, false if non-recoverable",
            "default": true
          },
          "overhead_profit": {
            "anyOf": [
              {
                "type": "number",
                "minimum": 0.0
              },
              {
                "type": "null"
              }
            ],
            "title": "Overhead Profit",
            "description": "Overhead & Profit dollar amount"
          },
          "overhead_profit_applicable": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "type": "null"
              }
            ],
            "title": "Overhead Profit Applicable",
            "description": "Whether O&P applies to this line"
          },
          "is_paid_when_incurred": {
            "type": "boolean",
            "title": "Is Paid When Incurred",
            "description": "Paid when incurred flag",
            "default": false
          },
          "enabled": {
            "type": "boolean",
            "title": "Enabled",
            "description": "Whether item is enabled for estimate export",
            "default": true
          },
          "room": {
            "type": "string",
            "title": "Room",
            "description": "Room or area grouping",
            "default": "General"
          },
          "section": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Section",
            "description": "Optional section within room"
          },
          "f9_note": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "F9 Note",
            "description": "Optional multiline plain text F9 note"
          }
        },
        "type": "object",
        "required": [
          "quantity"
        ],
        "title": "StructuredLineItemV1",
        "description": "Line item within a StructuredEstimateV1 payload."
      },
      "UploadRequest": {
        "properties": {
          "file_base64": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "File Base64",
            "description": "Base64-encoded PDF file"
          },
          "url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Url",
            "description": "Downloadable HTTPS URL to a PDF that the server can fetch immediately"
          },
          "s3_path": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "S3 Path",
            "description": "Existing protected S3 path previously created by POST /upload-url"
          },
          "file_name": {
            "type": "string",
            "title": "File Name",
            "description": "Original filename"
          },
          "xn_address": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Xn Address",
            "description": "Optional XactNet recipient address recorded with the upload."
          },
          "profile_code": {
            "anyOf": [
              {
                "type": "string",
                "enum": [
                  "5L",
                  "8D"
                ]
              },
              {
                "type": "null"
              }
            ],
            "title": "Profile Code",
            "description": "Optional Xactimate profile code recorded with the upload: 5L for Carrier or 8D for Contractor. Use the download URL's profile parameter to select the file.",
            "example": "5L"
          }
        },
        "type": "object",
        "required": [
          "file_name"
        ],
        "title": "UploadRequest",
        "description": "Request body for POST /upload."
      },
      "UploadResponse": {
        "properties": {
          "document_id": {
            "type": "string",
            "title": "Document Id",
            "description": "Public document ID for status polling, realtime subscriptions, and ESX downloads."
          },
          "status": {
            "type": "string",
            "title": "Status",
            "default": "processing"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "title": "Created At"
          },
          "status_url": {
            "type": "string",
            "title": "Status Url"
          },
          "ws_url": {
            "type": "string",
            "title": "Ws Url",
            "default": "/ws/status"
          },
          "download_url": {
            "type": "string",
            "title": "Download Url",
            "description": "Stable authenticated ESX download URL. It redirects to the Contractor profile by default once export is complete."
          },
          "contractor_download_url": {
            "type": "string",
            "title": "Contractor Download Url",
            "description": "Stable authenticated URL for the Contractor (8D) ESX file"
          },
          "carrier_download_url": {
            "type": "string",
            "title": "Carrier Download Url",
            "description": "Stable authenticated URL for the Carrier (5L) ESX file"
          },
          "source_type": {
            "type": "string",
            "title": "Source Type",
            "default": "PDF"
          }
        },
        "type": "object",
        "required": [
          "document_id",
          "created_at",
          "status_url",
          "download_url",
          "contractor_download_url",
          "carrier_download_url"
        ],
        "title": "UploadResponse",
        "description": "Response body for POST /upload."
      },
      "UploadUrlRequest": {
        "properties": {
          "file_name": {
            "type": "string",
            "title": "File Name",
            "description": "Original PDF filename"
          },
          "file_size_bytes": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ],
            "title": "File Size Bytes",
            "description": "Optional PDF size in bytes for early size validation"
          }
        },
        "type": "object",
        "required": [
          "file_name"
        ],
        "title": "UploadUrlRequest",
        "description": "Request body for POST /upload-url."
      },
      "UploadUrlResponse": {
        "properties": {
          "content_type": {
            "type": "string",
            "title": "Content Type",
            "default": "application/pdf"
          },
          "expires_in_seconds": {
            "type": "integer",
            "title": "Expires In Seconds"
          },
          "file_name": {
            "type": "string",
            "title": "File Name"
          },
          "friendly_upload_url": {
            "type": "string",
            "title": "Friendly Upload Url",
            "description": "Short PUT URL on the same API host that accepts the PDF upload directly and maps it to the staged S3 intake path"
          },
          "headers": {
            "additionalProperties": {
              "type": "string"
            },
            "type": "object",
            "title": "Headers"
          },
          "method": {
            "type": "string",
            "title": "Method",
            "default": "PUT"
          },
          "request_id": {
            "type": "string",
            "title": "Request Id"
          },
          "s3_path": {
            "type": "string",
            "title": "S3 Path"
          }
        },
        "type": "object",
        "required": [
          "expires_in_seconds",
          "file_name",
          "friendly_upload_url",
          "headers",
          "request_id",
          "s3_path"
        ],
        "title": "UploadUrlResponse",
        "description": "Response body for POST /upload-url."
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      },
      "XactimateAddressItem": {
        "properties": {
          "id": {
            "type": "string",
            "title": "Id"
          },
          "organization_id": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Organization Id"
          },
          "address": {
            "type": "string",
            "title": "Address"
          },
          "profile_code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "enum": [
              "5L",
              "8D"
            ],
            "title": "Profile Code",
            "description": "Stored Xactimate profile code. Accepted values are 5L (Carrier) and 8D (Contractor).",
            "example": "5L"
          },
          "created_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Created At"
          },
          "updated_at": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ],
            "title": "Updated At"
          }
        },
        "type": "object",
        "required": [
          "id",
          "address"
        ],
        "title": "XactimateAddressItem"
      },
      "XactimateAddressMutationResponse": {
        "properties": {
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "address": {
            "$ref": "#/components/schemas/XactimateAddressItem"
          }
        },
        "type": "object",
        "required": [
          "organization_id",
          "address"
        ],
        "title": "XactimateAddressMutationResponse",
        "description": "Response body for Xactimate address mutations."
      },
      "XactimateAddressProfileCodeUpdateRequest": {
        "properties": {
          "profile_code": {
            "type": "string",
            "enum": [
              "5L",
              "8D"
            ],
            "title": "Profile Code",
            "description": "Xactimate profile code. Accepted values are 5L (Carrier) and 8D (Contractor).",
            "example": "5L"
          }
        },
        "type": "object",
        "required": [
          "profile_code"
        ],
        "title": "XactimateAddressProfileCodeUpdateRequest",
        "description": "Request body for PATCH /xactimate-addresses/{id}/profile-code."
      },
      "XactimateAddressRequest": {
        "properties": {
          "address": {
            "type": "string",
            "title": "Address",
            "description": "Xactimate/XactNet recipient address to save"
          },
          "profile_code": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "enum": [
              "5L",
              "8D"
            ],
            "title": "Profile Code",
            "description": "Optional Xactimate profile code to store with the address",
            "example": "5L"
          }
        },
        "type": "object",
        "required": [
          "address"
        ],
        "title": "XactimateAddressRequest",
        "description": "Request body for POST /xactimate-addresses."
      },
      "XactimateAddressesResponse": {
        "properties": {
          "organization_id": {
            "type": "string",
            "title": "Organization Id"
          },
          "addresses": {
            "items": {
              "$ref": "#/components/schemas/XactimateAddressItem"
            },
            "type": "array",
            "title": "Addresses"
          }
        },
        "type": "object",
        "required": [
          "organization_id",
          "addresses"
        ],
        "title": "XactimateAddressesResponse",
        "description": "Response body for GET /xactimate-addresses."
      }
    },
    "securitySchemes": {
      "CapoutApiKey": {
        "type": "apiKey",
        "description": "Organization-scoped CapOut API key",
        "in": "header",
        "name": "capout-api-key"
      }
    }
  }
}
