> ## Documentation Index
> Fetch the complete documentation index at: https://unkey.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# update-credits

> Update remaining credit quotas on an API key using the Unkey CLI. Adjust usage limits for plan changes, billing cycles, or purchased 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 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 regions.

<Note>
  See the [API reference](/api-reference/keys/update-key-credits) for the full HTTP endpoint documentation.
</Note>

## Usage

```bash theme={"theme":"kanagawa-wave"}
unkey api keys update-credits [flags]
```

## Flags

<ParamField body="--key-id" type="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.
</ParamField>

<ParamField body="--operation" type="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.
</ParamField>

<ParamField body="--value" type="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).
</ParamField>

## Global Flags

| Flag         | Type   | Description                                              |
| ------------ | ------ | -------------------------------------------------------- |
| `--root-key` | string | Override root key (`$UNKEY_ROOT_KEY`)                    |
| `--api-url`  | string | Override API base URL (default: `https://api.unkey.com`) |
| `--config`   | string | Path to config file (default: `~/.unkey/config.toml`)    |
| `--output`   | string | Output format. Use `json` for raw JSON                   |

## Examples

<CodeGroup>
  ```bash Set credits to a fixed value theme={"theme":"kanagawa-wave"}
  unkey api keys update-credits --key-id=key_1234abcd --operation=set --value=1000
  ```

  ```bash Increment credits after a purchase theme={"theme":"kanagawa-wave"}
  unkey api keys update-credits --key-id=key_1234abcd --operation=increment --value=500
  ```

  ```bash Decrement credits for a refund theme={"theme":"kanagawa-wave"}
  unkey api keys update-credits --key-id=key_1234abcd --operation=decrement --value=100
  ```

  ```bash JSON output for scripting theme={"theme":"kanagawa-wave"}
  unkey api keys update-credits --key-id=key_1234abcd --operation=set --value=1000 --output=json
  ```
</CodeGroup>

## Output

Default output shows the request ID with latency, followed by the updated credit data:

```text theme={"theme":"kanagawa-wave"}
req_2c9a0jf23l4k567 (took 45ms)

{
  "remaining": 1000,
  "refill": {
    "interval": "monthly",
    "amount": 1000,
    "refillDay": 1
  }
}
```

With `--output=json`, the full response envelope is returned:

```json theme={"theme":"kanagawa-wave"}
{
  "meta": {
    "requestId": "req_2c9a0jf23l4k567"
  },
  "data": {
    "remaining": 1000,
    "refill": {
      "interval": "monthly",
      "amount": 1000,
      "refillDay": 1
    }
  }
}
```
