Set a key's budget
set_key_budgetSet a key's budget
Sets or replaces one key's budget: daily, weekly, monthly and lifetime limits at our price (at least one), the alert share and the mode. limits.monthly becomes the key's monthlyLimitUsd. hard_stop refuses the key's requests with a 402 once a limit is reached (the request that crosses it can go a little over: the check runs before a request, its cost lands after, and the Model API keeps the key's state for about a minute); alert_only never blocks and sends one email per limit and window when the spend crosses alertPct. The account's budget, when there is one, applies too: the key stops at whichever limit it reaches first. Requests follow within about a minute.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"id": "<id>",
"limits": "<limits>"
},
"name": "set_key_budget"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The key id: any working model key of the account, a customer's included (GET /budgets lists them). | |
| mode | No | hard_stop refuses requests with a 402 at a limit; alert_only never blocks (it needs alertPct above 0). | hard_stop |
| limits | Yes | Limits in USD at our price, to the cent. At least one; null or left out is no limit. | |
| alertPct | No | Email once per limit and window when the spend crosses this share of a limit. 0 turns the alert off. | |
| idempotencyKey | No | Optional. A unique string so that repeating this call never creates twice. |