Update key credits
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 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
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.
Request body
Example request
{
"keyId": "key_2cGKbMxRyIzhCxo1Idjz8q",
"value": 1000,
"operation": "set"
}Response
Credits updated successfully. Response includes updated remaining credits and refill settings.
Example response
{
"meta": {
"requestId": "req_123"
},
"data": {
"remaining": 1000,
"refill": {
"interval": "daily",
"amount": 1000,
"refillDay": 15
}
}
}