{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/varg-ai/json-schema/varg-ai-resource-file-schema.json",
  "title": "ResourceFile",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/varg-ai-openapi.json#/components/schemas/ResourceFile",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "source": {
      "type": "string",
      "enum": [
        "attachment",
        "gateway"
      ],
      "description": "`gateway` for generated files, `attachment` for uploads."
    },
    "url": {
      "type": "string"
    },
    "filename": {
      "type": [
        "string",
        "null"
      ]
    },
    "title": {
      "type": [
        "string",
        "null"
      ]
    },
    "subtitle": {
      "type": [
        "string",
        "null"
      ]
    },
    "media_type": {
      "type": [
        "string",
        "null"
      ]
    },
    "size": {
      "type": [
        "integer",
        "null"
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "hash": {
      "type": [
        "string",
        "null"
      ]
    },
    "thumbnail_url": {
      "type": [
        "string",
        "null"
      ]
    },
    "origin": {
      "type": "string",
      "enum": [
        "upload",
        "generated"
      ]
    },
    "created_by": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid"
    },
    "created_by_profile": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "display_name": {
          "type": [
            "string",
            "null"
          ]
        },
        "avatar_url": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "creator_type": {
      "type": [
        "string",
        "null"
      ],
      "enum": [
        "user",
        "api_key",
        "system",
        null
      ]
    },
    "created_by_api_key": {
      "type": [
        "object",
        "null"
      ],
      "description": "The API key the file was created through. Only set when `creator_type` is `api_key`.",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "key_preview": {
          "type": "string"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "metadata": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": true
    },
    "lineage": {
      "oneOf": [
        {
          "$ref": "#/$defs/ResourceLineage"
        },
        {
          "type": "null"
        }
      ]
    },
    "is_favorite": {
      "type": "boolean"
    }
  },
  "$defs": {
    "ResourceLineage": {
      "type": "object",
      "description": "The job that produced a file. Detail responses carry extra fields (`provider`, `breakdown`, `created_at`, `file`).",
      "additionalProperties": true,
      "properties": {
        "job_id": {
          "type": "string"
        },
        "tool": {
          "type": "string"
        },
        "model": {
          "type": [
            "string",
            "null"
          ]
        },
        "prompt": {
          "type": [
            "string",
            "null"
          ]
        },
        "provider": {
          "type": [
            "string",
            "null"
          ]
        },
        "cost_cents": {
          "type": [
            "integer",
            "null"
          ]
        },
        "parent_job_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "root_job_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "children_count": {
          "type": "integer"
        },
        "total_cost_cents": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Cost of this job plus every sub-generation it spawned."
        },
        "children_by_tool": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "tool": {
                "type": "string"
              },
              "count": {
                "type": "integer"
              },
              "cost_cents": {
                "type": "integer"
              }
            }
          }
        },
        "breakdown": {
          "type": "array",
          "description": "Per-job cost lines behind `total_cost_cents`. Only on the detail endpoint, and only when the job has children.",
          "items": {
            "type": "object",
            "properties": {
              "job_id": {
                "type": "string"
              },
              "tool": {
                "type": "string"
              },
              "model": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "status": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "cost_cents": {
                "type": "integer"
              },
              "is_root": {
                "type": "boolean"
              }
            }
          }
        },
        "output_count": {
          "type": "integer",
          "description": "Total files the job produced."
        },
        "output_index": {
          "type": [
            "integer",
            "null"
          ],
          "description": "1-based position of this file among the job's outputs."
        },
        "primary_file_id": {
          "type": [
            "string",
            "null"
          ]
        },
        "created_at": {
          "type": "string",
          "format": "date-time"
        },
        "input": {
          "type": "object",
          "additionalProperties": true
        },
        "file": {
          "type": "object",
          "additionalProperties": true
        }
      }
    }
  }
}