openapi: 3.1.0
info:
  title: BankIntel API
  version: 1.1.0
  description: |
    Agent-ready intelligence for FDIC-insured U.S. banks. BankIntel normalizes
    public FDIC BankFind Suite and Summary of Deposits data, exposes deterministic
    derived ratios, trends, screening, geographic intelligence, regulatory-capital
    references, and transparent peer-relative context. Paid resources use x402 V2.
servers:
  - url: https://bankintel.onrender.com
    description: Live BankIntel API

tags:
  - name: Discovery
  - name: Banks
  - name: Paid Intelligence

paths:
  /health:
    get:
      tags: [Discovery]
      summary: Health check
      responses:
        '200': { description: Healthy }

  /v1/web/access:
    get:
      tags: [Discovery]
      summary: Check the signed-in web account's approval status
      description: Requires a valid Clerk bearer token from an authorized party. Responses are private and not cached. Registration does not grant licensed access.
      parameters:
        - in: header
          name: Authorization
          required: true
          schema: { type: string }
      responses:
        '200': { description: Verified and approved web account }
        '401': { description: Missing or invalid session token }
        '403': { description: Verified account awaiting approval }
        '503': { description: Web authorization configuration unavailable }

  /v1/catalog:
    get:
      tags: [Discovery]
      summary: Machine-readable endpoint and pricing catalog
      responses:
        '200': { description: BankIntel resource catalog }

  /llms.txt:
    get:
      tags: [Discovery]
      summary: Concise agent-readable service description
      responses:
        '200': { description: Plain-text service description }

  /openapi.yaml:
    get:
      tags: [Discovery]
      summary: OpenAPI contract
      responses:
        '200': { description: This OpenAPI document }

  /docs:
    get:
      tags: [Discovery]
      summary: Developer documentation
      responses:
        '200': { description: BankIntel developer guide }

  /v1/banks/search:
    get:
      tags: [Banks]
      summary: Search FDIC institutions
      parameters:
        - { in: query, name: q, required: true, schema: { type: string, minLength: 2, maxLength: 80 } }
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 25, default: 10 } }
      responses:
        '200': { description: Matching institutions }
        '400': { $ref: '#/components/responses/InvalidRequest' }

  /v1/banks/screen:
    get:
      tags: [Paid Intelligence]
      summary: Cross-bank screening, filtering, and ranking
      description: |
        x402 price: $0.20. Screens supported FDIC financial metrics across the
        selected quarterly reporting universe. If report_date is omitted,
        BankIntel resolves the latest FDIC financial report date.
      parameters:
        - { in: query, name: report_date, description: "Optional FDIC report date in YYYYMMDD format. Defaults to latest available.", schema: { type: string, pattern: '^[0-9]{8}$' } }
        - { in: query, name: filter, description: "Repeatable filter in metric:operator:value form. Operators: gt, gte, lt, lte, eq.", schema: { type: array, items: { type: string } }, style: form, explode: true }
        - { in: query, name: sort_by, description: Supported screening metric, schema: { type: string, default: assets_usd } }
        - { in: query, name: sort_order, schema: { type: string, enum: [asc, desc], default: desc } }
        - { in: query, name: min_assets, description: Minimum FDIC-reported assets in thousands, schema: { type: number, minimum: 0 } }
        - { in: query, name: max_assets, description: Maximum FDIC-reported assets in thousands, schema: { type: number, minimum: 0 } }
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
      responses:
        '200': { description: Screening results and metric definitions }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '502': { $ref: '#/components/responses/UpstreamError' }
        '503': { $ref: '#/components/responses/UpstreamUnavailable' }

  /v1/banks/{cert}/snapshot:
    get:
      tags: [Paid Intelligence]
      summary: Normalized quarterly bank snapshot
      description: "x402 price: $0.03. Includes balance sheet, performance, capital and derived ratios."
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Bank snapshot }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/trends:
    get:
      tags: [Paid Intelligence]
      summary: Quarterly bank trend series
      description: "x402 price: $0.05. Includes historical financial, capital, earnings, loan, credit-quality, deposit and funding data."
      parameters:
        - { $ref: '#/components/parameters/Cert' }
        - { in: query, name: quarters, schema: { type: integer, minimum: 4, maximum: 20, default: 8 } }
      responses:
        '200': { description: Trend series }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/liquidity:
    get:
      tags: [Paid Intelligence]
      summary: Liquidity and funding intelligence
      description: "x402 price: $0.05. Includes liquidity, funding, borrowings, uninsured/brokered deposits and YoY trends."
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Liquidity and funding intelligence }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/deposits:
    get:
      tags: [Paid Intelligence]
      summary: Deposit composition and funding intelligence
      description: "x402 price: $0.05. Includes deposit composition, insurance estimates, brokered funding, selected maturity data and trends."
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Deposit intelligence }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/regulatory-capital:
    get:
      tags: [Paid Intelligence]
      summary: Regulatory-capital reference intelligence
      description: |
        x402 price: $0.05. Returns reported capital ratios and deterministic
        comparisons with published numerical regulatory reference thresholds.
        It does not assign an official PCA classification or supervisory rating.
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Reported capital ratios and numerical reference assessment }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/securities:
    get:
      tags: [Paid Intelligence]
      summary: Securities composition, maturity exposure, and trends
      description: |
        x402 price: $0.10. FDIC securities categories are not assumed to be
        mutually exclusive; BankIntel does not synthesize unsupported residual
        categories or maturity buckets.
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Securities intelligence }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/geography:
    get:
      tags: [Paid Intelligence]
      summary: Geographic deposit footprint and market intelligence
      description: |
        x402 price: $0.10. Uses FDIC Summary of Deposits data to calculate
        deposit footprint, concentration, and selected county/MSA market-share
        and rank statistics.
      parameters:
        - { $ref: '#/components/parameters/Cert' }
        - { in: query, name: year, description: "Optional SOD year. Defaults to latest FDIC SOD year.", schema: { type: integer, minimum: 1934, maximum: 2100 } }
      responses:
        '200': { description: Geographic deposit intelligence }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/peers:
    get:
      tags: [Paid Intelligence]
      summary: Transparent FDIC peer benchmarking
      description: "x402 price: $0.15. Same-quarter nationwide peer cohort with assets from 50% to 200% of subject assets."
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Peer statistics and percentiles }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/historical-peers:
    get:
      tags: [Paid Intelligence]
      summary: Historical peer benchmarking
      description: |
        x402 price: $0.20. Recalculates the same-quarter nationwide 50%-200%
        asset peer cohort independently for each historical quarter.
      parameters:
        - { $ref: '#/components/parameters/Cert' }
        - { in: query, name: quarters, schema: { type: integer, minimum: 4, maximum: 20, default: 8 } }
      responses:
        '200': { description: Historical peer statistics and percentiles }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

  /v1/banks/{cert}/analysis:
    get:
      tags: [Paid Intelligence]
      summary: Cross-domain bank analysis
      description: "x402 price: $0.25. Combines funding, liquidity, capital, profitability, securities and peer context without assigning a rating."
      parameters: [ { $ref: '#/components/parameters/Cert' } ]
      responses:
        '200': { description: Cross-domain factual analysis }
        '400': { $ref: '#/components/responses/InvalidRequest' }
        '402': { $ref: '#/components/responses/PaymentRequired' }
        '404': { $ref: '#/components/responses/NotFound' }

components:
  parameters:
    Cert:
      in: path
      name: cert
      required: true
      description: FDIC certificate number
      schema: { type: integer, minimum: 1 }

  responses:
    InvalidRequest:
      description: Invalid or ambiguous request parameters.

    PaymentRequired:
      description: x402 V2 payment required. Read the PAYMENT-REQUIRED response metadata for authoritative network, asset, amount, and payTo values.

    NotFound:
      description: Bank or required financial data not found.

    UpstreamError:
      description: FDIC returned an upstream HTTP error.

    UpstreamUnavailable:
      description: FDIC is unavailable or rate limited.
