{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/marginofinsight-com/json-schema/marginofinsight-com-response-envelope-schema.json",
  "title": "ResponseEnvelope",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/marginofinsight-com-openapi.json#/components/schemas/ResponseEnvelope",
  "type": "object",
  "required": [
    "ticker",
    "company",
    "exchange",
    "report_type",
    "tier",
    "generated_at",
    "coverage_as_of",
    "freshness_days",
    "data",
    "metadata"
  ],
  "properties": {
    "ticker": {
      "type": "string",
      "description": "Uppercase ticker symbol"
    },
    "company": {
      "type": "string"
    },
    "exchange": {
      "type": "string"
    },
    "report_type": {
      "type": "string",
      "enum": [
        "primer",
        "fundamental",
        "memo"
      ]
    },
    "tier": {
      "type": "string",
      "enum": [
        "free",
        "fundamental",
        "full"
      ]
    },
    "generated_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when this report was generated"
    },
    "coverage_as_of": {
      "type": "string",
      "description": "Most recent quarter reflected in the research"
    },
    "freshness_days": {
      "type": "integer",
      "description": "Days since report was generated"
    },
    "steps_included": {
      "type": "array",
      "items": {
        "type": "integer"
      }
    },
    "data": {
      "$ref": "#/$defs/ResearchData"
    },
    "metadata": {
      "$ref": "#/$defs/ResponseMetadata"
    }
  },
  "$defs": {
    "ResearchData": {
      "type": "object",
      "description": "Research content. Fields present depend on tier requested.",
      "properties": {
        "overview": {
          "type": "object",
          "description": "Step 1 — Business Overview",
          "properties": {
            "description": {
              "type": "string"
            },
            "sector": {
              "type": "string"
            },
            "industry": {
              "type": "string"
            },
            "exchange": {
              "type": "string"
            },
            "market_cap_usd": {
              "type": "number"
            },
            "employees": {
              "type": "integer"
            },
            "business_model": {
              "type": "string"
            },
            "revenue_model": {
              "type": "string"
            },
            "core_products": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "financial_snapshot": {
          "type": "object",
          "description": "Step 2 — Financial Snapshot",
          "properties": {
            "revenue_ttm": {
              "type": "number"
            },
            "net_income_ttm": {
              "type": "number"
            },
            "eps_ttm": {
              "type": "number"
            },
            "gross_margin_pct": {
              "type": "number"
            },
            "operating_margin_pct": {
              "type": "number"
            },
            "fcf_ttm": {
              "type": "number"
            },
            "pe_ratio": {
              "type": "number"
            },
            "ps_ratio": {
              "type": "number"
            },
            "ev_ebitda": {
              "type": "number"
            },
            "quarterly": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "period": {
                    "type": "string"
                  },
                  "revenue": {
                    "type": "number"
                  },
                  "net_income": {
                    "type": "number"
                  },
                  "eps": {
                    "type": "number"
                  },
                  "yoy_revenue_growth_pct": {
                    "type": "number"
                  }
                }
              }
            }
          }
        },
        "catalysts": {
          "type": "object",
          "description": "Step 3 — Recent Catalysts",
          "properties": {
            "recent": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "earnings",
                      "guidance",
                      "news",
                      "filing"
                    ]
                  },
                  "summary": {
                    "type": "string"
                  },
                  "sentiment": {
                    "type": "string",
                    "enum": [
                      "positive",
                      "negative",
                      "neutral"
                    ]
                  }
                }
              }
            },
            "upcoming": {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string",
                    "format": "date"
                  },
                  "event": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "revenue_breakdown": {
          "type": "object",
          "description": "Step 4 — Revenue Breakdown ($1 tier and above)",
          "properties": {
            "segments": {
              "type": "array",
              "items": {
                "type": "object"
              }
            },
            "geographic": {
              "type": "array",
              "items": {
                "type": "object"
              }
            },
            "concentration_risk": {
              "type": "string"
            }
          }
        },
        "earnings_analysis": {
          "type": "object",
          "description": "Step 5 — Earnings Transcript Analysis ($1 tier and above)",
          "properties": {
            "quarters_analyzed": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "management_tone": {
              "type": "string",
              "enum": [
                "confident",
                "cautious",
                "mixed"
              ]
            },
            "key_quotes": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "guidance_credibility": {
              "type": "string"
            },
            "analyst_pushback_themes": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "competitive_positioning": {
          "type": "object",
          "description": "Step 6 — Competitive Positioning ($1 tier and above)"
        },
        "financial_trends": {
          "type": "object",
          "description": "Step 7 — Financial Trends ($1 tier and above)"
        },
        "risk_register": {
          "type": "array",
          "description": "Step 8 — Risk Register ($1 tier and above)",
          "items": {
            "type": "object",
            "properties": {
              "risk": {
                "type": "string"
              },
              "severity": {
                "type": "string",
                "enum": [
                  "high",
                  "medium",
                  "low"
                ]
              },
              "likelihood": {
                "type": "string",
                "enum": [
                  "high",
                  "medium",
                  "low"
                ]
              },
              "source": {
                "type": "string"
              }
            }
          }
        },
        "balance_sheet": {
          "type": "object",
          "description": "Step 9 — Balance Sheet Health ($1 tier and above)"
        },
        "capital_allocation": {
          "type": "object",
          "description": "Step 10 — Capital Allocation ($1 tier and above)"
        },
        "industry_context": {
          "type": "object",
          "description": "Step 11 — Industry Context ($1 tier and above)"
        },
        "moat_analysis": {
          "type": "object",
          "description": "Step 12 — Moat Analysis ($2 tier only)"
        },
        "management_quality": {
          "type": "object",
          "description": "Step 13 — Management Quality ($2 tier only)"
        },
        "dcf_valuation": {
          "type": "object",
          "description": "Step 14 — DCF Valuation ($2 tier only)",
          "properties": {
            "implied_price": {
              "type": "number"
            },
            "current_price": {
              "type": "number"
            },
            "upside_pct": {
              "type": "number"
            },
            "wacc_pct": {
              "type": "number"
            },
            "terminal_growth_rate_pct": {
              "type": "number"
            },
            "assumptions": {
              "type": "object"
            }
          }
        },
        "comp_analysis": {
          "type": "object",
          "description": "Step 15 — Comparable Analysis ($2 tier only)"
        },
        "sensitivity_matrix": {
          "type": "object",
          "description": "Step 16 — Sensitivity Analysis ($2 tier only)",
          "properties": {
            "axes": {
              "type": "object",
              "properties": {
                "x": {
                  "type": "string",
                  "description": "Variable on X axis, e.g. revenue growth rate"
                },
                "y": {
                  "type": "string",
                  "description": "Variable on Y axis, e.g. terminal margin"
                }
              }
            },
            "matrix": {
              "type": "array",
              "description": "3x3 grid of implied prices",
              "items": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              }
            }
          }
        },
        "scenarios": {
          "type": "object",
          "description": "Step 17 — Scenario Analysis ($2 tier only)",
          "properties": {
            "bear": {
              "type": "object",
              "properties": {
                "price_target": {
                  "type": "number"
                },
                "probability": {
                  "type": "number"
                },
                "thesis": {
                  "type": "string"
                },
                "catalysts": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            "base": {
              "type": "object",
              "properties": {
                "price_target": {
                  "type": "number"
                },
                "probability": {
                  "type": "number"
                },
                "thesis": {
                  "type": "string"
                },
                "catalysts": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            },
            "bull": {
              "type": "object",
              "properties": {
                "price_target": {
                  "type": "number"
                },
                "probability": {
                  "type": "number"
                },
                "thesis": {
                  "type": "string"
                },
                "catalysts": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "investment_thesis": {
          "type": "string",
          "description": "Step 18 — 3-sentence investment thesis: company characterization, key assumption, primary risk ($2 tier only)"
        },
        "structured_memo": {
          "type": "string",
          "description": "Step 19 — Full prose investment memo in Markdown, optimized for LLM downstream consumption ($2 tier only)"
        },
        "returns_on_capital": {
          "type": "object",
          "description": "Step 20 — Returns on Capital analysis ($1 tier and above)"
        },
        "institutional_insider": {
          "type": "object",
          "description": "Step 21 — Institutional ownership & insider activity ($2 tier only)"
        }
      }
    },
    "ResponseMetadata": {
      "type": "object",
      "properties": {
        "data_sources": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "model": {
          "type": "string"
        },
        "steps_run": {
          "type": "integer"
        },
        "estimated_self_research_cost_usd": {
          "type": "number"
        },
        "api_version": {
          "type": "string"
        }
      }
    }
  }
}