{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/placestack-com/json-schema/placestack-com-credit-view-schema.json",
  "title": "CreditView",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/placestack-com-usage-api-openapi.yml#/components/schemas/CreditView",
  "properties": {
    "object": {
      "type": "string",
      "const": "credit_balance",
      "title": "Object",
      "description": "The object's type. Always `credit_balance`.",
      "default": "credit_balance"
    },
    "organization_id": {
      "type": "string",
      "title": "Organization Id",
      "description": "The organization's id."
    },
    "balance": {
      "type": "integer",
      "title": "Balance",
      "description": "The current credit balance."
    },
    "included_credits": {
      "type": "integer",
      "title": "Included Credits",
      "description": "Credits included with the plan each billing period. `0` without a plan."
    },
    "grants": {
      "items": {
        "$ref": "#/$defs/CreditGrant"
      },
      "type": "array",
      "title": "Grants",
      "description": "Grants with credits left to spend, in the order they are spent."
    },
    "ledger": {
      "items": {
        "$ref": "#/$defs/LedgerEntry"
      },
      "type": "array",
      "title": "Ledger",
      "description": "The most recent credits granted, purchased, expired or adjusted, newest first, up to `limit`. Credits spent on requests are in `/usage`."
    }
  },
  "type": "object",
  "required": [
    "object",
    "organization_id",
    "balance",
    "included_credits",
    "grants",
    "ledger"
  ],
  "$defs": {
    "CreditGrant": {
      "properties": {
        "object": {
          "type": "string",
          "const": "credit_grant",
          "title": "Object",
          "description": "The object's type. Always `credit_grant`.",
          "default": "credit_grant"
        },
        "id": {
          "type": "string",
          "title": "Id",
          "description": "Unique identifier for the object."
        },
        "amount": {
          "type": "integer",
          "title": "Amount",
          "description": "Credits granted."
        },
        "remaining": {
          "type": "integer",
          "title": "Remaining",
          "description": "Credits of the grant not yet spent."
        },
        "category": {
          "type": "string",
          "enum": [
            "paid",
            "promotional"
          ],
          "title": "Category",
          "description": "One of `paid` (a plan's period or a purchase) or `promotional` (signup or an adjustment)."
        },
        "source": {
          "type": "string",
          "enum": [
            "signup",
            "subscription",
            "purchase",
            "adjustment"
          ],
          "title": "Source",
          "description": "One of `signup`, `subscription` (a plan's period), `purchase` or `adjustment`."
        },
        "priority": {
          "type": "integer",
          "title": "Priority",
          "description": "Order of spending. Lower is spent first."
        },
        "effective_at": {
          "type": "string",
          "format": "date-time",
          "title": "Effective At",
          "description": "Time from which the credits can be spent."
        },
        "expires_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "title": "Expires At",
          "description": "Time at which what is left lapses. Null if it does not."
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "title": "Created At",
          "description": "Time at which the object was created."
        }
      },
      "type": "object",
      "required": [
        "object",
        "id",
        "amount",
        "remaining",
        "category",
        "source",
        "priority",
        "effective_at",
        "expires_at",
        "created_at"
      ],
      "title": "CreditGrant",
      "description": "Credits granted at once, spent in order of `priority`, then soonest `expires_at`."
    },
    "LedgerEntry": {
      "properties": {
        "delta": {
          "type": "integer",
          "title": "Delta",
          "description": "Credits added, as a positive number, or spent, as a negative one."
        },
        "grant": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Grant",
          "description": "The credit grant the credits were added to or taken from."
        },
        "reason": {
          "type": "string",
          "title": "Reason",
          "description": "One of `signup`, `subscription`, `purchase`, `expiry` or `adjustment`."
        },
        "reference": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Reference",
          "description": "The billing event's id for `purchase`, `subscription` and `expiry`. Null otherwise."
        },
        "balance_after": {
          "type": "integer",
          "title": "Balance After",
          "description": "The credit balance after this entry."
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "title": "Created At",
          "description": "Time at which the object was created."
        }
      },
      "type": "object",
      "required": [
        "delta",
        "reason",
        "balance_after",
        "created_at"
      ],
      "title": "LedgerEntry"
    }
  }
}