{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usewrit-app/json-schema/usewrit-app-api-key-created-schema.json",
  "title": "ApiKeyCreated",
  "description": "The created key record plus the ONE-TIME plaintext `key` — capture it now; it can never be recovered later.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usewrit-app-keys-api-openapi.yml#/components/schemas/ApiKeyCreated",
  "allOf": [
    {
      "$ref": "#/$defs/ApiKey"
    },
    {
      "type": "object",
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "description": "The full plaintext `wlk_…` key (shown exactly once)."
        }
      }
    }
  ],
  "$defs": {
    "ApiKey": {
      "type": "object",
      "description": "One `wlk_` key record. The sha256 `key_hash` is NEVER serialized; the plaintext key exists only in the create response.",
      "required": [
        "id",
        "name",
        "prefix",
        "scopes",
        "enabled",
        "created_at"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        },
        "prefix": {
          "type": "string",
          "description": "`wlk_` + first 6 chars of the raw key (display only)."
        },
        "scopes": {
          "type": "string",
          "description": "CSV of scopes: `read|run|admin`."
        },
        "enabled": {
          "type": "integer",
          "description": "0/1 integer flag."
        },
        "last_used_at": {
          "type": [
            "string",
            "null"
          ]
        },
        "created_at": {
          "type": "string"
        },
        "revoked_at": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}