{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/letsship-ai/json-schema/letsship-ai-billing-summary-schema.json",
  "title": "BillingSummary",
  "x-generated": "2026-11-15",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/letsship-ai-openapi.json#/components/schemas/BillingSummary",
  "type": "object",
  "properties": {
    "orgId": {
      "type": "string"
    },
    "plan": {
      "$ref": "#/$defs/BillingPlan"
    },
    "cohort": {
      "anyOf": [
        {
          "$ref": "#/$defs/BillingCohort"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "mode": {
      "$ref": "#/$defs/BillingMode"
    },
    "balance": {
      "type": "integer",
      "minimum": 0
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/CreditSource"
      }
    },
    "low": {
      "type": "boolean"
    },
    "canStartMission": {
      "type": "boolean"
    },
    "canManage": {
      "type": "boolean"
    },
    "coveredByShip": {
      "type": "boolean"
    },
    "missionCeiling": {
      "type": "integer",
      "exclusiveMinimum": 0
    },
    "sandboxLimit": {
      "anyOf": [
        {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "projects": {
      "type": "object",
      "properties": {
        "used": {
          "type": "integer",
          "minimum": 0
        },
        "limit": {
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "used",
        "limit"
      ]
    },
    "trackerTriggers": {
      "$ref": "#/$defs/TrackerTriggerPolicy"
    },
    "usage": {
      "$ref": "#/$defs/BillingUsage"
    },
    "openCreditRequest": {
      "anyOf": [
        {
          "$ref": "#/$defs/CreditRequestSummary"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "creditRequestsGoTo": {
      "$ref": "#/$defs/CreditRequestRecipient"
    },
    "purchase": {
      "$ref": "#/$defs/BillingPurchaseState"
    },
    "subscription": {
      "anyOf": [
        {
          "$ref": "#/$defs/TeamSubscription"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "advice": {
      "anyOf": [
        {
          "$ref": "#/$defs/PlanAdvice"
        },
        {
          "type": "null"
        },
        {
          "type": "null"
        }
      ]
    },
    "trial": {
      "$ref": "#/$defs/BillingTrialState"
    },
    "onFounderPath": {
      "type": "boolean"
    }
  },
  "required": [
    "orgId",
    "plan",
    "cohort",
    "mode",
    "balance",
    "sources",
    "low",
    "canStartMission",
    "canManage",
    "coveredByShip",
    "missionCeiling",
    "sandboxLimit",
    "projects",
    "trackerTriggers",
    "usage",
    "openCreditRequest",
    "creditRequestsGoTo",
    "purchase",
    "subscription",
    "advice",
    "trial"
  ],
  "$defs": {
    "BillingCohort": {
      "type": "string",
      "enum": [
        "friend",
        "design-partner",
        "enterprise-trial",
        "investor",
        "internal"
      ]
    },
    "BillingMode": {
      "type": "string",
      "enum": [
        "enforce",
        "shadow",
        "off"
      ]
    },
    "BillingPlan": {
      "type": "string",
      "enum": [
        "trial",
        "sponsored",
        "team",
        "enterprise"
      ]
    },
    "BillingPurchaseState": {
      "type": "object",
      "properties": {
        "available": {
          "type": "boolean"
        },
        "reason": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "checkout_closed",
                "plan_not_purchasable",
                "billing_manage_required"
              ]
            },
            {
              "type": "null"
            },
            {
              "type": "null"
            }
          ]
        },
        "credits": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "packs",
                "team_credits"
              ]
            },
            {
              "type": "null"
            },
            {
              "type": "null"
            }
          ]
        },
        "team": {
          "type": "boolean"
        }
      },
      "required": [
        "available",
        "reason",
        "credits",
        "team"
      ]
    },
    "BillingTrialState": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "not_applicable",
            "awaiting_repository",
            "granted",
            "not_eligible"
          ]
        },
        "reason": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "invited",
                "identity_used"
              ]
            },
            {
              "type": "null"
            },
            {
              "type": "null"
            }
          ]
        },
        "credits": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "status",
        "reason",
        "credits"
      ]
    },
    "BillingUsage": {
      "type": "object",
      "properties": {
        "periodDays": {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        "credits": {
          "type": "integer",
          "minimum": 0
        },
        "missions": {
          "type": "integer",
          "minimum": 0,
          "description": "Missions the org started in the window, each counted once however many times it restarted. Always 0 while billing is off for the org (`mode` `off`), which meters no mission."
        },
        "valueUsd": {
          "type": "number",
          "minimum": 0
        },
        "perCreditUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "basis": {
          "type": "string",
          "enum": [
            "packs",
            "team",
            "purchases"
          ],
          "description": "The price `perCreditUsd` is: `team`, the org's plan rate; `purchases`, what the org paid per credit; `packs`, the lowest per-credit pack price (the org bought nothing)."
        },
        "estimate": {
          "type": "boolean",
          "enum": [
            true
          ]
        }
      },
      "required": [
        "periodDays",
        "credits",
        "missions",
        "valueUsd",
        "perCreditUsd",
        "basis",
        "estimate"
      ]
    },
    "CreditRequestRecipient": {
      "type": "string",
      "enum": [
        "founder",
        "billing_contacts"
      ]
    },
    "CreditRequestSummary": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "createdAt": {
          "type": "integer"
        },
        "messageCount": {
          "type": "integer",
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "id",
        "createdAt",
        "messageCount"
      ]
    },
    "CreditSource": {
      "type": "object",
      "properties": {
        "kind": {
          "$ref": "#/$defs/CreditSourceKind"
        },
        "remaining": {
          "type": "integer",
          "minimum": 0
        },
        "expiresAt": {
          "type": [
            "integer",
            "null"
          ]
        }
      },
      "required": [
        "kind",
        "remaining",
        "expiresAt"
      ]
    },
    "CreditSourceKind": {
      "type": "string",
      "enum": [
        "trial",
        "sponsored",
        "plan",
        "contract",
        "purchase"
      ]
    },
    "PlanAdvice": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "start",
            "switch"
          ]
        },
        "plan": {
          "$ref": "#/$defs/TeamPlanId"
        },
        "name": {
          "type": "string"
        },
        "priceUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "agentsAtOnce": {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        "periodDays": {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        "credits": {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        "currentCostUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "planCostUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "savingsUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "kind",
        "plan",
        "name",
        "priceUsd",
        "agentsAtOnce",
        "periodDays",
        "credits",
        "currentCostUsd",
        "planCostUsd",
        "savingsUsd"
      ]
    },
    "SubscribedPlan": {
      "type": "object",
      "properties": {
        "plan": {
          "$ref": "#/$defs/TeamPlanId"
        },
        "name": {
          "type": "string"
        },
        "priceUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "creditsPerMonth": {
          "type": "integer",
          "exclusiveMinimum": 0
        },
        "perCreditUsd": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "agentsAtOnce": {
          "type": "integer",
          "exclusiveMinimum": 0
        }
      },
      "required": [
        "plan",
        "name",
        "priceUsd",
        "creditsPerMonth",
        "perCreditUsd",
        "agentsAtOnce"
      ]
    },
    "TeamPlanId": {
      "type": "string",
      "enum": [
        "starter",
        "scale"
      ]
    },
    "TeamSubscription": {
      "allOf": [
        {
          "$ref": "#/$defs/SubscribedPlan"
        },
        {
          "type": "object",
          "properties": {
            "status": {
              "$ref": "#/$defs/TeamSubscriptionStatus"
            },
            "nextPlan": {
              "anyOf": [
                {
                  "$ref": "#/$defs/SubscribedPlan"
                },
                {
                  "type": "null"
                },
                {
                  "type": "null"
                }
              ]
            },
            "currentPeriodEnd": {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "null"
                },
                {
                  "type": "null"
                }
              ]
            },
            "cancelAtPeriodEnd": {
              "type": "boolean"
            }
          },
          "required": [
            "status",
            "nextPlan",
            "currentPeriodEnd",
            "cancelAtPeriodEnd"
          ]
        }
      ]
    },
    "TeamSubscriptionStatus": {
      "type": "string",
      "enum": [
        "incomplete",
        "active",
        "past_due",
        "canceled"
      ]
    },
    "TrackerTriggerPolicy": {
      "type": "string",
      "enum": [
        "anyone",
        "linked_members"
      ]
    }
  }
}