Skip to content
PATCH/api/v1/api-keys/{keyId}/budget

Set or remove an API key's monthly budget cap

Sets the per-key budget cap and/or its reset cadence. Pass `monthlyBudgetUsd` as a number to set the cap (max 1,000,000; a larger value is rejected 400 VALIDATION_ERROR by the body schema before the handler runs) or `null` to remove it (unlimited), and/or `resetPeriod` (`daily`|`weekly`|`monthly`) to change the cadence at which the spend counter auto-resets. At least one of the two keys must be present or the request 400s MISSING_FIELDS; neither is individually required. Admin role required. Returns the updated `{keyId, monthlyBudgetUsd, resetPeriod, currentPeriodSpentUsd, currentPeriodStartedAt}` and invalidates the gateway's cached team metadata for the key.

Authentication

Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/settings/api-keys.

Parameters

keyId in pathrequired
string

Request body required

Example

{
  "monthlyBudgetUsd": 0
}
Schema
{
  "application/json": {
    "schema": {
      "type": "object",
      "required": [
        "monthlyBudgetUsd"
      ],
      "properties": {
        "monthlyBudgetUsd": {
          "type": "number",
          "minimum": 0,
          "maximum": 1000000,
          "nullable": true,
          "description": "Number sets the cap (0..1,000,000); null removes it. 400 MISSING_BUDGET if the key is absent."
        }
      }
    }
  }
}

Response

200 example

{
  "success": true
}

All status codes

200Budget updated.
400(no description)
401(no description)
403Forbidden — admin role required.
404(no description)
409Conflict — CONFLICT.
429(no description)
500Internal Server Error — DB_ERROR.

Code samples

cURL

# {keyId} is shown with an EXAMPLE value — replace it with real values.
curl -X PATCH \
  https://evalguard.ai/api/v1/api-keys/00000000-0000-0000-0000-000000000000/budget \
  -H "Authorization: Bearer $EVALGUARD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "monthlyBudgetUsd": 0 }'

TypeScript

// The TypeScript SDK (@evalguard/sdk) exposes TYPED methods — runEval,
// getEval, runSecurityScan, checkFirewall, … — not a generic request().
// For an arbitrary endpoint, call it directly:
// {keyId} is shown with an EXAMPLE value — replace it with real values.

const res = await fetch("https://evalguard.ai/api/v1/api-keys/00000000-0000-0000-0000-000000000000/budget", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.EVALGUARD_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "monthlyBudgetUsd": 0
  }),
});
console.log(res.status, await res.json());

Python

# The Python SDK (pip install evalguardai) exposes TYPED methods on
# EvalGuardClient — run_eval, get_eval, … — not a generic request().
# For an arbitrary endpoint, call it directly:
# {keyId} is shown with an EXAMPLE value — replace it with real values.

import os
import requests

headers = {"Authorization": f"Bearer {os.environ['EVALGUARD_API_KEY']}"}
headers["Content-Type"] = "application/json"

response = requests.request(
    "PATCH",
    "https://evalguard.ai/api/v1/api-keys/00000000-0000-0000-0000-000000000000/budget",
    headers=headers,
    json={
    "monthlyBudgetUsd": 0
},
)
print(response.status_code, response.json())

Go

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"strings"
)

// {keyId} is shown with an EXAMPLE value — replace it with real values.
func main() {
	body := strings.NewReader(`{"monthlyBudgetUsd":0}`)
	req, _ := http.NewRequestWithContext(context.Background(), "PATCH", "https://evalguard.ai/api/v1/api-keys/00000000-0000-0000-0000-000000000000/budget", body)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("EVALGUARD_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	resp, err := http.DefaultClient.Do(req)
	if err != nil { panic(err) }
	defer resp.Body.Close()
	fmt.Println(resp.Status)
}

Errors

400401403404409429500

Other API Keys endpoints