{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/amplerun-com/json-schema/amplerun-com-template-schema.json",
  "title": "Template",
  "description": "Public template (D-19(b)); mirrors packages/contracts/schemas/template.schema.json, which remains the authority for templates.spec. kind=model requires model_ref and readiness.",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/amplerun-com-openapi.json#/components/schemas/Template",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "published",
    "template_id",
    "name",
    "template_version",
    "image_digest",
    "launch_profile_version",
    "kind",
    "engine",
    "vram_fit",
    "exposes",
    "env",
    "min_gpu_count",
    "required_runtime",
    "setup_notes"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/UUID"
    },
    "published": {
      "type": "boolean"
    },
    "template_id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]{0,63}$"
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "template_version": {
      "type": "string",
      "minLength": 1
    },
    "image_digest": {
      "$ref": "#/$defs/ImageDigest",
      "description": "Pinned OCI reference (name@sha256:<64 hex>) — the same form quotes, START commands and qualification records carry."
    },
    "launch_profile_version": {
      "type": "string",
      "minLength": 1
    },
    "kind": {
      "enum": [
        "model",
        "classical",
        "custom"
      ]
    },
    "engine": {
      "enum": [
        "vllm",
        "llamacpp",
        "comfyui",
        "faster-whisper",
        "pytorch",
        "jupyter",
        "ollama",
        "oci"
      ]
    },
    "model_ref": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "hf_repo",
        "revision",
        "files"
      ],
      "properties": {
        "hf_repo": {
          "type": "string",
          "minLength": 1
        },
        "revision": {
          "type": "string",
          "minLength": 1
        },
        "files": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "sha256",
              "size_bytes"
            ],
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^(?!\\.\\.?$)[A-Za-z0-9._-]+$"
              },
              "sha256": {
                "type": "string",
                "pattern": "^[0-9a-f]{64}$"
              },
              "size_bytes": {
                "$ref": "#/$defs/DecimalString"
              }
            }
          }
        }
      }
    },
    "quantization": {
      "type": "string",
      "minLength": 1
    },
    "vram_fit": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "min_vram_bytes",
        "est_weights_bytes",
        "est_kv_bytes_per_1k_tokens"
      ],
      "properties": {
        "min_vram_bytes": {
          "$ref": "#/$defs/DecimalString"
        },
        "est_weights_bytes": {
          "$ref": "#/$defs/DecimalString"
        },
        "est_kv_bytes_per_1k_tokens": {
          "$ref": "#/$defs/DecimalString"
        }
      }
    },
    "readiness": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "http_path",
        "expect_status"
      ],
      "properties": {
        "http_path": {
          "type": "string",
          "pattern": "^/"
        },
        "expect_status": {
          "type": "integer",
          "minimum": 100,
          "maximum": 599
        }
      }
    },
    "exposes": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "name",
          "port",
          "protocol"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1
          },
          "port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
          },
          "protocol": {
            "enum": [
              "http",
              "ssh",
              "tcp"
            ]
          }
        }
      }
    },
    "env": {
      "type": "object",
      "propertyNames": {
        "pattern": "^[A-Z][A-Z0-9_]{1,63}$"
      },
      "additionalProperties": {
        "type": "string"
      }
    },
    "min_gpu_count": {
      "type": "integer",
      "minimum": 1
    },
    "required_runtime": {
      "enum": [
        "cuda",
        "rocm-hip",
        "level-zero",
        "opencl",
        "xpu"
      ]
    },
    "setup_notes": {
      "type": "string"
    },
    "runtimes": {
      "description": "Additive. One template, many backends: the same weights and API contract per backend. tier container is an OCI image; tier inference is the signed Tier B runtime artifact (<source>@sha256:<hex>). The control plane picks the machine's runtime by preference (cuda > rocm > sycl > vulkan > metal) and pins its digest in the quote and lease.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "cuda": {
          "$ref": "#/$defs/TemplateRuntime"
        },
        "rocm": {
          "$ref": "#/$defs/TemplateRuntime"
        },
        "sycl": {
          "$ref": "#/$defs/TemplateRuntime"
        },
        "vulkan": {
          "$ref": "#/$defs/TemplateRuntime"
        },
        "metal": {
          "$ref": "#/$defs/TemplateRuntime"
        }
      }
    },
    "backends": {
      "description": "Additive. Backends with a built runtime, in preference order (\"Works on\" filter). Spec compatibility, not a hardware test.",
      "type": "array",
      "items": {
        "enum": [
          "cuda",
          "rocm",
          "sycl",
          "vulkan",
          "metal"
        ]
      }
    },
    "works_on": {
      "description": "Additive. Hardware vendors those backends cover. Spec compatibility only; a hardware report is what says \"tested on\".",
      "type": "array",
      "items": {
        "enum": [
          "nvidia",
          "amd",
          "intel",
          "apple"
        ]
      }
    }
  },
  "$defs": {
    "DecimalString": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)$",
      "description": "Unsigned base-10 integer as string; never a float."
    },
    "ImageDigest": {
      "type": "string",
      "pattern": "^[^@\\s]+@sha256:[0-9a-f]{64}$"
    },
    "TemplateRuntime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tier",
        "image_digest"
      ],
      "properties": {
        "tier": {
          "enum": [
            "container",
            "inference"
          ]
        },
        "image_digest": {
          "$ref": "#/$defs/ImageDigest"
        }
      }
    },
    "UUID": {
      "type": "string",
      "format": "uuid",
      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
    }
  }
}