v66

OpenAPI 3.1.0raw.githubusercontent.com2026-08-0174265626.3 KB
keys

Update key settings

Update key properties in response to plan changes, subscription updates, or account status changes.

Use this for user upgrades/downgrades, role modifications, or administrative changes. Supports partial updates - only specify fields you want to change. Set fields to null to clear them.

Important: Permissions and roles are replaced entirely. Use dedicated add/remove endpoints for incremental changes.

Required Permissions

Your credential must have one of the following permissions:

  • api.*.update_key (to update keys in any API)
  • api.<api_id>.update_key (to update keys in a specific API)
  • unkey:v1:<workspace_id>:keyspaces/*/keys/*#update_key (to update keys in any keyspace)
  • unkey:v1:<workspace_id>:keyspaces/<keyspace_id>/keys/*#update_key (to update keys in a specific keyspace)
  • unkey:v1:<workspace_id>:keyspaces/<keyspace_id>/keys/<key_id>#update_key (to update a specific key)

Side Effects

If you specify an externalId that doesn't exist, a new identity will be automatically created and linked to the key. Permission updates will auto-create any permissions that don't exist in your workspace. Changes take effect immediately but may take up to 30 seconds to propagate to all edge regions due to cache invalidation.

post/v2/keys.updateKey

Request body

keyIdstring required

Specifies which key to update using the database identifier returned from createKey. Do not confuse this with the actual API key string that users include in requests.

namestring nullable

Sets a human-readable name for internal organization and identification. Omitting this field leaves the current name unchanged, while setting null removes it entirely. Avoid generic names like "API Key" when managing multiple keys per user or service.

externalIdstring nullable

Links this key to a user or entity in your system for ownership tracking during verification. Omitting this field preserves the current association, while setting null disconnects the key from any identity. Essential for user-specific analytics, billing, and key management across multiple users. Supports letters, numbers, underscores, dots, and hyphens for flexible identifier formats.

metaobject nullable

Stores arbitrary JSON metadata returned during key verification. Omitting this field preserves existing metadata, while setting null removes all metadata entirely. Avoid storing sensitive data here as it's returned in verification responses. Large metadata objects increase verification latency and should stay under 10KB total size.

expiresinteger nullable

Sets when this key automatically expires as a Unix timestamp in milliseconds. Verification fails with code=EXPIRED immediately after this time passes. Omitting this field preserves the current expiration, while setting null makes the key permanent.

Avoid setting timestamps in the past as they immediately invalidate the key. Keys expire based on server time, not client time, which prevents timezone-related issues. Active sessions continue until their next verification attempt after expiry.

enabledboolean

Controls whether the key is currently active for verification requests. When set to false, all verification attempts fail with code=DISABLED regardless of other settings. Omitting this field preserves the current enabled status. Useful for temporarily suspending access during billing issues, security incidents, or maintenance windows without losing key configuration.

rolesstring[]
permissionsstring[]

Example request

{
  "keyId": "key_2cGKbMxRyIzhCxo1Idjz8q",
  "name": "Payment Service Production Key",
  "externalId": "user_912a841d",
  "meta": {
    "plan": "enterprise",
    "limits": {
      "storage": "500GB",
      "compute": "1000 minutes/month"
    },
    "features": [
      "analytics",
      "exports",
      "webhooks"
    ],
    "hasAcceptedTerms": true,
    "billing": {
      "cycle": "monthly",
      "next_billing": "2024-01-15"
    },
    "preferences": {
      "timezone": "UTC",
      "notifications": true
    },
    "lastBillingDate": "2023-10-15"
  },
  "expires": 1704067200000,
  "credits": {
    "remaining": 1000,
    "refill": {
      "interval": "daily",
      "amount": 1000,
      "refillDay": 15
    }
  },
  "ratelimits": [
    {
      "name": "api"
    }
  ],
  "enabled": true,
  "roles": [
    "api_admin",
    "billing_reader"
  ],
  "permissions": [
    "documents.read",
    "documents.write",
    "settings.view"
  ]
}

Response

Key updated successfully. Changes take effect immediately with up to 30-second edge propagation.

dataEmptyResponse required

Empty response object by design. A successful response indicates this operation was successfully executed.

Example response

{
  "meta": {
    "requestId": "req_123"
  }
}