{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/aidelly-ai/json-schema/aidelly-ai-ai-credit-balance-envelope-schema.json",
  "title": "AiCreditBalanceEnvelope",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/aidelly-ai-usage-api-openapi.yml#/components/schemas/AiCreditBalanceEnvelope",
  "allOf": [
    {
      "$ref": "#/$defs/EnvelopeBase"
    },
    {
      "type": "object",
      "properties": {
        "success": {
          "const": true
        },
        "data": {
          "type": "object",
          "properties": {
            "balance": {
              "$ref": "#/$defs/AiCreditBalance"
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "AiCreditBalance": {
      "type": "object",
      "required": [
        "enforced",
        "balance",
        "plan_credits",
        "plan_id",
        "billing_cycle",
        "payg_enabled",
        "payg_rate_usd_per_credit"
      ],
      "properties": {
        "enforced": {
          "type": "boolean",
          "description": "Whether credit enforcement is active for this workspace."
        },
        "workspace_id": {
          "type": [
            "string",
            "null"
          ],
          "format": "uuid",
          "description": "Workspace ID."
        },
        "balance": {
          "type": "integer",
          "description": "Total spendable credits (trial + included + purchased)."
        },
        "plan_credits": {
          "type": "integer",
          "description": "Monthly included credits from the plan (0 if trialing)."
        },
        "plan_id": {
          "type": "string",
          "description": "Current plan tier (free, launch, scale, agency)."
        },
        "billing_cycle": {
          "type": "string",
          "description": "Billing cycle (monthly, annual)."
        },
        "status": {
          "type": [
            "string",
            "null"
          ],
          "description": "Account status."
        },
        "trial_ends_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "ISO 8601 timestamp when trial ends (null if not trialing)."
        },
        "is_trialing": {
          "type": "boolean",
          "description": "True if the account is currently in trial."
        },
        "is_expired_trial": {
          "type": "boolean",
          "description": "True if the trial has expired."
        },
        "is_plan_active": {
          "type": "boolean",
          "description": "True if the plan is active and not past due."
        },
        "payg_enabled": {
          "type": "boolean",
          "description": "True if pay-as-you-go (overage) is enabled."
        },
        "payg_rate_usd_per_credit": {
          "type": "number",
          "format": "double",
          "description": "USD cost per credit for overage charges."
        },
        "overage_metered_this_month": {
          "type": "integer",
          "description": "PAYG credits metered (charged) this month."
        },
        "stripe_customer_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Stripe customer ID."
        },
        "stripe_subscription_id": {
          "type": [
            "string",
            "null"
          ],
          "description": "Stripe subscription ID (for PAYG, not base plan)."
        },
        "trial_balance": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Spendable trial grant credits."
        },
        "included_balance": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Spendable included (plan) credits for current month."
        },
        "purchased_balance": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Spendable purchased add-on credits."
        },
        "purchased_total": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Total purchased credits (including spent)."
        },
        "trial_total": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Total trial grant credits (including spent/expired)."
        },
        "included_total": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Total included credits for current month."
        },
        "credit_pool_total": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Total spendable pool at start of period."
        },
        "next_reset_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "ISO 8601 timestamp for next monthly reset (null if no included credits)."
        },
        "ledger_version": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Internal ledger version for debugging."
        }
      }
    },
    "EnvelopeBase": {
      "type": "object",
      "required": [
        "success",
        "request_id"
      ],
      "properties": {
        "success": {
          "type": "boolean"
        },
        "request_id": {
          "type": "string",
          "format": "uuid"
        }
      }
    }
  }
}