# LLMBUDGET.SET

> Create or update an LLM budget with a token cap, a cost cap and a window length.

URL: https://docs.hotkv.com/commands/llmbudget-set/

```
LLMBUDGET.SET name token_limit cost_limit_usd window_seconds
```

- Group: LLM usage and budgets
- Complexity: O(1)
- HotKV Cloud: Performance and Scale plans
- On-Premise: requires the llm-budget license feature

LLM budgets put a hard cap on the tokens and dollars a named budget (for example one per tenant) can spend in a time window, so you can refuse a request before you pay the model provider for it. `LLMBUDGET.SET` creates budget `name`, or changes the limits of an
existing one without clearing what it has already used.

All three arguments are positional:

- `token_limit`: the most tokens allowed per window. `0` means no token cap.
- `cost_limit_usd`: the most dollars allowed per window, as a decimal with at most six digits after the point and a leading digit (`5`, `5.00`, `0.25`). `0` means no cost cap.
- `window_seconds`: the window length. A new window starts when the budget is created, and once `window_seconds` have passed the usage goes back to zero and the next window starts. `0` means a single window that never resets.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Budget created or updated | Simple string `OK` | Same |

Errors:

- `ERR invalid argument` if a limit or the window is negative or not in the format above.
- `ERR budget limit reached` if the budget is new and the server already holds its maximum number of budgets (`max_budgets` under `[llmbudget]`).
- `ERR wrong number of arguments for 'llmbudget.set' command` if the argument count is wrong.
- `NOLICENSE llm-budget requires a HotKV license. Contact sales@hotkv.com` if your license does not include the `llm-budget` feature.

## Examples

```
127.0.0.1:6379> LLMBUDGET.SET tenant_acme 0 5.00 3600
OK
127.0.0.1:6379> LLMBUDGET.SET tenant_beta 1000000 0 86400
OK
```

The first budget allows $5 per hour with no token cap; the second allows a
million tokens per day with no cost cap.

## Compatibility

HotKV-only command. Redis and Valkey have no equivalent.

## See also

[LLMBUDGET.CONSUME](https://docs.hotkv.com/commands/llmbudget-consume/index.md), [LLMBUDGET.STATUS](https://docs.hotkv.com/commands/llmbudget-status/index.md), [LLMBUDGET.RESET](https://docs.hotkv.com/commands/llmbudget-reset/index.md), [LLMBUDGET.DROP](https://docs.hotkv.com/commands/llmbudget-drop/index.md), [LLMBUDGET.LIST](https://docs.hotkv.com/commands/llmbudget-list/index.md), [AI features guide](https://docs.hotkv.com/ai-features/index.md)