{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/flashdata-dev/json-schema/flashdata-dev-subscription-schema.json",
  "title": "Subscription",
  "description": "Effective entitlement projection. `status=payg` and `id=null` means no billing subscription record exists.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/flashdata-dev-billing-api-openapi.yml#/components/schemas/Subscription",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "status",
    "plan",
    "cancelAtPeriodEnd",
    "usageRates"
  ],
  "properties": {
    "id": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^sub_"
    },
    "status": {
      "type": "string",
      "enum": [
        "payg",
        "trialing",
        "active",
        "past_due",
        "grace",
        "cancelled"
      ]
    },
    "plan": {
      "$ref": "#/$defs/Plan"
    },
    "usageRates": {
      "type": "object",
      "description": "Account-specific configured credit rates. Query rates come from the account entitlement, not the public plan catalog. One TB is 1,000,000,000,000 bytes; download charges are settled against actual bytes and rounded per result.",
      "additionalProperties": false,
      "required": [
        "customized",
        "queries",
        "downloadCreditsPerTb"
      ],
      "properties": {
        "customized": {
          "type": "boolean",
          "description": "True when an administrator configured rates for this account."
        },
        "queries": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "source",
              "name",
              "creditsPerRequest"
            ],
            "properties": {
              "source": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "creditsPerRequest": {
                "type": "number",
                "minimum": 0
              }
            }
          }
        },
        "downloadCreditsPerTb": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "currentPeriodStart": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "currentPeriodEnd": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "cancelAtPeriodEnd": {
      "type": "boolean"
    },
    "graceEndsAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  },
  "$defs": {
    "Plan": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "slug",
        "name",
        "description",
        "includedCredits",
        "limits",
        "prices",
        "features",
        "usagePrices"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^plan_"
        },
        "slug": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "includedCredits": {
          "type": "number",
          "minimum": 0,
          "multipleOf": 0.001,
          "description": "Credits included in each paid subscription cycle; zero for Pay As You Go."
        },
        "limits": {
          "$ref": "#/$defs/PlanLimits"
        },
        "prices": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/PlanPrice"
          }
        },
        "features": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "usagePrices": {
          "$ref": "#/$defs/PlanUsagePrices"
        }
      }
    },
    "PlanLimits": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "concurrency",
        "maxBatchSize",
        "maxPendingJobs"
      ],
      "properties": {
        "concurrency": {
          "type": "integer",
          "minimum": 1
        },
        "maxBatchSize": {
          "type": "integer",
          "minimum": 1
        },
        "maxPendingJobs": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "PlanPrice": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "currency",
        "unitAmount",
        "credits",
        "type",
        "interval"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^prc_"
        },
        "currency": {
          "type": "string",
          "const": "USD"
        },
        "unitAmount": {
          "type": "integer",
          "minimum": 0,
          "description": "USD cents"
        },
        "credits": {
          "type": "number",
          "minimum": 0,
          "multipleOf": 0.001,
          "description": "Credits granted by a successful one-time top-up; zero for recurring prices."
        },
        "type": {
          "type": "string",
          "enum": [
            "recurring",
            "one_time"
          ]
        },
        "interval": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "month",
            "year",
            null
          ]
        }
      }
    },
    "PlanUsagePrices": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "googlePer1kCents",
        "youtubePer1kCents",
        "downloadPerTbCents"
      ],
      "properties": {
        "googlePer1kCents": {
          "type": "integer",
          "minimum": 0,
          "description": "Google request price per 1,000 successful requests, in USD cents."
        },
        "youtubePer1kCents": {
          "type": "integer",
          "minimum": 0,
          "description": "Standard YouTube request price per 1,000 successful requests, in USD cents."
        },
        "downloadPerTbCents": {
          "type": "integer",
          "minimum": 0,
          "description": "Download price per decimal TB (1,000,000,000,000 bytes), in USD cents."
        }
      }
    }
  }
}