{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/casama-ai/json-schema/casama-ai-billing-summary-schema.json",
  "title": "BillingSummary",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/casama-ai-openapi.json#/components/schemas/BillingSummary",
  "type": "object",
  "properties": {
    "enabled": {
      "type": "boolean",
      "description": "False on self-hosted servers: no paywall"
    },
    "plan_code": {
      "type": "string"
    },
    "plan_name": {
      "type": "string"
    },
    "interval": {
      "type": "string"
    },
    "limits": {
      "type": "object",
      "additionalProperties": {
        "type": "number"
      }
    },
    "unlimited": {
      "type": "boolean"
    },
    "valid_until": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "source": {
      "type": "string",
      "enum": [
        "default",
        "dodo",
        "app_store",
        "google_play"
      ]
    },
    "cancel_at_period_end": {
      "type": "boolean"
    },
    "extra_seats": {
      "type": "integer",
      "description": "People paid for beyond the plan's seats (D-249)"
    },
    "trial_available": {
      "type": "boolean",
      "description": "The owner can still start a plan's free trial (D-249)"
    },
    "resets": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/SavedLimitReset"
      }
    },
    "credits_usd": {
      "type": "number"
    },
    "daily": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "used_usd": {
          "type": "number",
          "description": "Spent today (UTC) on the server's keys"
        },
        "cap_usd": {
          "type": "number",
          "description": "The plan's daily cap on the server's keys"
        },
        "resets_at": {
          "type": "string",
          "format": "date-time",
          "description": "Next midnight UTC, when the day's spend resets"
        }
      },
      "required": [
        "used_usd",
        "cap_usd",
        "resets_at"
      ],
      "description": "Today's spend against the plan's daily cap; runs stop when it is reached (D-311). Null when no cap applies"
    },
    "computer_hours": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "used_hours": {
          "type": "number",
          "description": "Hosted computer hours used this month (UTC)"
        },
        "limit_hours": {
          "type": "number",
          "description": "The plan's computer hours a month"
        },
        "resets_at": {
          "type": "string",
          "format": "date-time",
          "description": "The first of next month (UTC), when the hours reset"
        }
      },
      "required": [
        "used_hours",
        "limit_hours",
        "resets_at"
      ],
      "description": "This month's hosted computer hours against the plan's. Past them only computers stop; chat keeps running on credits (D-442). Null when no limit applies"
    },
    "sandbox": {
      "type": "boolean",
      "description": "The plan was bought with a store test account (TestFlight, App Review, Play license testers): it has tester limits (docs/SANDBOX-LIMITS-PLAN.md)"
    },
    "comp": {
      "type": [
        "object",
        "null"
      ],
      "properties": {
        "plan_code": {
          "type": "string"
        },
        "ends_at": {
          "type": "string",
          "format": "date-time"
        },
        "from": {
          "type": "string",
          "enum": [
            "grant",
            "code"
          ]
        },
        "keep_from": {
          "type": "string",
          "format": "date-time",
          "description": "From this moment the comped plan can be bought to keep it"
        }
      },
      "required": [
        "plan_code",
        "ends_at",
        "from",
        "keep_from"
      ],
      "description": "A plan given free by Casama, while it runs (docs/COMP-PLANS-PLAN.md). `source` then says default, for older apps"
    },
    "casama_models": {
      "type": "string",
      "enum": [
        "on",
        "off"
      ],
      "description": "Whether Casama's own model keys are available on this workspace's plan (docs/OWN-KEYS-PLAN.md §6)"
    },
    "casama_models_note": {
      "type": [
        "string",
        "null"
      ],
      "description": "Optional note from the instance owner when Casama's models are turned off (§3.3)"
    },
    "subscriptions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Subscription"
      }
    },
    "providers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/BillingSource"
      }
    }
  },
  "required": [
    "enabled",
    "plan_code",
    "plan_name",
    "interval",
    "limits",
    "unlimited",
    "valid_until",
    "source",
    "cancel_at_period_end",
    "credits_usd",
    "subscriptions",
    "providers"
  ],
  "$defs": {
    "BillingSource": {
      "type": "string",
      "enum": [
        "dodo",
        "app_store",
        "google_play"
      ]
    },
    "SavedLimitReset": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "campaign_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid"
        },
        "message": {
          "type": "string"
        },
        "expires_at": {
          "type": "string",
          "format": "date-time"
        },
        "refill_usd": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000000
        },
        "reset_daily": {
          "type": "boolean"
        },
        "reset_computer": {
          "type": "boolean"
        },
        "can_use": {
          "type": "boolean"
        },
        "unavailable_reason": {
          "type": [
            "string",
            "null"
          ],
          "description": "Why it can't be used now: owner_required, paused, period_limit, budget, nothing_to_refill or no_billing_period; null when it can"
        }
      },
      "required": [
        "id",
        "campaign_id",
        "message",
        "expires_at",
        "refill_usd",
        "reset_daily",
        "reset_computer",
        "can_use",
        "unavailable_reason"
      ]
    },
    "Subscription": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "source": {
          "$ref": "#/$defs/BillingSource"
        },
        "plan_code": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "current_period_end": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "cancel_at_period_end": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "source",
        "plan_code",
        "status",
        "current_period_end",
        "cancel_at_period_end"
      ]
    }
  }
}