{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/domani-run/json-schema/domani-run-token-info-schema.json",
  "title": "TokenInfo",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/domani-run-api-tokens-api-openapi.yml#/components/schemas/TokenInfo",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique token identifier (use this for DELETE)"
    },
    "name": {
      "type": "string",
      "description": "Human-readable token label"
    },
    "key": {
      "type": "string",
      "description": "Masked API key (full key shown only on creation)"
    },
    "lastUsed": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Approximate recorded last use (one-minute granularity)"
    },
    "expiresAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When this token expires (null = never)"
    },
    "expired": {
      "type": "boolean",
      "description": "Whether this token has expired"
    },
    "scopes": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Permission scopes granted to this token. ['*'] means full access."
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "max_per_tx": {
      "type": [
        "number",
        "null"
      ],
      "description": "Per-transaction spend cap in USD (null = uncapped)"
    },
    "max_per_month": {
      "type": [
        "number",
        "null"
      ],
      "description": "Rolling monthly spend cap in USD (null = uncapped)"
    },
    "spent_this_month": {
      "type": "number",
      "description": "USD spent against the monthly cap this calendar month"
    },
    "parent_token_id": {
      "type": [
        "string",
        "null"
      ],
      "description": "Id of the token that minted this one (null = created via dashboard/session)"
    },
    "mailbox_ids": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Mailbox ids this token is confined to. Empty means no mailbox-id confinement."
    },
    "http_route_policy": {
      "$ref": "#/$defs/HttpRoutePolicy"
    },
    "agent_identity": {
      "type": [
        "object",
        "null"
      ],
      "description": "Agent identity represented by this token. Its mail actions are attributed to this agent.",
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "slug": {
          "type": "string"
        }
      }
    }
  },
  "required": [
    "id",
    "name",
    "key",
    "scopes",
    "mailbox_ids",
    "http_route_policy",
    "createdAt"
  ],
  "$defs": {
    "HttpRoutePolicy": {
      "type": [
        "object",
        "null"
      ],
      "description": "Structured hostname, concurrency, and lease authority for a least-privilege HTTP route token.",
      "required": [
        "hostname_rules",
        "max_concurrent",
        "max_lease_seconds"
      ],
      "properties": {
        "hostname_rules": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "oneOf": [
              {
                "type": "object",
                "required": [
                  "domain",
                  "kind",
                  "hostname"
                ],
                "properties": {
                  "domain": {
                    "type": "string"
                  },
                  "kind": {
                    "const": "exact"
                  },
                  "hostname": {
                    "type": "string"
                  }
                }
              },
              {
                "type": "object",
                "required": [
                  "domain",
                  "kind",
                  "prefix"
                ],
                "properties": {
                  "domain": {
                    "type": "string"
                  },
                  "kind": {
                    "const": "subdomain_prefix"
                  },
                  "prefix": {
                    "type": "string"
                  }
                }
              }
            ]
          }
        },
        "max_concurrent": {
          "type": "integer",
          "minimum": 1,
          "maximum": 20
        },
        "max_lease_seconds": {
          "type": "integer",
          "minimum": 60,
          "maximum": 86400
        }
      }
    }
  }
}