{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.cheapgpu.com/specs/endpoint-v1-draft/schemas/model-catalog.schema.json",
  "$comment": "Model identity, capabilities and protocol metadata only. All inference prices come from supplier offers; the model catalog carries no rates or price sources.",
  "type": "object",
  "properties": {
    "contract_version": {
      "const": "cheapgpu.endpoint.v1-draft.4"
    },
    "catalog_revision": {
      "$ref": "common.schema.json#/$defs/positive_decimal"
    },
    "status": {
      "const": "draft"
    },
    "coverage": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9._-]{0,127}$"
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1024
          },
          "kind": {
            "enum": [
              "model_author_or_family",
              "provider"
            ]
          },
          "status": {
            "enum": [
              "seeded",
              "planned",
              "synthetic"
            ]
          }
        },
        "required": [
          "id",
          "display_name",
          "kind",
          "status"
        ],
        "additionalProperties": false
      },
      "minItems": 1,
      "uniqueItems": true
    },
    "models": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "model_id": {
            "$ref": "common.schema.json#/$defs/model_id"
          },
          "model_revision": {
            "anyOf": [
              {
                "$ref": "common.schema.json#/$defs/model_revision"
              },
              {
                "type": "null"
              }
            ]
          },
          "display_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1024
          },
          "catalog_state": {
            "enum": [
              "candidate",
              "synthetic",
              "registered"
            ]
          },
          "author_id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9._-]{0,127}$"
          },
          "family_id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9._-]{0,127}$"
          },
          "upstream": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9._-]{0,127}$"
                  },
                  "model_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1024
                  },
                  "documented_snapshot_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 1024
                    },
                    "minItems": 0,
                    "uniqueItems": true
                  },
                  "capabilities": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9._-]{0,127}$"
                    },
                    "minItems": 1,
                    "uniqueItems": true
                  },
                  "constraints": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 1024
                    },
                    "minItems": 0,
                    "uniqueItems": true
                  },
                  "sources": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "url": {
                          "type": "string",
                          "pattern": "^https://[^\\s]+$",
                          "maxLength": 2048
                        },
                        "checked_on": {
                          "type": "string",
                          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
                        },
                        "kind": {
                          "enum": [
                            "model"
                          ]
                        }
                      },
                      "required": [
                        "url",
                        "checked_on",
                        "kind"
                      ],
                      "additionalProperties": false
                    },
                    "minItems": 1,
                    "uniqueItems": true
                  },
                  "lifecycle": {
                    "enum": [
                      "listed",
                      "deprecated",
                      "retired",
                      "unknown"
                    ]
                  }
                },
                "required": [
                  "provider_id",
                  "model_id",
                  "documented_snapshot_ids",
                  "capabilities",
                  "constraints",
                  "sources",
                  "lifecycle"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          },
          "input_modalities": {
            "type": "array",
            "items": {
              "enum": [
                "text",
                "image",
                "audio",
                "video"
              ]
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "output_modalities": {
            "type": "array",
            "items": {
              "enum": [
                "text",
                "image",
                "audio",
                "video",
                "embedding"
              ]
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "billing_dimensions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^[a-z][a-z0-9._-]{0,127}$"
                },
                "unit": {
                  "enum": [
                    "token",
                    "second",
                    "image",
                    "frame",
                    "request"
                  ]
                }
              },
              "required": [
                "id",
                "unit"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "tasks": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/$defs/language_task"
                },
                {
                  "$ref": "#/$defs/video_task"
                }
              ]
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "registration": {
            "oneOf": [
              {
                "$ref": "#/$defs/huggingface_registration"
              },
              {
                "$ref": "#/$defs/provider_snapshot_registration"
              }
            ]
          }
        },
        "required": [
          "model_id",
          "model_revision",
          "display_name",
          "catalog_state",
          "author_id",
          "family_id",
          "upstream",
          "input_modalities",
          "output_modalities",
          "billing_dimensions",
          "tasks"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "catalog_state": {
                  "const": "candidate"
                }
              },
              "required": [
                "catalog_state"
              ]
            },
            "then": {
              "properties": {
                "upstream": {
                  "type": "object"
                },
                "tasks": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "api_profiles": {
                        "type": "array",
                        "maxItems": 0
                      }
                    }
                  }
                }
              }
            },
            "else": {
              "if": {
                "properties": {
                  "catalog_state": {
                    "const": "synthetic"
                  }
                },
                "required": [
                  "catalog_state"
                ]
              },
              "then": {
                "properties": {
                  "upstream": {
                    "type": "null"
                  },
                  "model_revision": {
                    "$ref": "common.schema.json#/$defs/model_revision"
                  }
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "catalog_state": {
                  "const": "registered"
                }
              },
              "required": [
                "catalog_state"
              ]
            },
            "then": {
              "required": [
                "registration"
              ],
              "properties": {
                "model_revision": {
                  "$ref": "common.schema.json#/$defs/model_revision"
                },
                "upstream": {
                  "type": "object"
                },
                "registration": {}
              },
              "if": {
                "properties": {
                  "registration": {
                    "properties": {
                      "kind": {
                        "const": "huggingface_commit"
                      }
                    },
                    "required": [
                      "kind"
                    ],
                    "type": "object"
                  }
                },
                "required": [
                  "registration"
                ]
              },
              "then": {
                "properties": {
                  "model_revision": {
                    "type": "string",
                    "pattern": "^hf-[a-f0-9]{40}$"
                  }
                }
              }
            },
            "else": {
              "not": {
                "required": [
                  "registration"
                ],
                "properties": {
                  "registration": {}
                }
              }
            }
          }
        ]
      },
      "minItems": 1,
      "uniqueItems": true
    }
  },
  "required": [
    "contract_version",
    "catalog_revision",
    "status",
    "coverage",
    "models"
  ],
  "additionalProperties": false,
  "$defs": {
    "language_task": {
      "type": "object",
      "properties": {
        "task_type": {
          "const": "language_generation"
        },
        "specification": {
          "type": "object",
          "properties": {
            "context_window_tokens": {
              "$ref": "common.schema.json#/$defs/positive_decimal"
            },
            "max_input_tokens": {
              "$ref": "common.schema.json#/$defs/positive_decimal"
            },
            "max_output_tokens": {
              "$ref": "common.schema.json#/$defs/positive_decimal"
            },
            "reasoning_efforts": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9._-]{0,127}$"
              },
              "minItems": 0,
              "uniqueItems": true
            },
            "structured_output_constraints": {
              "enum": [
                "openai_base",
                "openai_fine_tuned",
                null
              ],
              "description": "Trusted provider schema-constraint class. Null is unknown, not an assumed base model."
            }
          },
          "required": [
            "context_window_tokens",
            "max_input_tokens",
            "max_output_tokens",
            "reasoning_efforts",
            "structured_output_constraints"
          ],
          "additionalProperties": false
        },
        "api_profiles": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/profile_id"
          },
          "minItems": 0,
          "uniqueItems": true
        },
        "upstream_interfaces": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/upstream_interface"
          }
        }
      },
      "required": [
        "task_type",
        "specification",
        "api_profiles",
        "upstream_interfaces"
      ],
      "additionalProperties": false
    },
    "video_task": {
      "type": "object",
      "properties": {
        "task_type": {
          "const": "video_generation"
        },
        "specification": {
          "type": "object",
          "properties": {
            "duration_seconds": {
              "anyOf": [
                {
                  "type": "object",
                  "properties": {
                    "minimum": {
                      "type": "string",
                      "pattern": "^([1-9][0-9]*(\\.[0-9]+)?|0\\.[0-9]*[1-9][0-9]*)$",
                      "maxLength": 64
                    },
                    "maximum": {
                      "type": "string",
                      "pattern": "^([1-9][0-9]*(\\.[0-9]+)?|0\\.[0-9]*[1-9][0-9]*)$",
                      "maxLength": 64
                    }
                  },
                  "required": [
                    "minimum",
                    "maximum"
                  ],
                  "additionalProperties": false
                },
                {
                  "type": "null"
                }
              ]
            },
            "resolutions": {
              "anyOf": [
                {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "minItems": 1,
                  "uniqueItems": true
                },
                {
                  "type": "null"
                }
              ]
            },
            "frames_per_second": {
              "anyOf": [
                {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "pattern": "^([1-9][0-9]*(\\.[0-9]+)?|0\\.[0-9]*[1-9][0-9]*)$",
                    "maxLength": 64
                  },
                  "minItems": 1,
                  "uniqueItems": true
                },
                {
                  "type": "null"
                }
              ]
            },
            "audio_output": {
              "type": [
                "boolean",
                "null"
              ]
            }
          },
          "required": [
            "duration_seconds",
            "resolutions",
            "frames_per_second",
            "audio_output"
          ],
          "additionalProperties": false
        },
        "api_profiles": {
          "type": "array",
          "maxItems": 0
        },
        "upstream_interfaces": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/upstream_interface"
          }
        }
      },
      "required": [
        "task_type",
        "specification",
        "api_profiles",
        "upstream_interfaces"
      ],
      "additionalProperties": false
    },
    "upstream_interface": {
      "type": "object",
      "properties": {
        "api_family": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9._-]{0,127}$"
        },
        "execution_modes": {
          "anyOf": [
            {
              "type": "array",
              "items": {
                "enum": [
                  "request_response",
                  "streaming",
                  "async_task"
                ]
              },
              "minItems": 1,
              "uniqueItems": true
            },
            {
              "type": "null"
            }
          ]
        },
        "capability_support": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "capability": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9._-]{0,127}$"
              },
              "support": {
                "enum": [
                  "supported",
                  "unsupported",
                  "conditional"
                ]
              },
              "conditions": {
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "type": "object",
                  "properties": {
                    "field": {
                      "type": "string",
                      "pattern": "^/(?:[^~]|~[01])*$"
                    },
                    "values": {
                      "type": "array",
                      "minItems": 1,
                      "uniqueItems": true,
                      "items": {
                        "anyOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "boolean"
                          },
                          {
                            "type": "null"
                          }
                        ]
                      }
                    }
                  },
                  "required": [
                    "field",
                    "values"
                  ],
                  "additionalProperties": false
                }
              }
            },
            "required": [
              "capability",
              "support",
              "conditions"
            ],
            "additionalProperties": false,
            "allOf": [
              {
                "if": {
                  "properties": {
                    "support": {
                      "const": "conditional"
                    }
                  },
                  "required": [
                    "support"
                  ]
                },
                "then": {
                  "properties": {
                    "conditions": {
                      "minItems": 1,
                      "type": "array"
                    }
                  }
                },
                "else": {
                  "properties": {
                    "conditions": {
                      "maxItems": 0,
                      "type": "array"
                    }
                  }
                }
              }
            ]
          }
        }
      },
      "required": [
        "api_family",
        "execution_modes",
        "capability_support"
      ],
      "additionalProperties": false
    },
    "huggingface_registration": {
      "type": "object",
      "properties": {
        "kind": {
          "const": "huggingface_commit"
        },
        "repository": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+/[A-Za-z0-9_.-]+$",
          "maxLength": 256
        },
        "commit": {
          "type": "string",
          "pattern": "^[a-f0-9]{40}$"
        },
        "artifacts": {
          "type": "array",
          "minItems": 3,
          "maxItems": 512,
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_][A-Za-z0-9_./-]{0,255}$"
              },
              "role": {
                "enum": [
                  "weights",
                  "tokenizer",
                  "config"
                ]
              },
              "sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              }
            },
            "required": [
              "path",
              "role",
              "sha256"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "kind",
        "repository",
        "commit",
        "artifacts"
      ],
      "additionalProperties": false
    },
    "provider_snapshot_registration": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "kind": {
          "const": "provider_snapshot"
        },
        "provider_id": {
          "const": "openai"
        },
        "snapshot_id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9._-]{0,127}$"
        }
      },
      "required": [
        "kind",
        "provider_id",
        "snapshot_id"
      ]
    }
  }
}
