ApiKey

Represents programmatic credentials enabling authenticated API access across users, organizations, tenants, or service accounts. Supports lifecycle management with expiration and revocation policies, fine-grained scope permissions, and network-level security controls through IP and origin restrictions. Includes usage tracking and rate limiting for comprehensive API credential management.

25 properties
Schema

Properties

PropertyTypeModeDescriptionRequired
keyIdstring
stored

Unique public identifier for the API key, typically prefixed for easy recognition and used as the primary reference in API requests. This is the non-sensitive portion that can be logged and displayed safely.

Example: "ak_live_1a2b3c4d5e6f7g8h9i0j"

Required
namestring
stored

Human-readable name assigned to the API key for identification purposes, helping users and administrators distinguish between multiple keys with different purposes or environments.

Example: "Production Integration Key"

Required
descriptionstring
stored

Optional detailed description explaining the purpose, usage context, or intended application of this API key, useful for documentation and governance purposes.

Example: "API key for production payment gateway integration with Stripe webhook processing"

Optional
userUser
stored

Reference to the User entity that owns this API key when the key is scoped to an individual user account. Null when the key belongs to an organization, tenant, or is a service account.

Example: "user_9k8j7h6g5f4d3s2a1"

Optional
organizationOrganization
stored

Reference to the Organization entity that owns this API key when the key is scoped to organizational access. Null when the key belongs to a user, tenant, or is a service account.

Example: "org_tech_corp_2024"

Optional
tenantTenant
stored

Reference to the Tenant entity that owns this API key in multi-tenant architectures where keys are scoped to specific tenant instances. Null when not applicable to tenant context.

Example: "tenant_acme_production"

Optional
ownerTypestring
stored

Discriminator indicating the type of entity that owns this API key, used to determine which ownership reference field should be populated and how permissions should be evaluated.

Values: user, organization, tenant, service-account

Example: "organization"

Required
statusstring
stored

Current lifecycle status of the API key controlling whether it can be used for authentication. Active keys allow API access, inactive keys are temporarily disabled, revoked keys are permanently invalidated, and expired keys have passed their expiration date.

Values: active, inactive, revoked, expired

Example: "active"

Required
hashedSecretstring
stored

Cryptographically hashed representation of the secret key portion used to validate authentication requests. The plain-text secret is only shown once at creation time and never stored directly for security purposes.

Example: "$2b$12$KIXxKzXq8Z5yF6Hv8qE2Pu.Vz9fG8yH5jN2kL3mP4qR5sT6uV7wX8"

Required
allowedScopesstring[]
stored

Array of permission scopes that define what operations and resources this API key is authorized to access. Scope syntax follows domain-specific conventions such as resource:action patterns or hierarchical namespaces.

Example: ["users:read","payments:write","webhooks:manage"]

Optional
allowedIpAddressesstring[]
stored

Whitelist of IP addresses or CIDR ranges from which API requests using this key will be accepted. Empty or null indicates no IP restrictions, allowing requests from any origin address.

Example: ["203.0.113.0/24","198.51.100.42"]

Optional
allowedOriginsstring[]
stored

Whitelist of origin domains or URLs permitted to use this API key, typically used for browser-based applications requiring CORS validation. Null or empty allows all origins.

Example: ["https://app.example.com","https://dashboard.example.com"]

Optional
rateLimitjson
stored

Rate limiting configuration object specifying maximum request thresholds per time window to prevent abuse and ensure fair resource usage. Contains fields like requestsPerMinute, requestsPerHour, and requestsPerDay.

Example: {"requestsPerMinute":60,"requestsPerHour":1000,"requestsPerDay":10000}

Optional
usageCountnumber
stored

Cumulative count of successful API requests authenticated with this key since its creation, useful for tracking key utilization and identifying high-traffic integrations.

Example: 15847

Optional
lastUsedAtdatetime
stored

Timestamp of the most recent successful API request authenticated with this key, useful for identifying stale or unused keys that may be candidates for revocation.

Example: "2025-11-27T14:32:18Z"

Optional
expiresAtdatetime
stored

Optional expiration timestamp after which the API key will no longer be valid for authentication. Null indicates the key does not expire and remains valid until explicitly revoked or deactivated.

Example: "2026-11-27T23:59:59Z"

Optional
revokedAtdatetime
stored

Timestamp when the API key was permanently revoked, indicating it can no longer be used for authentication. Null when the key has not been revoked.

Example: "2025-11-15T09:20:33Z"

Optional
revokedByUser
stored

Reference to the User entity who performed the revocation action, useful for audit trails and security investigations. Null when not revoked or revoked by automated processes.

Example: "user_admin_5f4d3s2a1z"

Optional
revokedReasonstring
stored

Optional explanation for why the API key was revoked, providing context for security audits, compliance reviews, or troubleshooting access issues.

Example: "Security incident: potential key compromise detected"

Optional
environmentstring
stored

