{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/withhuman-ai/json-schema/withhuman-ai-apikey-schema.json",
  "title": "APIKey",
  "description": "An API key without its secret. Personal prefixes start with `whk_`; organization prefixes start with `who_`.",
  "x-generated": "2026-11-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/withhuman-ai-openapi.yaml#/components/schemas/APIKey",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "grants",
    "usable",
    "id",
    "prefix",
    "kind",
    "name",
    "permissions",
    "assurance_at_issue",
    "status",
    "created_at",
    "expires_at",
    "last_used_at",
    "revoked_at"
  ],
  "properties": {
    "grants": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Grant"
      },
      "description": "Current organization-key grants projected from RBAC permission policies. Empty for personal keys."
    },
    "effective_grants": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Grant"
      },
      "description": "On detail responses, currently allowed organization-key grants."
    },
    "usable": {
      "type": "boolean",
      "description": "Whether the key is active and not blocked by organization policy or status."
    },
    "blocked_reason": {
      "type": "string",
      "enum": [
        "organization_inactive",
        "api_keys_disabled"
      ]
    },
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "prefix": {
      "type": "string"
    },
    "kind": {
      "type": "string",
      "enum": [
        "personal",
        "organization"
      ],
      "description": "Personal keys act as a member; organization keys act as themselves."
    },
    "membership_id": {
      "type": "string",
      "format": "uuid",
      "description": "The member a personal key acts as."
    },
    "created_by": {
      "type": "object",
      "additionalProperties": false,
      "description": "Who minted it. Present on the organization-wide list.",
      "required": [
        "membership_id",
        "display_name",
        "email"
      ],
      "properties": {
        "membership_id": {
          "type": "string",
          "format": "uuid"
        },
        "display_name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        }
      }
    },
    "name": {
      "type": "string"
    },
    "permissions": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "The narrowing list, or `null` when the key inherits everything its member holds. The key's effective permissions are always this list intersected with the member's current grants."
    },
    "assurance_at_issue": {
      "type": "string",
      "description": "The assurance of the session that minted the key (`strong`, `single_factor`), presented as the key's own when it decides."
    },
    "oauth_client": {
      "type": "object",
      "additionalProperties": false,
      "description": "The MCP client the key was minted for through the consent page. Absent for a key made by hand.",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "status": {
      "type": "string",
      "enum": [
        "active",
        "expired",
        "revoked"
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "expires_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "`null` when the key lives until revoked."
    },
    "last_used_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "revoked_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "revocation_reason": {
      "type": "string",
      "enum": [
        "manual",
        "membership_deprovisioned"
      ]
    }
  },
  "$defs": {
    "Grant": {
      "type": "object",
      "required": [
        "permission",
        "scope_kind"
      ],
      "properties": {
        "permission": {
          "type": "string",
          "description": "A registry key such as request.decide"
        },
        "scope_kind": {
          "type": "string",
          "enum": [
            "organization",
            "team",
            "agent",
            "pipeline"
          ]
        },
        "scope_id": {
          "type": "string",
          "description": "The team id, agent slug, or pipeline key the grant applies to; absent at organization scope"
        }
      }
    }
  }
}