Skip to main content
Update credit quotas in response to plan changes, billing cycles, or usage purchases. Use this for user upgrades/downgrades, monthly quota resets, credit purchases, or promotional bonuses. Supports three operations: set, increment, or decrement credits. Set to null for unlimited usage. Important: Setting unlimited credits automatically clears existing refill configurations. Required permissions: Your root key 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)
Side effects: Credit updates remove the key from cache immediately. Setting credits to unlimited automatically clears any existing refill settings. Changes take effect instantly but may take up to 30 seconds to propagate to all edge regions.
See the API reference for the full HTTP endpoint documentation.

Usage

unkey api keys update-credits [flags]

Flags

--key-id
string
required
The ID of the key to update (begins with key_). This is the database reference ID for the key, not the actual API key string that users authenticate with. This ID uniquely identifies which key’s credits will be updated.
--operation
string
required
Defines how to modify the key’s remaining credits. Must be one of set, increment, or decrement. Use set to replace current credits with a specific value or unlimited usage, increment to add credits for plan upgrades or credit purchases, and decrement to reduce credits for refunds or policy violations.
--value
integer
The credit value to use with the specified operation. For set, this becomes the new remaining credits value. For increment, this amount is added to current credits. For decrement, this amount is subtracted from current credits.Omit when using the set operation to make the key unlimited (removes usage restrictions entirely). When decrementing, if the result would be negative, remaining credits are automatically set to zero.Required when using increment or decrement operations. Optional for set operation (omitting creates unlimited usage).

Global Flags

FlagTypeDescription
--root-keystringOverride root key ($UNKEY_ROOT_KEY)
--api-urlstringOverride API base URL (default: https://api.unkey.com)
--configstringPath to config file (default: ~/.unkey/config.toml)
--outputstringOutput format — use json for raw JSON

Examples

unkey api keys update-credits --key-id=key_1234abcd --operation=set --value=1000

Output

Default output shows the request ID with latency, followed by the updated credit data:
req_2c9a0jf23l4k567 (took 45ms)

{
  "remaining": 1000,
  "refill": {
    "interval": "monthly",
    "amount": 1000,
    "refillDay": 1
  }
}
With --output=json, the full response envelope is returned:
{
  "meta": {
    "requestId": "req_2c9a0jf23l4k567"
  },
  "data": {
    "remaining": 1000,
    "refill": {
      "interval": "monthly",
      "amount": 1000,
      "refillDay": 1
    }
  }
}
Last modified on March 26, 2026