{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/nopaque-co-uk/json-schema/nopaque-co-uk-v2-balance-response-schema.json",
  "title": "V2BalanceResponse",
  "description": "Response for `GET /workspaces/{workspaceId}/billing/v2/balance`. Three\ndistinct branches share this one field set, distinguished by\n`provisioned` and `metronomeProvisioning`:\n\n- **Provisioned** (`provisioned: true`): a real balance read from\n  Metronome. `metronomeCurrentPlan` is present ONLY on this branch.\n- **Not yet provisioned** (`provisioned: false`, no customer id): all\n  ids `null`, `totalCents`/`purchasedCreditCents` are `0`, `segments`\n  is `[]`. `metronomeCurrentPlan` is absent.\n- **Provisioning retry failed** (`provisioned: false`,\n  `metronomeProvisioning: 'pending'`): a lazy provisioning retry was\n  attempted and failed. Deliberately a 200 with zeros rather than a\n  500 — the frontend renders this as a server-driven pending state.\n",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/nopaque-co-uk-billing-api-openapi.yml#/components/schemas/V2BalanceResponse",
  "type": "object",
  "required": [
    "provisioned",
    "metronomeCustomerId",
    "metronomeContractId",
    "metronomeWstartedAt",
    "subscriptionStatus",
    "consumptionEnabled",
    "totalCents",
    "purchasedCreditCents",
    "segments"
  ],
  "properties": {
    "provisioned": {
      "type": "boolean"
    },
    "metronomeProvisioning": {
      "type": [
        "string",
        "null"
      ],
      "description": "Server-driven provisioning state flag. `'pending'` on the retry-failed branch; otherwise `null` or absent."
    },
    "metronomeCustomerId": {
      "type": [
        "string",
        "null"
      ]
    },
    "metronomeContractId": {
      "type": [
        "string",
        "null"
      ]
    },
    "metronomeCurrentPlan": {
      "type": "string",
      "description": "Present ONLY on the provisioned branch. Includes `beta` as a real\nruntime value — the raw DDB passthrough. Excluding `beta` from\nthis enum's handling once let beta workspaces fall through tier\ngates, so treat it as a genuine value, not an oversight.\n",
      "enum": [
        "free",
        "starter",
        "team",
        "enterprise",
        "beta"
      ]
    },
    "metronomeWstartedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "subscriptionStatus": {
      "type": "string",
      "description": "Defaults to `'none'` when unset on the workspace record."
    },
    "consumptionEnabled": {
      "type": [
        "boolean",
        "null"
      ]
    },
    "totalCents": {
      "type": "integer"
    },
    "purchasedCreditCents": {
      "type": "integer",
      "description": "Sum of `pack`-category segments only — excludes the license fee and the free allocation."
    },
    "segments": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/V2BalanceSegment"
      }
    }
  },
  "$defs": {
    "V2BalanceSegment": {
      "type": "object",
      "description": "One balance segment (e.g. a free allocation, a license grant, or a purchased pack).",
      "required": [
        "type",
        "name",
        "balanceCents",
        "category"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Metronome credit-type identifier for this segment."
        },
        "name": {
          "type": "string"
        },
        "balanceCents": {
          "type": "integer",
          "description": "Remaining drawable balance in cents. 0 means fully spent."
        },
        "category": {
          "type": "string",
          "description": "Segment category. `purchasedCreditCents` on the parent response\nsums only `pack` segments — `license` and `free` are excluded.\n",
          "enum": [
            "free",
            "license",
            "pack"
          ]
        }
      }
    }
  }
}