Deployment environment context where this API key is intended to be used, helping teams organize and manage keys across different stages of the development lifecycle.

Values: development, staging, production, test

Example: "production"

Optional
metadatajson
stored

Flexible key-value store for domain-specific attributes, custom tags, integration identifiers, or any additional data needed for specialized implementations without modifying the core schema.

Example: {"integrationId":"int_stripe_webhook_001","projectName":"Payment Gateway v2","costCenter":"engineering-platform"}

Optional
isActiveboolean
calculated

Computed boolean indicating whether the API key is currently valid for authentication by evaluating status, expiration, and revocation conditions. Returns true only when status is active and key is neither expired nor revoked.

Example: true

Optional
isExpiredboolean
calculated

Computed boolean indicating whether the API key has passed its expiration date. Returns true when expiresAt exists and is in the past, false otherwise.

Optional
daysUntilExpirationnumber
calculated

Computed number of days remaining until the API key expires, useful for proactive notifications and renewal workflows. Null when expiresAt is not set, negative when already expired.

Example: 365

Optional
daysSinceLastUsenumber
calculated

Computed number of days elapsed since the API key was last used for authentication, useful for identifying dormant keys. Null when lastUsedAt is not set.

Example: 3

Optional

Examples

Example 1

{
  "@type": "ApiKey",
  "keyId": "ak_live_user_personal_abc123xyz",
  "name": "Personal Development Key",
  "description": "Personal API key for testing and development purposes",
  "user": "user_john_doe_123",
  "organization": null,
  "tenant": null,
  "ownerType": "user",
  "status": "active",
  "hashedSecret": "$2b$12$N9qo8uLOickgx2ZMRZoMye.IjdJDXIgZwPJn7EQXxYz8PqmZ3r4K2",
  "allowedScopes": [
    "users:read",
    "projects:read",
    "projects:write"
  ],
  "allowedIpAddresses": null,
  "allowedOrigins": null,
  "rateLimit": {
    "requestsPerMinute": 30,
    "requestsPerHour": 500,
    "requestsPerDay": 5000
  },
  "usageCount": 1247,
  "lastUsedAt": "2025-11-27T08:15:30Z",
  "expiresAt": "2026-01-15T23:59:59Z",
  "revokedAt": null,
  "revokedBy": null,
  "revokedReason": null,
  "environment": "development",
  "metadata": {
    "purpose": "local-development",
    "device": "macbook-pro-2023"
  },
  "isActive": true,
  "isExpired": false,
  "daysUntilExpiration": 49,
  "daysSinceLastUse": 0,
  "createdAt": "2025-01-15T10:30:00Z",
  "updatedAt": "2025-11-20T14:22:10Z"
}

Example 2

{
  "@type": "ApiKey",
  "keyId": "ak_live_org_integration_xyz789abc",
  "name": "Production Payment Integration",
  "description": "Organization-level API key for Stripe payment gateway integration handling webhook processing and transaction management",
  "user": null,
  "organization": "org_acme_corporation",
  "tenant": null,
  "ownerType": "organization",
  "status": "active",
  "hashedSecret": "$2b$12$KIXxKzXq8Z5yF6Hv8qE2Pu.Vz9fG8yH5jN2kL3mP4qR5sT6uV7wX8",
  "allowedScopes": [
    "payments:read",
    "payments:write",
    "webhooks:manage",
    "refunds:write"
  ],
  "allowedIpAddresses": [
    "52.89.214.238",
    "34.212.75.30",
    "54.187.174.169"
  ],
  "allowedOrigins": [
    "https://api.stripe.com"
  ],
  "rateLimit": {
    "requestsPerMinute": 120,
    "requestsPerHour": 5000,
    "requestsPerDay": 100000
  },
  "usageCount": 2847593,
  "lastUsedAt": "2025-11-27T15:42:18Z",
  "expiresAt": null,
  "revokedAt": null,
  "revokedBy": null,
  "revokedReason": null,
  "environment": "production",
  "metadata": {
    "integrationId": "int_stripe_001",
    "projectName": "E-commerce Platform",
    "costCenter": "payments-team",
    "sla": "tier-1-critical"
  },
  "isActive": true,
  "isExpired": false,
  "daysUntilExpiration": null,
  "daysSinceLastUse": 0,
  "createdAt": "2024-03-10T09:00:00Z",
  "updatedAt": "2025-08-15T11:30:45Z"
}

Example 3

