{
  "openapi": "3.0.3",
  "info": {
    "title": "FinanceSec API Reference",
    "version": "0.4.0",
    "description": "Secure, deterministic financial Q&A query engine powered by the Volumetric Lattice Network (VLN). All responses are cryptographically grounded to SEC EDGAR source filings with a 0.00% hallucination rate guarantee. **No LLM is present in the fact path**; LLMs are restricted strictly to downstream context synthesis and report generation.\n\nTo integrate with your spreadsheets and existing tools, refer to the [Workflows Sheets Stepper](/dashboard#integrations).\n\n## Core Integration Sections\n\n### Auth\nAuthenticate by providing your private license key in the `X-License-Key` header. Manage keys in the [API Keys Console](/dashboard#keys).\n\n### Query\nExecute single natural language queries against SEC filings via `POST /api/query`. Responses are returned in under 400ms with full citation metadata.\n\n### Batch\nFor high-volume ingestion, queue up to 100 queries using `POST /api/batch` and poll `GET /api/batch/{id}` for status updates.\n\n### Provenance\nEvery successful answer returns a `provenance` block detailing the specific source filing CIK, xbrl_concept, document period, and a cryptographic `audit_hash` for auditability.\n\n### Agent\nLeverage external frontier LLMs to synthesize SEC-grounded reports. Fact retrieval is decoupled from LLM generation to ensure accuracy.\n\n### Tool Calling & Model Context Protocol (MCP)\nHosted MCP binary `financesec-mcp` wraps `POST /api/query` (FACT-PATH-1: no LLM). Transports: stdio (local) and streamable HTTP at `https://finsec.caleralabs.com/mcp`. Authenticate with `X-License-Key` (or Bearer). `SAFE_REFUSAL` is honest tool content, not a transport error. Canonical schema version `1.2.0`:\n\n```json\n{\n  \"name\": \"query_financial_sec\",\n  \"version\": \"1.2.0\",\n  \"description\": \"Certified SEC fact query. Returns verified values with provenance or SAFE_REFUSAL. Does not invent numbers. Treat SAFE_REFUSAL as success-of-honesty, not a tool failure. Monetary answers default to the filer's reporting currency; request FX conversion via target_currency / usd_only or natural-language 'in USD'.\",\n  \"annotations\": {\n    \"title\": \"Query Certified SEC Facts\",\n    \"readOnlyHint\": true\n  },\n  \"inputSchema\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"query\": {\n        \"type\": \"string\",\n        \"description\": \"Natural language financial question. Append 'in USD' (or another supported ISO code) to convert foreign reporting currencies after verified recall.\"\n      },\n      \"target_currency\": {\n        \"type\": \"string\",\n        \"description\": \"Optional ISO 4217 code (e.g. USD, EUR) for post-recall FX conversion using audited annual-average rates. Provenance records original_unit, fx_rate, and fx_converted.\"\n      },\n      \"usd_only\": {\n        \"type\": \"boolean\",\n        \"description\": \"When true, forces monetary answers into USD.\"\n      }\n    },\n    \"required\": [\n      \"query\"\n    ]\n  }\n}\n```\n\n### Webhooks\nConfigure Webhook endpoints in the dashboard to receive immediate event payload push notifications (e.g., `filing.detected`, `filing.ingested`, `filing.materialized`, `metric.changed`, `batch.completed`) when background jobs or filing materializations finish.\n\n### Errors\nIf a query cannot be verified to 100% confidence, the network returns an honest refusal (`HONEST_FAIL`) with clear remediation guidance rather than inventing data."
  },
  "servers": [
    {
      "url": "https://financesec.api.caleralabs.com",
      "description": "Production API Server"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Check API health",
        "operationId": "checkApiHealth",
        "description": "Returns the current health status, version, port, system timestamp, and TTND stage breakdown per CIK (Freshness SLA: ≤30m p95).",
        "security": [],
        "responses": {
          "200": {
            "description": "API is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/watchlist/{cik}": {
      "post": {
        "summary": "Register CIK for real-time monitoring and pre-warming",
        "operationId": "addWatchlistCIK",
        "description": "Registers a CIK for real-time SEC filing detection, priority queue processing, and lattice pre-warming (Freshness SLA: ≤30m p95).",
        "security": [],
        "parameters": [
          {
            "name": "cik",
            "in": "path",
            "description": "10-digit zero-padded SEC Central Index Key (CIK)",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CIK successfully registered for RT pipeline",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "success" },
                    "cik": { "type": "string", "example": "0000320193" },
                    "rt_active": { "type": "boolean", "example": true },
                    "prewarmed": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "CIK 0000320193 registered for RT pipeline and pre-warming initiated" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/companies": {
      "get": {
        "summary": "Retrieve supported companies",
        "operationId": "getCompanies",
        "description": "Get the list of all supported companies in the SEC EDGAR universe. Can be filtered by query prefix.",
        "security": [],
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Optional search prefix matching ticker or company name",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A list of companies",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Company"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/tiers": {
      "get": {
        "summary": "Get subscription tiers comparison",
        "operationId": "getTiers",
        "description": "Returns pricing, support, SLA, and feature configurations for all FinanceSec subscription tiers.",
        "security": [],
        "responses": {
          "200": {
            "description": "Subscription tiers information",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/TierComparisonEntry"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "summary": "Get API statistics",
        "operationId": "getStats",
        "description": "Returns active metrics on answer rates, known companies count, coverage indices, and diagnostic run hashes.",
        "responses": {
          "200": {
            "description": "Diagnostic and operational statistics",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StatsResponse"
                }
              }
            }
          },
          "402": {
            "description": "License Key Required"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/query": {
      "post": {
        "summary": "Submit single SEC query",
        "operationId": "submitQuery",
        "description": "Queries the VLN lattice for factual answers to questions regarding SEC 10-K, 10-Q, and 8-K filings.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QueryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Query response containing grounding results or Refusal metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QueryResponse"
                }
              }
            }
          },
          "402": {
            "description": "License Required"
          },
          "429": {
            "description": "Rate Limit Reached"
          }
        }
      }
    },
    "/api/packs/valuation-inputs": {
      "post": {
        "summary": "Retrieve valuation-inputs pack",
        "operationId": "getValuationInputsPack",
        "description": "Returns structured, EDGAR-certified valuation input cells and compositions for the specified company, period, and pack enum. EDGAR-only scope; excludes market price multiples (P/E, trading EV) and macro indicators (Buffett Indicator).",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ValuationPackRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Valuation pack response payload with cell & composition provenance and EDGAR-only disclaimer",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValuationPackResponse"
                }
              }
            }
          },
          "402": {
            "description": "License Required"
          }
        }
      }
    },

    "/api/provenance/{id}": {
      "get": {
        "summary": "Retrieve fact provenance",
        "operationId": "getProvenance",
        "description": "Fetch detailed provenance trace and verification hashes for a specific grounded entity fact.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Unique ID of the provenance record",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Provenance details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProvenanceResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Provenance record not found"
          }
        }
      }
    },
    "/api/trends": {
      "get": {
        "summary": "Get multi-year financial trends",
        "operationId": "getTrends",
        "description": "Collects multi-year comparative lists of core metrics (Revenue, Net Income, and Operating Margins) for a company.",
        "parameters": [
          {
            "name": "company",
            "in": "query",
            "description": "Ticker symbol of the target company",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Trends datasets",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TrendsResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/batch": {
      "post": {
        "summary": "Submit async batch job",
        "operationId": "submitBatchJob",
        "description": "Queue up to 100 queries for background processing. Available for Professional and Enterprise tiers only.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Batch job queued successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchJob"
                }
              }
            }
          },
          "400": {
            "description": "Invalid batch payload or batch size exceeded"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Endpoint access forbidden for active tier"
          }
        }
      }
    },
    "/api/batch/{batch_id}": {
      "get": {
        "summary": "Retrieve batch status and results",
        "operationId": "getBatchJob",
        "description": "Check current status and download query results of a queued batch processing job.",
        "parameters": [
          {
            "name": "batch_id",
            "in": "path",
            "description": "Unique identifier of the submitted batch job",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Batch job details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchJob"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Batch job not found"
          }
        }
      }
    },
    "/api/xbrl/ingest": {
      "post": {
        "summary": "Ingest custom XBRL filings",
        "description": "Allows Enterprise customers to upload and ingest custom SEC-style XBRL filings to build/query their private lattice instance.",
        "operationId": "ingestCustomXbrl",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/XbrlIngestRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Filing ingested successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XbrlIngestResponse"
                }
              }
            }
          },
          "202": {
            "description": "Filing upload accepted for asynchronous ingestion",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/XbrlIngestResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid payload or parsing failure"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Endpoint access forbidden for active tier"
          }
        }
      }
    },
    "/api/keys": {
      "get": {
        "summary": "List API keys",
        "description": "Returns all API keys associated with the user's organization.",
        "operationId": "listApiKeys",
        "responses": {
          "200": {
            "description": "A list of API keys"
          }
        }
      },
      "post": {
        "summary": "Create API key",
        "description": "Generates a new API key for the organization.",
        "operationId": "createApiKey",
        "responses": {
          "201": {
            "description": "API key created"
          }
        }
      }
    },
    "/api/webhooks": {
      "get": {
        "summary": "List webhook endpoints",
        "description": "Returns all registered webhook endpoints for the organization.",
        "operationId": "listWebhooks",
        "responses": {
          "200": {
            "description": "A list of webhook endpoints"
          }
        }
      },
      "post": {
        "summary": "Create webhook endpoint",
        "description": "Registers a new webhook endpoint for event notifications.",
        "operationId": "createWebhook",
        "responses": {
          "201": {
            "description": "Webhook endpoint created"
          }
        }
      }
    },
    "/api/audit/export": {
      "get": {
        "summary": "Export audit logs",
        "description": "Downloads the organization audit trail in JSON Lines format.",
        "operationId": "exportAuditLogs",
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Exported audit logs"
          }
        }
      }
    },
    "/api/org/create": {
      "post": {
        "summary": "Create organization",
        "description": "Creates a new multi-seat organization.",
        "operationId": "createOrg",
        "responses": {
          "201": {
            "description": "Organization created"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-License-Key",
        "description": "Your secret FinanceSec API license key. Required for authenticated endpoints."
      }
    },
    "schemas": {
      "ValuationPackRequest": {
        "type": "object",
        "required": ["company", "period", "pack"],
        "properties": {
          "company": {
            "type": "string",
            "example": "AAPL"
          },
          "period": {
            "type": "string",
            "example": "FY2023"
          },
          "pack": {
            "type": "string",
            "enum": [
              "equity_screen",
              "ev_bridge",
              "quality_of_earnings",
              "segment_mix",
              "returns_screen",
              "leverage_screen",
              "piotroski_f",
              "altman_z_prime",
              "beneish_m_score",
              "dupont_5step",
              "working_capital_efficiency",
              "dcf_valuation_inputs"
            ],
            "example": "leverage_screen"
          }
        }
      },
      "ValuationPackResponse": {
        "type": "object",
        "properties": {
          "pack_id": {
            "type": "string",
            "example": "leverage_screen"
          },
          "company": {
            "type": "string",
            "example": "AAPL"
          },
          "period": {
            "type": "string",
            "example": "FY2023"
          },
          "pack_status": {
            "type": "string",
            "enum": ["COMPLETE", "PARTIAL", "DEADLINE"],
            "example": "COMPLETE"
          },
          "cells": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "metric": { "type": "string" },
                "status": { "type": "string" },
                "value": { "type": "number" },
                "unit": { "type": "string" },
                "provenance": {
                  "type": "object",
                  "properties": {
                    "accession": { "type": "string" },
                    "xbrl_concept": { "type": "string" },
                    "audit_hash": { "type": "string" }
                  }
                },
                "reason": { "type": "string" }
              }
            }
          },
          "compositions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string" },
                "status": { "type": "string" },
                "value": {},
                "formatted": { "type": "string" },
                "reason": { "type": "string" },
                "provenance": {
                  "type": "object",
                  "properties": {
                    "accession": { "type": "string" },
                    "xbrl_concept": { "type": "string" },
                    "audit_hash": { "type": "string" }
                  }
                }
              }
            }
          },
          "disclaimer": {
            "type": "string",
            "example": "Market price, trading EV, P/E, and macro gauges (e.g. Buffett Indicator) are not provided by FINSEC. Packs are EDGAR-certified inputs only."
          }
        }
      },
      "HealthResponse": {

        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "domain": {
            "type": "string",
            "example": "Calera FinanceSec \u2014 SEC Filing QA"
          },
          "version": {
            "type": "string",
            "example": "v0.1.10"
          },
          "api_version": {
            "type": "string",
            "example": "v0.1.10"
          },
          "platform_version": {
            "type": "string",
            "example": "v0.3.2"
          },
          "port": {
            "type": "string",
            "example": "8080"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "example": "2026-07-09T23:02:04Z"
          },
          "ttnd_breakdown": {
            "type": "object",
            "description": "Per-CIK TTND stage latency breakdown and total detect-to-materialize timing",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "cik": { "type": "string", "example": "0000320193" },
                "accession": { "type": "string", "example": "0000320193-26-000013" },
                "detected_at": { "type": "string", "format": "date-time" },
                "queued_at": { "type": "string", "format": "date-time" },
                "fetched_at": { "type": "string", "format": "date-time" },
                "trained_at": { "type": "string", "format": "date-time" },
                "visible_at": { "type": "string", "format": "date-time" },
                "total_ttnd_ms": { "type": "integer", "example": 240000 }
              }
            }
          }
        }
      },
      "Company": {
        "type": "object",
        "properties": {
          "ticker": {
            "type": "string",
            "example": "MMM"
          },
          "name": {
            "type": "string",
            "example": "3M"
          },
          "sector": {
            "type": "string",
            "example": "Industrials"
          }
        }
      },
      "TierComparisonEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "professional"
          },
          "name": {
            "type": "string",
            "example": "Professional"
          },
          "price": {
            "type": "string",
            "example": "$5000/mo"
          },
          "queriesPerDay": {
            "type": "integer",
            "example": 5000
          },
          "filings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "10-K",
              "10-Q",
              "8-K"
            ]
          },
          "conns": {
            "type": "integer",
            "example": 10
          },
          "audit": {
            "type": "integer",
            "example": 90
          },
          "sla": {
            "type": "string",
            "example": "99.95%"
          },
          "support": {
            "type": "string",
            "example": "Slack + Email"
          },
          "color": {
            "type": "string",
            "example": "#ef5350"
          }
        }
      },
      "StatsResponse": {
        "type": "object",
        "properties": {
          "lattice_coverage_index": {
            "type": "number",
            "format": "float",
            "example": 0.95
          },
          "training_ms": {
            "type": "integer",
            "example": 120
          },
          "fixture_items": {
            "type": "integer",
            "example": 150
          },
          "known_companies": {
            "type": "integer",
            "example": 10000
          },
          "version": {
            "type": "string",
            "example": "v0.1.2"
          },
          "domain_version": {
            "type": "string",
            "example": "v0.1.2"
          },
          "answer_rate_pct": {
            "type": "number",
            "format": "float",
            "description": "Accuracy percentage on the FinanceBench 150-question evaluation benchmark set.",
            "example": 92.0
          },
          "correct_count": {
            "type": "integer",
            "example": 150
          },
          "total_questions": {
            "type": "integer",
            "example": 150
          },
          "segment_dimension_support": {
            "type": "boolean",
            "example": true
          },
          "quarterly_10q_support": {
            "type": "boolean",
            "example": true
          },
          "novel_nlu_categories": {
            "type": "integer",
            "example": 5
          },
          "domain_relevant_detectors": {
            "type": "integer",
            "example": 14
          },
          "battery_sha256": {
            "type": "string",
            "example": "d222effd29c2..."
          },
          "answerRate": {
            "type": "number",
            "format": "float",
            "description": "Overall answer rate float (0.0 to 1.0) across all incoming queries including safety refusals.",
            "example": 0.793
          },
          "total_queries": {
            "type": "integer",
            "example": 250
          }
        }
      },
      "QueryRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "The natural language query about SEC filings.",
            "example": "WiMi Hologram Cloud Inc. net income 2025"
          },
          "target_currency": {
            "type": "string",
            "description": "Optional ISO 4217 target currency code (e.g. 'USD') to convert foreign reporting currencies.",
            "example": "USD"
          },
          "currency": {
            "type": "string",
            "description": "Alias for target_currency.",
            "example": "USD"
          },
          "usd_only": {
            "type": "boolean",
            "description": "When true, forces response values to be output in USD.",
            "example": true
          }
        }
      },
      "QueryResponse": {
        "type": "object",
        "properties": {
          "query_id": {
            "type": "string",
            "example": "q_000181"
          },
          "status": {
            "type": "string",
            "enum": [
              "VERIFIED_SUCCESS",
              "TENTATIVE_MATCH",
              "SAFE_REFUSAL",
              "EVENT_ACK_PENDING_FACTS",
              "EARNINGS_DAY_EMPTY",
              "OUT_OF_UNIVERSE",
              "SCHEDULE_NOT_IN_ONTOLOGY",
              "FILING_EVENT_SET"
            ],
            "example": "VERIFIED_SUCCESS",
            "description": "EVENT_ACK_PENDING_FACTS: 8-K Item 2.02 seen; certified metrics pending (see filing_event). EARNINGS_DAY_EMPTY / OUT_OF_UNIVERSE / SCHEDULE_NOT_IN_ONTOLOGY: typed honest silences (UX-SILENCE-TYPED-1). FILING_EVENT_SET: EDGAR-observed earnings-day set recall (Class B)."
          },
          "source": {
            "type": "string",
            "enum": [
              "LATTICE_RECALL",
              "ANALYTICAL_GATE",
              "TEMPORAL_GATE",
              "ENTITY_GATE",
              "CONFIDENCE_GATE",
              "FILING_EVENT_GATE",
              "CAPABILITY_GATE",
              "COVERAGE_GATE",
              "ONTOLOGY_GATE"
            ],
            "example": "LATTICE_RECALL"
          },
          "coverage": {
            "type": "object",
            "description": "Public coverage bound for earnings-day answers and typed silences. Never implies full-market calendar coverage.",
            "properties": {
              "universe_description": {
                "type": "string",
                "example": "Cohort0 + active watchlists"
              },
              "universe_size": {
                "type": "integer",
                "example": 12
              },
              "model_generation": {
                "type": "integer",
                "example": 7
              },
              "promoted_at": {
                "type": "string",
                "format": "date-time",
                "example": "2026-07-24T15:00:00Z"
              }
            }
          },
          "answer": {
            "type": "object",
            "properties": {
              "value": {
                "type": "number",
                "example": 1577
              },
              "unit": {
                "type": "string",
                "example": "USD"
              },
              "formatted": {
                "type": "string",
                "example": "$1,577.00"
              }
            }
          },
          "filing_event": {
            "type": "object",
            "description": "Structured 8-K event metadata (Item codes from SEC submissions). Present on EVENT_ACK_PENDING_FACTS. Never contains invented monetary values.",
            "properties": {
              "form_type": { "type": "string", "example": "8-K" },
              "items": {
                "type": "array",
                "items": { "type": "string" },
                "example": ["2.02", "9.01"]
              },
              "event_type": { "type": "string", "example": "earnings_release" },
              "event_types": {
                "type": "array",
                "items": { "type": "string" },
                "example": ["earnings_release", "exhibit_filing"]
              },
              "cik": { "type": "string", "example": "0001652044" },
              "ticker": { "type": "string", "example": "GOOGL" },
              "accession": { "type": "string", "example": "0001652044-26-000066" },
              "filing_date": { "type": "string", "example": "2026-07-22" },
              "next_check": { "type": "string", "example": "companyfacts_or_10q" }
            }
          },
          "confidence_score": {
            "type": "number",
            "format": "float",
            "example": 1
          },
          "method": {
            "type": "string",
            "example": "FuzzyAnswerLookup"
          },
          "provenance": {
            "type": "object",
            "properties": {
              "entity_id": {
                "type": "string",
                "example": "fin:3M_3M_2018_10K"
              },
              "source_filing": {
                "type": "string",
                "example": "fin:3M_2018_10K"
              },
              "company": {
                "type": "string",
                "example": "3M"
              },
              "xbrl_concept": {
                "type": "string",
                "example": "us-gaap:PaymentsToAcquirePropertyPlantAndEquipment"
              },
              "doc_period": {
                "type": "string",
                "example": "FY2018"
              },
              "audit_hash": {
                "type": "string",
                "example": "452b9177..."
              },
              "original_value": {
                "type": "string",
                "description": "Formatted reporting-currency value before FX conversion.",
                "example": "¥1843388870.00 CNY"
              },
              "original_unit": {
                "type": "string",
                "description": "ISO reporting currency before FX conversion.",
                "example": "CNY"
              },
              "fx_rate": {
                "type": "string",
                "description": "Audited annual-average FX rate applied at inference time.",
                "example": "1 CNY = 0.1389 USD"
              },
              "fx_converted": {
                "type": "boolean",
                "description": "True when the answer was converted from the filer's reporting currency.",
                "example": true
              }
            }
          },
          "decomposition": {
            "type": "object",
            "properties": {
              "steps": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string",
                      "example": "Gross Profit"
                    },
                    "value": {
                      "type": "string",
                      "example": "$8,156M"
                    }
                  }
                }
              },
              "operator": {
                "type": "string",
                "example": "\u00f7"
              },
              "result": {
                "type": "string",
                "example": "12.50%"
              }
            }
          },
          "reason": {
            "type": "string",
            "description": "Human-readable refusal, typed silence, or pending-facts explanation. EVENT_ACK_PENDING_FACTS and UX-SILENCE-TYPED-1 classes use fixed product copy (not scraped from press HTML).",
            "example": "No crystallized evidence for this query."
          }
        }
      },
      "ProvenanceResponse": {
        "type": "object",
        "properties": {
          "entity_id": {
            "type": "string",
            "example": "fin:3M_3M_2018_10K"
          },
          "source_filing": {
            "type": "string",
            "example": "fin:3M_2018_10K"
          },
          "xbrl_concept": {
            "type": "string",
            "example": "us-gaap:PaymentsToAcquirePropertyPlantAndEquipment"
          },
          "company": {
            "type": "string",
            "example": "3M"
          },
          "doc_period": {
            "type": "string",
            "example": "FY2018"
          },
          "document_location": {
            "type": "object",
            "properties": {
              "page": {
                "type": "integer",
                "example": 45
              }
            }
          },
          "audit_hash": {
            "type": "string",
            "example": "452b9177..."
          }
        }
      },
      "TrendsResponse": {
        "type": "object",
        "properties": {
          "company": {
            "type": "string",
            "example": "3M"
          },
          "revenue": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "example": [
              32184,
              34229,
              34268
            ]
          },
          "netIncome": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "example": [
              5349,
              5821,
              5777
            ]
          },
          "opMargin": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "example": [
              21.4,
              22,
              20.8
            ]
          },
          "periods": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "FY2021",
              "FY2022",
              "FY2023"
            ]
          }
        }
      },
      "BatchRequest": {
        "type": "object",
        "required": [
          "queries"
        ],
        "properties": {
          "queries": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "What is Tesla's FY22 gross margin?",
              "What is Amazon's FY23 operating margin?"
            ]
          }
        }
      },
      "BatchJob": {
        "type": "object",
        "properties": {
          "batch_id": {
            "type": "string",
            "example": "batch_abc123"
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDING",
              "PROCESSING",
              "COMPLETED",
              "FAILED"
            ],
            "example": "COMPLETED"
          },
          "total_queries": {
            "type": "integer",
            "example": 2
          },
          "processed_queries": {
            "type": "integer",
            "example": 2
          },
          "queries": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "example": [
              "What is Tesla's FY22 gross margin?",
              "What is Amazon's FY23 operating margin?"
            ]
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/QueryResponse"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "example": "2026-07-09T23:00:00Z"
          },
          "completed_at": {
            "type": "string",
            "format": "date-time",
            "example": "2026-07-09T23:01:00Z"
          },
          "error": {
            "type": "string",
            "example": "None"
          }
        }
      },
      "XbrlIngestRequest": {
        "type": "object",
        "required": [
          "ticker",
          "company_name",
          "filing_type",
          "xbrl_data"
        ],
        "properties": {
          "ticker": {
            "type": "string",
            "description": "The ticker symbol of the company.",
            "example": "AAPL"
          },
          "company_name": {
            "type": "string",
            "description": "The full name of the company.",
            "example": "Apple Inc."
          },
          "filing_type": {
            "type": "string",
            "enum": [
              "10-K",
              "10-Q",
              "8-K"
            ],
            "description": "The type of filing.",
            "example": "10-K"
          },
          "fiscal_year": {
            "type": "string",
            "description": "The fiscal year for the filing.",
            "example": "2025"
          },
          "xbrl_data": {
            "type": "string",
            "description": "Base64-encoded XML or raw XBRL JSON payload.",
            "example": "<xbrli:xbrl>...</xbrli:xbrl>"
          }
        }
      },
      "XbrlIngestResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "INGESTED"
          },
          "job_id": {
            "type": "string",
            "example": "job_xbrl_183204"
          },
          "companies_added": {
            "type": "integer",
            "example": 1
          }
        }
      }
    }
  }
}