Request access
OverviewQuickstartCLI Reference
Documentation / Budget Lock

Budget Lock

Hard pre-call spend caps for OpenAI-compatible and Anthropic traffic routed through the RaksHex gateway. Status: private beta.

Caps & scopes

Budget Lock supports monthly hard caps across three scopes:

  • Workspace cap: total monthly spend across the workspace.
  • Agent cap: monthly spend for a given x-rakshex-agent-id header.
  • Gateway key cap: monthly spend tied to a specific RaksHex gateway key.

Every cap that applies to an incoming request is checked together before the upstream call runs. If any single cap would be exceeded, the request is refused with HTTP 403 (rakshex_budget_blocked). Monthly caps reset automatically.

Worst-case reservation & settlement

Before forwarding a request, RaksHex calculates the worst-case cost from input tokens and max_tokens using per-model pricing across a catalog of ~3,400 models, and reserves that amount in one Cloudflare Durable Object per workspace, which handles one spend check at a time.

Once the provider responds, RaksHex settles the reservation to the real token cost and releases any unused reserve. Because the Durable Object handles one reservation or settlement at a time, two calls cannot both pass a cap.

Alerts & webhook payload

RaksHex emits threshold notifications at 50%, 80%, and 100% of any cap via the budget.threshold webhook event:

{
  "event": "budget.threshold",
  "thresholdPercent": 80,
  "scope": "agent",
  "scopeId": "support-triage",
  "spentUsd": 40.12,
  "capUsd": 50.00,
  "period": "2026-11"
}

Check your own caps and spend

Call the gateway with your own key to see the caps that apply to it (workspace, this key, and its agent), with spend, remaining amount and the reset date:

curl https://rakshex-gateway.rakshex.workers.dev/v1/rakshex/budget   -H "Authorization: Bearer $RAKSHEX_KEY"

Spend includes calls still in flight.

Manage your workspace

With the owner token, under /v1/rakshex/workspace: GET the workspace and keys, GET/PUT /caps, DELETE /caps/:id, POST /keys to issue a gateway key, POST /keys/:id/revoke, PUT /providers/:provider to rotate your provider key, PUT/DELETE /webhook, and GET /usage.

Key revocation

If a gateway key leaks, revoke it at once with your owner token (POST /v1/rakshex/workspace/keys/:id/revoke). Every later request with that key is refused at the gateway. Your provider key stays in our vault, so a leaked RaksHex key does not expose it.

Limits

Only calls routed through the RaksHex gateway are capped. Calls made directly to a provider are not.