{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/mumo-chat/json-schema/mumo-chat-credit-wallet-schema.json",
  "title": "CreditWallet",
  "x-generated": "2026-11-18",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/mumo-chat-openapi.yml#/components/schemas/CreditWallet",
  "type": "object",
  "required": [
    "effective_balance_usd",
    "buckets",
    "per_model_minimum_usd_default",
    "debit_order"
  ],
  "properties": {
    "effective_balance_usd": {
      "type": "number",
      "description": "Sum across all three buckets, markup-included. Zero or negative is `credit_exhausted`; above zero, each write additionally needs the balance to cover that request's round minimum."
    },
    "buckets": {
      "type": "object",
      "required": [
        "free",
        "subscription",
        "refill"
      ],
      "properties": {
        "free": {
          "type": "object",
          "description": "Monthly free-tier credit.",
          "required": [
            "balance_usd",
            "monthly_grant_usd",
            "resets_at"
          ],
          "properties": {
            "balance_usd": {
              "type": "number"
            },
            "monthly_grant_usd": {
              "type": "number",
              "description": "The platform grant each cycle."
            },
            "resets_at": {
              "type": "string",
              "description": "Next UTC 1st-of-month boundary when the bucket refills."
            }
          }
        },
        "subscription": {
          "type": "object",
          "description": "Paid-tier credit.",
          "required": [
            "balance_usd",
            "rollover_cap_usd",
            "subscription_status"
          ],
          "properties": {
            "balance_usd": {
              "type": "number"
            },
            "rollover_cap_usd": {
              "type": "number",
              "description": "Max unused balance that carries into a new cycle."
            },
            "subscription_status": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "active",
                "past_due",
                "cancelled",
                "expired",
                null
              ],
              "description": "Null means no subscription."
            }
          }
        },
        "refill": {
          "type": "object",
          "description": "Auto-refill top-ups. The two threshold fields appear only when auto-refill is enabled.",
          "required": [
            "balance_usd",
            "auto_refill_enabled"
          ],
          "properties": {
            "balance_usd": {
              "type": "number"
            },
            "auto_refill_enabled": {
              "type": "boolean"
            },
            "auto_refill_threshold_usd": {
              "type": "number",
              "description": "Trigger level. Absent when auto-refill is off."
            },
            "auto_refill_amount_usd": {
              "type": "number",
              "description": "Top-up size. Absent when auto-refill is off."
            }
          }
        }
      }
    },
    "per_model_minimum_usd_default": {
      "type": "number",
      "description": "Platform fallback minimum used when a model's registry row has no explicit minimum. Reported for reference; it does not gate admission."
    },
    "debit_order": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "FIFO debit sequence. Settlement drains each bucket in this order."
    }
  }
}