{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/secondappraisal-com/json-schema/secondappraisal-com-api-key-introspection-schema.json",
  "title": "ApiKeyIntrospection",
  "description": "The API key that made the call: what it is, what it may do, and when it expires. Never the key itself.",
  "x-generated": "2026-11-24",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/secondappraisal-com-openapi.json#/components/schemas/ApiKeyIntrospection",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "The key's id, the one the portal's API page lists it under.",
      "x-data-class": "institution_confidential"
    },
    "object": {
      "type": "string",
      "const": "gap.api_key",
      "x-data-class": "public"
    },
    "prefix": {
      "type": "string",
      "description": "The key's first characters, as the portal shows them: enough to tell your keys apart, never enough to use one. A signed credential's starts `pk:`, then the start of its public key's thumbprint.",
      "x-data-class": "institution_confidential"
    },
    "mode": {
      "type": "string",
      "enum": [
        "live",
        "test"
      ],
      "description": "`live`, or `test` for a sandbox key. New values may be added: treat one you don't recognise as unknown, and don't fail.",
      "x-data-class": "public"
    },
    "format": {
      "type": "string",
      "enum": [
        "legacy",
        "v2"
      ],
      "description": "`v2`: every key (`sa_live_` or `sa_test_`) and signed credential. `legacy`, for an `sa_gap_` key, is no longer sent: the API accepts v2 keys only. New values may be added: treat one you don't recognise as unknown, and don't fail.",
      "x-data-class": "public"
    },
    "auth_method": {
      "type": "string",
      "enum": [
        "secret",
        "public_key"
      ],
      "description": "`secret`: the key is sent as a bearer token. `public_key`: a signed credential, whose requests are signed with its registered public key's private half. New values may be added: treat one you don't recognise as unknown, and don't fail.",
      "x-data-class": "public"
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "referrals:write",
          "referrals:read",
          "referrals.contact:read",
          "reporting:read",
          "plans:read",
          "plans:write",
          "members:activation-link",
          "audit:read"
        ]
      },
      "description": "What the key may do: the permissions chosen when it was created. `referrals.contact:read` and `members:activation-link` are field permissions: they open no operation, and a key without one reads null in each field whose `x-requires-permission` names it, in whatever its operations answer. New values may be added: treat one you don't recognise as unknown, and don't fail.",
      "x-data-class": "institution_confidential"
    },
    "expires_at": {
      "anyOf": [
        {
          "type": "string",
          "format": "date-time"
        },
        {
          "type": "null"
        }
      ],
      "description": "When the key stops working.",
      "x-data-class": "institution_confidential"
    },
    "institution": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "Your institution's id.",
          "x-data-class": "institution_confidential"
        },
        "status": {
          "type": "string",
          "enum": [
            "requested",
            "active",
            "suspended",
            "terminated"
          ],
          "description": "`active`; `requested` before approval; `suspended`, which can read but not write; `terminated`. New values may be added: treat one you don't recognise as unknown, and don't fail.",
          "x-data-class": "public"
        }
      },
      "required": [
        "id",
        "status"
      ]
    },
    "allowed_cidr_count": {
      "type": "integer",
      "minimum": 0,
      "description": "How many address ranges the key's IP allowlist holds; 0 when it has none.",
      "x-data-class": "institution_confidential"
    }
  },
  "required": [
    "id",
    "object",
    "prefix",
    "mode",
    "format",
    "auth_method",
    "permissions",
    "expires_at",
    "institution",
    "allowed_cidr_count"
  ]
}