{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/knoxcall/json-schema/knoxcall-create-api-key-request-schema.json",
  "title": "CreateApiKeyRequest",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/knoxcall-api-keys-api-openapi.yml#/components/schemas/CreateApiKeyRequest",
  "type": "object",
  "required": [
    "name"
  ],
  "properties": {
    "name": {
      "type": "string",
      "description": "Human-readable name to identify this key."
    },
    "rate_limit_requests": {
      "type": "integer",
      "minimum": 1,
      "description": "Maximum requests per rate limit window. Leave empty for no rate limit."
    },
    "rate_limit_window_sec": {
      "type": "integer",
      "minimum": 1,
      "description": "Rate limit window in seconds. Required if `rate_limit_requests` is set."
    },
    "expires_in_days": {
      "type": "integer",
      "minimum": 1,
      "maximum": 365,
      "description": "Lifetime in days, counted from the moment the key is minted.\n\n**At most one** of `expires_in_days`, `expires_at` and `never_expires` may be\npresent; two or more is `400 conflicting_expiry_fields`. A value outside\n1-365 is `400 invalid_expiry`.\n\n**Omitting all three is not a way to opt out of expiry** — the key gets the\ndefault 90 days. To create a key that never expires you must say so, with\n`never_expires: true`.\n"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "Exact expiry instant, ISO 8601. Must be in the future and no more than 365 days\nfrom now, else `400 invalid_expiry`. Mutually exclusive with `expires_in_days`\nand `never_expires` (`400 conflicting_expiry_fields`).\n\nUse this when the key's life is pinned to a date you already know — a contract\nend, an audit window — rather than to a duration.\n"
    },
    "never_expires": {
      "type": "boolean",
      "description": "Send `true` for a key with **no expiry**: the response and every later read\ncarry `expires_at: null`, and the key stays valid until it is revoked by hand.\nA key that never stops working also never stops working for whoever finds it in\nan old CI secret or a container image, so this is a deliberate choice and not a\ndefault.\n\nMutually exclusive with `expires_in_days` and `expires_at`\n(`400 conflicting_expiry_fields`). `false` is refused with\n`400 invalid_expiry` rather than quietly meaning \"use the default\" — a body\nthat mentions expiry at all is making a statement about it, and answering that\nstatement with a silent 90-day clock is the guess this field exists to remove.\n"
    },
    "role_ids": {
      "type": "array",
      "maxItems": 20,
      "description": "Permission roles to attach to the new key, assigned in the SAME transaction as\nthe key itself. Discover ids with `GET /v1/roles?subject_kind=api_key`.\n\nOmit (or send `[]`) to create a key with no role — such a key is\n**default-denied on every policy-gated endpoint**, which is rarely what you\nwant. For an infrastructure-as-code runner, attach the seeded\n`Key — Infrastructure` role.\n\nEvery id must (a) belong to your tenant, else `404`; (b) declare the `api_key`\naudience in `applies_to`, else `400`; (c) grant nothing the calling key\ndoes not itself hold, else `403 privilege_escalation`; and (d) be one of the\nSEEDED key roles (`Key — Invoke`, `Key — Read-only`, `Key — Editor`,\n`Key — Infrastructure`), else `403 forbidden`. A key can never mint a key more\nprivileged than itself. Custom roles are being retired in favour of per-key\npermissions: a custom role a key already holds keeps working, but no new key\ncan be given one.\n",
      "items": {
        "type": "string",
        "format": "uuid"
      }
    }
  }
}