{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/shruwd-io/json-schema/shruwd-io-visibility-across-engines-schema.json",
  "title": "VisibilityAcrossEngines",
  "description": "`GET …/visibility?engine=all`: every engine at once and the mention rate across them (`metrics.md` §3.7).",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/shruwd-io-openapi.json#/components/schemas/VisibilityAcrossEngines",
  "type": "object",
  "required": [
    "brand",
    "engine",
    "range",
    "historyFrom",
    "asOf",
    "engines",
    "joining",
    "missing",
    "nResponses",
    "responses",
    "entities"
  ],
  "properties": {
    "brand": {
      "type": "object",
      "required": [
        "brandId",
        "name",
        "timezone"
      ],
      "properties": {
        "brandId": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "timezone": {
          "type": "string"
        }
      }
    },
    "engine": {
      "type": "string",
      "const": "all"
    },
    "range": {
      "type": "object",
      "required": [
        "from",
        "to"
      ],
      "properties": {
        "from": {
          "type": "string",
          "format": "date"
        },
        "to": {
          "type": "string",
          "format": "date"
        }
      }
    },
    "historyFrom": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "Set when `from` was moved forward to the plan's history window."
    },
    "asOf": {
      "type": [
        "string",
        "null"
      ],
      "format": "date",
      "description": "The latest close any engine has numbers for; null when no close covered the range."
    },
    "engines": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Engine"
      },
      "description": "The engines in the cross-engine rate: those that answered through the whole window. Its count belongs beside the rate (\"across 5 engines\")."
    },
    "joining": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/EngineJoining"
      },
      "description": "Engines the plan measures whose answers began after the window opened, with the day they join."
    },
    "missing": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Engine"
      },
      "description": "Engines that answered before the window but not inside it."
    },
    "nResponses": {
      "type": "integer",
      "description": "The fewest answers of any engine in `engines`: the rate shows once every one has ten. 0 when `engines` is empty."
    },
    "responses": {
      "type": "object",
      "additionalProperties": {
        "type": "integer"
      },
      "description": "Each measured engine's answers in its window, keyed by engine."
    },
    "entities": {
      "type": "array",
      "description": "The brand first, then by the rate across engines.",
      "items": {
        "$ref": "#/$defs/EntityAcrossEngines"
      }
    }
  },
  "$defs": {
    "AcrossEnginesMetric": {
      "description": "A metric across engines (`metrics.md` §3.7): the equal-weight mean of\neach engine's own rate over the engines that answered through the whole\nwindow, with an interval that averages their bounds. Shown only when\nevery one of those engines has ten answers of its own; otherwise\n`insufficient_data` names the engine holding it back, and its `n` and\n`needed` are that engine's. `engine` is null when no engine qualifies.\nNever a blended score: one measure, mention rate, beside each engine's.\n",
      "oneOf": [
        {
          "type": "object",
          "required": [
            "state",
            "point",
            "lo",
            "hi",
            "n"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "ok"
            },
            "point": {
              "type": "number",
              "description": "Mean of the engines' rates, in [0, 1]."
            },
            "lo": {
              "type": "number",
              "description": "Mean of the engines' lower bounds."
            },
            "hi": {
              "type": "number",
              "description": "Mean of the engines' upper bounds."
            },
            "n": {
              "type": "integer",
              "description": "Answers behind it, summed over the engines."
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "needed",
            "engine"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "insufficient_data"
            },
            "n": {
              "type": "integer",
              "description": "The short engine's answers."
            },
            "needed": {
              "type": "integer",
              "description": "How many more it needs to cross the floor of ten."
            },
            "engine": {
              "oneOf": [
                {
                  "$ref": "#/$defs/Engine"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "reason",
            "engine"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "undefined"
            },
            "n": {
              "type": "integer"
            },
            "reason": {
              "type": "string"
            },
            "engine": {
              "$ref": "#/$defs/Engine"
            }
          }
        }
      ]
    },
    "DisplayableMetric": {
      "description": "A metric that can be shown. Never a bare number: either a point\nestimate with its 95% interval and `n`, or an explicit reason there is\nno number. `insufficient_data` is **not** zero.\n",
      "oneOf": [
        {
          "type": "object",
          "required": [
            "state",
            "point",
            "lo",
            "hi",
            "n"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "ok"
            },
            "point": {
              "type": "number",
              "description": "Proportion in [0, 1]."
            },
            "lo": {
              "type": "number",
              "description": "Lower bound of the 95% interval."
            },
            "hi": {
              "type": "number",
              "description": "Upper bound of the 95% interval."
            },
            "n": {
              "type": "integer",
              "description": "Responses the estimate rests on."
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "needed"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "insufficient_data"
            },
            "n": {
              "type": "integer"
            },
            "needed": {
              "type": "integer",
              "description": "How many more responses would cross the floor of ten."
            }
          }
        },
        {
          "type": "object",
          "required": [
            "state",
            "n",
            "reason"
          ],
          "properties": {
            "state": {
              "type": "string",
              "const": "undefined"
            },
            "n": {
              "type": "integer"
            },
            "reason": {
              "type": "string"
            }
          }
        }
      ]
    },
    "Engine": {
      "type": "string",
      "enum": [
        "google_aio",
        "google_ai_mode",
        "chatgpt",
        "gemini",
        "perplexity"
      ],
      "description": "`google_aio` — Google AI Overviews. `google_ai_mode` — Google AI Mode, tracked since 2026-10-15. `chatgpt` — ChatGPT. `gemini` — Gemini, tracked since 2026-11-10. `perplexity` — Perplexity, asked through its Sonar API, tracked since 2026-11-11."
    },
    "EngineJoining": {
      "type": "object",
      "required": [
        "engine",
        "inFrom"
      ],
      "properties": {
        "engine": {
          "$ref": "#/$defs/Engine"
        },
        "inFrom": {
          "type": [
            "string",
            "null"
          ],
          "format": "date",
          "description": "The first day the window counts it: when the window no longer holds the brand's answers from before its first. Null when it has not answered the brand yet."
        }
      }
    },
    "EntityAcrossEngines": {
      "type": "object",
      "required": [
        "entityId",
        "canonicalName",
        "isSelf",
        "mentionRate",
        "byEngine"
      ],
      "properties": {
        "entityId": {
          "type": "string"
        },
        "canonicalName": {
          "type": "string"
        },
        "isSelf": {
          "type": "boolean"
        },
        "mentionRate": {
          "allOf": [
            {
              "$ref": "#/$defs/AcrossEnginesMetric"
            }
          ],
          "description": "The mention rate across `engines`."
        },
        "byEngine": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/DisplayableMetric"
          },
          "description": "Every measured engine's mention rate, keyed by engine: the same number its own read gives. `insufficient_data` with n 0 where the engine has no answers for the entity."
        }
      }
    }
  }
}