PATCH
/api/v1/api-keys/{keyId}/budgetUpdate API key budget
Sets or updates the monthly USD budget cap and alert thresholds for an API key. When the budget is exceeded, requests on this key return 402 Payment Required. Mass-assignment-safe (ADR-0017): only monthly_limit_usd, alert_thresholds, and hard_cap fields are accepted.
Authentication
Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/api-keys.
Request body required
Example
{
"monthly_limit_usd": 0,
"alert_thresholds": [
0
],
"hard_cap": false
}Schema
{
"application/json": {
"schema": {
"type": "object",
"properties": {
"monthly_limit_usd": {
"type": "number",
"minimum": 0
},
"alert_thresholds": {
"type": "array",
"items": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"description": "Fractions of monthly_limit_usd at which alerts fire (e.g., [0.5, 0.8, 1.0])."
},
"hard_cap": {
"type": "boolean",
"description": "If true, requests above limit return 402 instead of just alerting."
}
}
}
}
}Response
200 example
{
"success": true
}All status codes
200Budget updated.
400(no description)
401(no description)
403Forbidden — insufficient role for this operation.
404(no description)
429(no description)
Code samples
cURL
curl -X PATCH \
https://evalguard.ai/api/v1/api-keys/{keyId}/budget \
-H "Authorization: Bearer $EVALGUARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "monthly_limit_usd": 0, "alert_thresholds": [ 0 ], "hard_cap": false }'TypeScript
import { EvalGuard } from "@evalguard/sdk";
const client = new EvalGuard({ apiKey: process.env.EVALGUARD_API_KEY });
const response = await client.request({
method: "PATCH",
path: "/api/v1/api-keys/{keyId}/budget",
body: {
"monthly_limit_usd": 0,
"alert_thresholds": [
0
],
"hard_cap": false
},
});
console.log(response);Python
from evalguard import EvalGuard
import os
client = EvalGuard(api_key=os.environ["EVALGUARD_API_KEY"])
response = client.request(
method="PATCH",
path="/api/v1/api-keys/{keyId}/budget",
body={
"monthly_limit_usd": 0,
"alert_thresholds": [
0
],
"hard_cap": False
},
)
print(response)Go
package main
import (
"context"
"fmt"
"os"
"github.com/evalguard/evalguard-go"
)
func main() {
client := evalguard.NewClient(os.Getenv("EVALGUARD_API_KEY"))
resp, err := client.Request(context.Background(), "PATCH", "/api/v1/api-keys/{keyId}/budget", map[string]any{"monthly_limit_usd": 0, "alert_thresholds": []any{0}, "hard_cap": false})
if err != nil { panic(err) }
fmt.Println(resp)
}Errors
400401403404429