{
  "@type": "ApiKey",
  "keyId": "ak_live_tenant_saas_def456ghi",
  "name": "Tenant API Access - Beta Corp",
  "description": "Tenant-scoped API key providing isolated access to Beta Corp's data partition in our multi-tenant SaaS platform",
  "user": null,
  "organization": null,
  "tenant": "tenant_beta_corp_prod",
  "ownerType": "tenant",
  "status": "active",
  "hashedSecret": "$2b$12$QRstu5vWx6Yz7Ab8Cd9Ef0Gh1Ij2Kl3Mn4Op5Qr6St7Uv8Wx9Yz0",
  "allowedScopes": [
    "tenant:read",
    "tenant:write",
    "reports:read",
    "analytics:read"
  ],
  "allowedIpAddresses": [
    "198.51.100.0/24",
    "203.0.113.50"
  ],
  "allowedOrigins": [
    "https://beta-corp.example.com",
    "https://dashboard.beta-corp.com"
  ],
  "rateLimit": {
    "requestsPerMinute": 90,
    "requestsPerHour": 3000,
    "requestsPerDay": 50000
  },
  "usageCount": 45892,
  "lastUsedAt": "2025-11-26T22:18:05Z",
  "expiresAt": "2025-12-31T23:59:59Z",
  "revokedAt": null,
  "revokedBy": null,
  "revokedReason": null,
  "environment": "production",
  "metadata": {
    "tenantTier": "enterprise",
    "contractId": "contract_beta_2025",
    "billingAccount": "bill_beta_corp_001"
  },
  "isActive": true,
  "isExpired": false,
  "daysUntilExpiration": 34,
  "daysSinceLastUse": 1,
  "createdAt": "2025-01-01T00:00:00Z",
  "updatedAt": "2025-09-22T13:45:18Z"
}

Example 4

{
  "@type": "ApiKey",
  "keyId": "ak_live_service_monitoring_jkl012mno",
  "name": "System Monitoring Service Account",
  "description": "Service account API key for internal monitoring infrastructure with elevated privileges for health checks and metrics collection",
  "user": null,
  "organization": null,
  "tenant": null,
  "ownerType": "service-account",
  "status": "active",
  "hashedSecret": "$2b$12$Aa1Bb2Cc3Dd4Ee5Ff6Gg7Hh8Ii9Jj0Kk1Ll2Mm3Nn4Oo5Pp6Qq7",
  "allowedScopes": [
    "system:health",
    "metrics:read",
    "metrics:write",
    "logs:read",
    "alerts:manage"
  ],
  "allowedIpAddresses": [
    "10.0.0.0/8",
    "172.16.0.0/12"
  ],
  "allowedOrigins": null,
  "rateLimit": {
    "requestsPerMinute": 300,
    "requestsPerHour": 15000,
    "requestsPerDay": 300000
  },
  "usageCount": 9234567,
  "lastUsedAt": "2025-11-27T15:59:45Z",
  "expiresAt": null,
  "revokedAt": null,
  "revokedBy": null,
  "revokedReason": null,
  "environment": "production",
  "metadata": {
    "serviceType": "monitoring",
    "infrastructure": "kubernetes",
    "namespace": "observability",
    "automatedRotation": true
  },
  "isActive": true,
  "isExpired": false,
  "daysUntilExpiration": null,
  "daysSinceLastUse": 0,
  "createdAt": "2024-06-01T12:00:00Z",
  "updatedAt": "2025-11-01T08:00:00Z"
}

Example 5

{
  "@type": "ApiKey",
  "keyId": "ak_live_org_compromised_pqr345stu",
  "name": "Legacy Integration Key (REVOKED)",
  "description": "Previously used for third-party CRM integration, revoked due to suspected credential exposure in public repository",
  "user": null,
  "organization": "org_acme_corporation",
  "tenant": null,
  "ownerType": "organization",
  "status": "revoked",
  "hashedSecret": "$2b$12$Vw7Xx8Yy9Zz0Aa1Bb2Cc3Dd4Ee5Ff6Gg7Hh8Ii9Jj0Kk1Ll2Mm3",
  "allowedScopes": [
    "contacts:read",
    "contacts:write",
    "leads:read"
  ],
  "allowedIpAddresses": null,
  "allowedOrigins": [
    "https://crm.partner.com"
  ],
  "rateLimit": {
    "requestsPerMinute": 60,
    "requestsPerHour": 2000,
    "requestsPerDay": 20000
  },
  "usageCount": 128475,
  "lastUsedAt": "2025-11-14T17:23:10Z",
  "expiresAt": "2026-03-01T23:59:59Z",
  "revokedAt": "2025-11-15T09:20:33Z",
  "revokedBy": "user_security_admin_789",
  "revokedReason": "Security incident: API key found committed to public GitHub repository. Immediate revocation per incident response protocol IR-2025-0042.",
  "environment": "production",
  "metadata": {
    "incidentId": "SEC-2025-0042",
    "replacementKeyId": "ak_live_org_crm_new_vwx678yza",
    "discoveredBy": "automated-secret-scanning"
  },
  "isActive": false,
  "isExpired": false,
  "daysUntilExpiration": 94,
  "daysSinceLastUse": 13,
  "createdAt": "2024-09-15T14:20:00Z",
  "updatedAt": "2025-11-15T09:20:33Z"
}