{
  "openapi": "3.1.0",
  "info": {
    "title": "crypto-ai.dev Price Feed",
    "version": "1.0.0",
    "description": "Free, no-signup crypto price API. Cross-venue VWAP across Binance, Coinbase, Kraken, OKX. Unauthenticated clients receive a 15-second delayed feed; real-time access is keyed.",
    "contact": { "url": "https://crypto-ai.dev" },
    "license": { "name": "Data: public exchange feeds, attribution appreciated" }
  },
  "servers": [
    { "url": "https://crypto-ai-prices.fly.dev", "description": "Production (REST + WebSocket)" },
    { "url": "https://crypto-ai.dev", "description": "Web-app endpoints (wire)" }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "name": "X-API-Key",
        "in": "header",
        "description": "Grants real-time (non-delayed) access. Contact waitlist for access."
      }
    },
    "schemas": {
      "Price": {
        "type": "object",
        "properties": {
          "price":      { "type": "number", "description": "Latest trade price (simple mean across venues)." },
          "vwap":       { "type": "number", "description": "Volume-weighted average price across venues." },
          "change24h":  { "type": "number", "description": "Percentage change vs 24h ago." },
          "volume24h":  { "type": "number", "description": "USD-notional 24h volume (base * vwap summed across venues)." },
          "sources":    { "type": "array", "items": { "type": "string" }, "description": "Contributing venues." },
          "name":       { "type": "string" }
        },
        "required": ["price", "vwap", "change24h", "volume24h", "sources"]
      },
      "PricesResponse": {
        "type": "object",
        "properties": {
          "live":      { "type": "boolean" },
          "delay":     { "type": "number", "description": "Seconds of delay (0 when live)." },
          "timestamp": { "type": "integer" },
          "prices":    { "type": "object", "additionalProperties": { "$ref": "#/components/schemas/Price" } }
        },
        "required": ["live", "delay", "timestamp", "prices"]
      },
      "HistoryResponse": {
        "type": "object",
        "properties": {
          "symbol": { "type": "string" },
          "points": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "t":     { "type": "integer", "description": "Epoch ms" },
                "price": { "type": "number" }
              },
              "required": ["t", "price"]
            }
          }
        }
      },
      "WireItem": {
        "type": "object",
        "properties": {
          "id":          { "type": "string" },
          "title":       { "type": "string" },
          "link":        { "type": "string", "format": "uri" },
          "source":      { "type": "string", "enum": ["CoinDesk", "CoinTelegraph", "Decrypt", "The Block"] },
          "publishedAt": { "type": "string", "format": "date-time" },
          "summary":     { "type": "string" },
          "coins":       { "type": "array", "items": { "type": "string" } }
        }
      }
    }
  },
  "paths": {
    "/api/prices": {
      "get": {
        "summary": "Current prices for every tracked asset",
        "security": [{}, { "ApiKeyHeader": [] }],
        "responses": {
          "200": {
            "description": "Prices object keyed by symbol",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PricesResponse" } } }
          }
        }
      }
    },
    "/api/prices/{symbol}": {
      "get": {
        "summary": "Current price for a single asset",
        "parameters": [
          { "name": "symbol", "in": "path", "required": true, "schema": { "type": "string" }, "example": "BTC" }
        ],
        "security": [{}, { "ApiKeyHeader": [] }],
        "responses": {
          "200": { "description": "OK" },
          "404": { "description": "Unknown symbol" }
        }
      }
    },
    "/api/history/{symbol}": {
      "get": {
        "summary": "24-hour price history",
        "parameters": [
          { "name": "symbol", "in": "path", "required": true, "schema": { "type": "string" }, "example": "BTC" }
        ],
        "responses": {
          "200": {
            "description": "Sampled time-series",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HistoryResponse" } } }
          },
          "404": { "description": "Unknown symbol" }
        }
      }
    },
    "/api/wire": {
      "servers": [{ "url": "https://crypto-ai.dev" }],
      "get": {
        "summary": "Coin-tagged news feed (last 72h)",
        "parameters": [
          { "name": "coin",  "in": "query", "schema": { "type": "string" }, "description": "Filter to items mentioning this symbol." },
          { "name": "q",     "in": "query", "schema": { "type": "string" }, "description": "Full-text filter over title + summary." },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "maximum": 100, "default": 50 } }
        ],
        "responses": {
          "200": {
            "description": "News items, newest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": { "type": "array", "items": { "$ref": "#/components/schemas/WireItem" } },
                    "total": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Service health + per-venue connection stats",
        "responses": { "200": { "description": "OK" } }
      }
    }
  }
}
