{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tellers-ai/json-schema/tellers-ai-api-token-spend-schema.json",
  "title": "ApiTokenSpend",
  "x-generated": "2026-11-26",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tellers-ai-openapi.json#/components/schemas/ApiTokenSpend",
  "properties": {
    "start": {
      "type": "string",
      "format": "date-time",
      "title": "Start",
      "description": "Start of the period (inclusive, UTC)."
    },
    "end": {
      "type": "string",
      "format": "date-time",
      "title": "End",
      "description": "End of the period (exclusive, UTC)."
    },
    "granularity": {
      "type": "string",
      "enum": [
        "day",
        "week",
        "month"
      ],
      "title": "Granularity"
    },
    "timezone": {
      "type": "string",
      "title": "Timezone"
    },
    "total": {
      "type": "number",
      "title": "Total",
      "description": "Net tokens spent: `spent - refunded`."
    },
    "spent": {
      "type": "number",
      "title": "Spent",
      "description": "Tokens charged."
    },
    "refunded": {
      "type": "number",
      "title": "Refunded",
      "description": "Tokens given back."
    },
    "series": {
      "items": {
        "$ref": "#/$defs/ApiTokenSpendBucket"
      },
      "type": "array",
      "title": "Series",
      "description": "Every bucket of the period, oldest first, zeros included."
    },
    "by_category": {
      "items": {
        "$ref": "#/$defs/ApiTokenSpendGroup"
      },
      "type": "array",
      "title": "By Category",
      "description": "Net spend per category, largest first."
    },
    "by_source": {
      "items": {
        "$ref": "#/$defs/ApiTokenSpendGroup"
      },
      "type": "array",
      "title": "By Source",
      "description": "Net spend per category and source, largest first."
    },
    "items": {
      "items": {
        "$ref": "#/$defs/ApiTokenSpendItem"
      },
      "type": "array",
      "title": "Items",
      "description": "One page of individual charges and refunds, newest first. Only charges since `itemised_since` are listed; older ones still count in the totals, series and breakdowns."
    },
    "item_count": {
      "type": "integer",
      "title": "Item Count",
      "description": "How many listed charges and refunds match, across all pages."
    },
    "itemised_since": {
      "type": "string",
      "format": "date-time",
      "title": "Itemised Since",
      "description": "Charges before this time (UTC) are no longer listed in `items`; they still count in the totals, summed per hour."
    },
    "hourly_since": {
      "type": "string",
      "format": "date-time",
      "title": "Hourly Since",
      "description": "Spend before this time (UTC) is only known per UTC day, so a series cut in another timezone places it on the day its UTC day starts in."
    },
    "daily_since": {
      "type": "string",
      "format": "date-time",
      "title": "Daily Since",
      "description": "Spend before this time (UTC) is only known per UTC month, and counts on the first of its month."
    }
  },
  "type": "object",
  "required": [
    "start",
    "end",
    "granularity",
    "timezone",
    "total",
    "spent",
    "refunded",
    "series",
    "by_category",
    "by_source",
    "items",
    "item_count",
    "itemised_since",
    "hourly_since",
    "daily_since"
  ],
  "$defs": {
    "ApiTokenSpendBucket": {
      "properties": {
        "period_start": {
          "type": "string",
          "format": "date-time",
          "title": "Period Start",
          "description": "Start of the day, week (Monday) or month, in the requested timezone."
        },
        "total": {
          "type": "number",
          "title": "Total",
          "description": "Net tokens spent in the bucket."
        }
      },
      "type": "object",
      "required": [
        "period_start",
        "total"
      ],
      "title": "ApiTokenSpendBucket"
    },
    "ApiTokenSpendGroup": {
      "properties": {
        "category": {
          "$ref": "#/$defs/TokenSpendCategory"
        },
        "source": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Source",
          "description": "The tool for `tool`, the model for `assistant`, a sub-kind otherwise (`upload`, `downscale`, an export resolution). Null in `by_category`."
        },
        "source_display_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Source Display Name",
          "description": "Human-readable tool name, for `tool` rows."
        },
        "total": {
          "type": "number",
          "title": "Total",
          "description": "Net tokens spent."
        }
      },
      "type": "object",
      "required": [
        "category",
        "total"
      ],
      "title": "ApiTokenSpendGroup"
    },
    "ApiTokenSpendItem": {
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid",
          "title": "Id"
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "title": "Created At",
          "description": "When it was charged (UTC)."
        },
        "amount": {
          "type": "number",
          "title": "Amount",
          "description": "Tokens charged; negative for a refund of an earlier charge."
        },
        "category": {
          "$ref": "#/$defs/TokenSpendCategory"
        },
        "source": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Source"
        },
        "source_display_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Source Display Name"
        },
        "chat_id": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ],
          "title": "Chat Id"
        },
        "project_id": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ],
          "title": "Project Id"
        },
        "asset_id": {
          "anyOf": [
            {
              "type": "string",
              "format": "uuid"
            },
            {
              "type": "null"
            }
          ],
          "title": "Asset Id"
        }
      },
      "type": "object",
      "required": [
        "id",
        "created_at",
        "amount",
        "category",
        "source",
        "source_display_name",
        "chat_id",
        "project_id",
        "asset_id"
      ],
      "title": "ApiTokenSpendItem"
    },
    "TokenSpendCategory": {
      "type": "string",
      "enum": [
        "assistant",
        "tool",
        "asset_processing",
        "transcription",
        "export"
      ],
      "title": "TokenSpendCategory",
      "description": "What a charge of Tellers tokens paid for, as the user sees it."
    }
  }
}