{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://open-assets.x12i.com/schemas/models-profiles.schema.json",
  "title": "x12i AI Profiles Model Registry v4",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "registryId",
    "generatedAt",
    "lastVerifiedAt",
    "version",
    "currency",
    "pricingUnit",
    "namingConvention",
    "semantics",
    "sourceCatalog",
    "profiles"
  ],
  "properties": {
    "schema": {
      "const": "x12i.ai-profiles.model-registry.v4"
    },
    "registryId": { "type": "string", "minLength": 1 },
    "generatedAt": { "type": "string", "format": "date-time" },
    "lastVerifiedAt": { "type": "string", "format": "date-time" },
    "version": { "type": "string" },
    "currency": { "const": "USD" },
    "pricingUnit": { "const": "1M_tokens" },
    "namingConvention": { "const": "lowerCamelCase" },
    "semantics": { "type": "object", "additionalProperties": { "type": "string" } },
    "sourceCatalog": {
      "type": "object",
      "required": ["providers"],
      "properties": {
        "providers": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["id"],
            "properties": {
              "id": { "type": "string" },
              "docsUrl": { "type": "string", "format": "uri" }
            }
          }
        },
        "modelsCatalogUrl": { "type": "string", "format": "uri" },
        "openRouterCatalogUrl": { "type": "string", "format": "uri" }
      }
    },
    "profiles": {
      "type": "object",
      "additionalProperties": { "$ref": "#/$defs/profile" }
    }
  },
  "$defs": {
    "profile": {
      "type": "object",
      "required": [
        "profile",
        "displayName",
        "description",
        "category",
        "catalogLane",
        "defaultChoice",
        "choices"
      ],
      "properties": {
        "profile": { "type": "string" },
        "displayName": { "type": "string" },
        "description": { "type": "string" },
        "category": { "type": "string" },
        "vendorFamily": { "type": "boolean" },
        "catalogLane": {
          "enum": [
            "text",
            "image",
            "embeddings",
            "audio",
            "video",
            "rerank",
            "speech",
            "transcription"
          ]
        },
        "defaultChoice": { "type": "string" },
        "requiredCapabilities": { "$ref": "#/$defs/requiredCapabilities" },
        "deploymentType": {
          "enum": ["proprietary", "openWeightsHosted", "selfHosted"]
        },
        "fallbackChoiceOrder": { "type": "array", "items": { "type": "string" } },
        "defaultSecondaryChoice": { "type": "string" },
        "tags": {
          "type": "array",
          "items": {
            "enum": [
              "flg",
              "eco",
              "pro",
              "exp",
              "agt",
              "sec",
              "cyb",
              "rsn",
              "anl",
              "for",
              "aud",
              "str",
              "json",
              "xtr",
              "cls",
              "cod",
              "eng",
              "res",
              "cre",
              "wrt",
              "sum",
              "vis",
              "rte",
              "tri",
              "wf",
              "bat",
              "rev",
              "spd",
              "loc",
              "vnd",
              "ds",
              "ggl",
              "xai",
              "mmx",
              "ant",
              "oai"
            ]
          },
          "uniqueItems": true
        },
        "choices": {
          "type": "object",
          "additionalProperties": { "$ref": "#/$defs/choice" }
        }
      }
    },
    "requiredCapabilities": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "reasoning": {
          "enum": ["minimal", "low", "medium", "high", "max"]
        },
        "coding": { "type": "boolean" },
        "context": { "enum": ["standard", "large", "xlarge"] },
        "cost": { "enum": ["low", "medium", "high"] },
        "speed": { "enum": ["high"] },
        "latency": { "enum": ["low"] },
        "quality": { "enum": ["high", "premium"] },
        "structuredOutput": { "type": "boolean" },
        "supportsJsonSchema": { "type": "boolean" },
        "supportsVision": { "type": "boolean" },
        "supportsTools": { "type": "boolean" },
        "inputModalities": {
          "type": "array",
          "items": {
            "enum": ["text", "image", "audio", "video", "file"]
          },
          "minItems": 1
        },
        "outputModalities": {
          "type": "array",
          "items": {
            "enum": ["text", "image", "audio", "video", "file"]
          },
          "minItems": 1
        }
      }
    },
    "modalityContract": {
      "type": "object",
      "required": ["input", "output"],
      "additionalProperties": false,
      "properties": {
        "input": {
          "type": "array",
          "items": {
            "enum": ["text", "image", "audio", "video", "file"]
          },
          "minItems": 1
        },
        "output": {
          "type": "array",
          "items": {
            "enum": ["text", "image", "audio", "video", "file"]
          },
          "minItems": 1
        }
      }
    },
    "secondaryRef": {
      "type": "object",
      "required": ["kind"],
      "properties": {
        "kind": { "enum": ["choice", "model"] },
        "choice": { "type": "string" },
        "provider": { "type": "string" },
        "modelId": { "type": "string" },
        "reason": { "type": "string" },
        "runtime": {
          "type": "object",
          "additionalProperties": true
        }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "choice" } } },
          "then": { "required": ["choice"] }
        },
        {
          "if": { "properties": { "kind": { "const": "model" } } },
          "then": { "required": ["provider", "modelId"] }
        }
      ]
    },
    "choice": {
      "type": "object",
      "required": ["choice", "provider", "modelId"],
      "properties": {
        "choice": { "type": "string" },
        "displayName": { "type": "string" },
        "description": { "type": "string" },
        "provider": { "type": "string" },
        "modelId": { "type": "string" },
        "modelStatus": { "enum": ["verified", "predicted"] },
        "modalities": { "$ref": "#/$defs/modalityContract" },
        "secondary": { "$ref": "#/$defs/secondaryRef" },
        "deploymentType": {
          "enum": ["proprietary", "openWeightsHosted", "selfHosted"]
        }
      }
    }
  }
}
