AI API Spend Kill-Switch – OpenAI & Anthropic Budget Guard avatar

AI API Spend Kill-Switch – OpenAI & Anthropic Budget Guard

Pricing

Pay per event

Go to Apify Store
AI API Spend Kill-Switch – OpenAI & Anthropic Budget Guard

AI API Spend Kill-Switch – OpenAI & Anthropic Budget Guard

Hard spending limit for OpenAI and Anthropic (Claude) APIs. Checks spend via the official Admin APIs on a schedule, alerts Slack/Discord/webhooks, and can automatically disable leaked or runaway API keys.

Pricing

Pay per event

Rating

0.0

(0)

Developer

jet_mythology

jet_mythology

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

18 hours ago

Last modified

Share

AI API Spend Kill-Switch – OpenAI & Anthropic (Claude) budget guard

A hard spending limit and automatic kill switch for your OpenAI and Anthropic API keys. Run it on an Apify schedule (for example every 15 minutes): it reads your real spend from the official Admin APIs, alerts you on Slack, Discord or any webhook when a limit is crossed, and — if you allow it — disables the leaked or runaway API keys before the bill gets worse.

Built after the October 2026 wave of API key leaks (keys exposed through hosting environment variables were drained within hours) and after users reported being billed $515 against a $1 usage limit. Provider-side limits are soft or delayed; this Actor adds an independent second line of defense.

What it does

  • ✅ OpenAI spending limit: today's and month-to-date cost from GET /v1/organization/costs, grouped per project and per API key — so it can point to the exact key that is burning money.
  • ✅ Anthropic API budget: today's and month-to-date cost from the Claude Admin API cost report (GET /v1/organizations/cost_report), grouped per workspace.
  • ✅ Three kinds of limits: daily org limit, monthly org limit, and an optional per-key (OpenAI) / per-workspace (Anthropic) daily limit that catches a single leaked key even while your total looks normal.
  • ✅ Alerts to Slack incoming webhooks, Discord webhooks, or any HTTPS endpoint (JSON). One alert per breach per day (no spam every 15 minutes), plus an alert each time a key is disabled.
  • ✅ Kill switch (opt-in):
    • Anthropic: offending keys are set to status: "inactive" — fully reversible in the Claude Console.
    • OpenAI: OpenAI has no documented "pause key" endpoint for project keys, so the offending project keys are deleted (DELETE /v1/organization/projects/{project_id}/api_keys/{key_id}), or — your choice — the whole project is archived (POST /v1/organization/projects/{project_id}/archive). Both are irreversible: you will create new keys afterwards.
  • ✅ Allowlist / blocklist: protect your production keys or projects, restrict actions to some projects/workspaces, or name keys to kill first (e.g. keys you know were exposed on a compromised host).
  • ✅ Dry run to see exactly which keys would be disabled, without touching anything.
  • ✅ Demo mode with simulated data — run it right now without any key.

Quick start

  1. Create an Admin key:
    • OpenAI: platform.openai.com → Settings → Organization → Admin keys (Organization Owner only). Normal sk-proj-... keys cannot read costs.
    • Anthropic: Claude Console → Settings → Admin keys (organization admin). Normal sk-ant-api... keys cannot read the cost report.
  2. Paste the key(s) into the Actor input (fields are secret: encrypted by Apify and never written to the log or dataset).
  3. Set a daily and/or monthly limit in USD. Start in Alert only mode.
  4. Add your Slack/Discord webhook URL.
  5. Run once and check the dataset. When you trust the numbers, switch to Disable keys with Dry run on, then turn dry run off.

Schedule it (every 15 minutes)

  1. In Apify Console open Schedules → Create new.
  2. Cron expression: */15 * * * * (every 15 min) — or 0 * * * * for hourly.
  3. Add Actor → pick this Actor and the saved input (or create a Task with your input first and schedule the task).
  4. Optional: in the Actor's Settings → Notifications, enable "run failed" emails. With Mark the run as failed if a provider check fails on (default), a wrong key or a provider outage will email you.

Provider cost data only updates every few minutes to hours, so running more often than every 10–15 minutes does not add protection.

Input

FieldMeaning
openaiAdminKey / anthropicAdminKeyAdmin keys (secret). Leave both empty for a demo run.
dailyLimitUsdMax spend today (UTC), whole organization, per provider.
monthlyLimitUsdMax month-to-date spend (UTC), per provider.
perKeyOrWorkspaceDailyLimitUsdMax spend today for a single OpenAI key / Anthropic workspace. When set, only units over this limit are treated as offending ("precise mode").
modealert (default, never touches keys) or disable (kill switch).
disableScopeoffending = keys (OpenAI) / workspaces (Anthropic) that spent in the breached period; all = every active key in scope.
openaiDisableActiondelete_keys (default) or archive_projects.
dryRunShow what would be disabled, change nothing.
protectedKeyIds, protectedProjectOrWorkspaceIdsNever touched. Use default for Anthropic's default workspace.
onlyProjectOrWorkspaceIdsOnly act inside these.
blocklistKeyIdsAlways disabled when any limit is hit.
webhookUrlSlack / Discord / generic webhook (secret field).
alertEveryRunRe-alert on every run while over the limit (default: once per day per breach).

Output

One dataset row per provider per run, plus an OUTPUT record in the key-value store with the run summary:

{
"provider": "openai",
"checkedAt": "2026-10-22T11:00:00+00:00",
"todayUsd": 42.8,
"monthUsd": 46.0,
"dailyLimitUsd": 20,
"breaches": [
{"type": "org_daily", "spendUsd": 42.8, "limitUsd": 20},
{"type": "unit_daily", "unit": "key_leaked", "spendUsd": 41.7, "limitUsd": 15}
],
"topSpendersToday": [{"unit": "key_leaked", "usd": 41.7}, {"unit": "key_prod", "usd": 1.1}],
"actions": [{"keyId": "key_leaked", "keyName": "railway-env", "scopeId": "proj_railway", "keyHint": "sk-...lk3d", "result": "deleted"}],
"alertSent": "HTTP 200",
"error": null
}

Only key IDs, names and the provider's own redacted hints are stored — never key values.

Pricing

Pay per event:

  • Spend check — $0.002 per provider checked (one OpenAI + one Anthropic check = $0.004). Every 15 minutes ≈ $0.19/day ≈ $5.80/month for both providers; hourly ≈ $1.50/month.
  • Kill-switch action — $0.05 per key actually disabled/deleted or project archived. Dry runs and alerts are free.
  • Demo runs and failed checks are not charged per event.

That is usually less than a few minutes of a leaked key's spend.

Important limitations (please read)

  • Best effort, not a guarantee. Provider billing data lags (typically minutes, sometimes hours) and is finalized later. A leaked key can spend money between two checks and before the cost shows up. Use this together with provider-side limits, one key per project, and key rotation — not instead of them.
  • Costs are computed in UTC days/months, as reported by the providers.
  • OpenAI deletion and project archiving are irreversible. Keep dryRun on until you are sure, and allowlist your production keys.
  • OpenAI costs that are not tied to an API key (e.g. some org-level line items) count toward the org totals but cannot be attributed to a key (unattributedTodayUsd).
  • Anthropic reports cost per workspace, not per key. In offending mode every active key of an offending workspace is deactivated. Put each app in its own workspace for precise kills. Org-scoped (principal-bound) keys appear under default.
  • OpenAI organization/user keys and admin keys are not touched; only project API keys are.
  • Only official, documented endpoints are used: OpenAI GET /v1/organization/costs, GET /v1/organization/projects, GET /v1/organization/projects/{id}/api_keys, DELETE /v1/organization/projects/{id}/api_keys/{key_id}, POST /v1/organization/projects/{id}/archive; Anthropic GET /v1/organizations/cost_report, GET /v1/organizations/api_keys, POST /v1/organizations/api_keys/{id}. OpenRouter, Google Gemini and others are not supported yet.
  • This Actor is not affiliated with OpenAI or Anthropic.

FAQ

Why not just use the provider's usage limit? Provider limits are often soft, delayed, or apply only to some products — users have reported spending far above their configured limit. An independent check that can actually revoke keys closes that gap.

My key leaked right now — what should I do? Rotate it immediately in the provider console. Then run this Actor in disable mode with the leaked key IDs in blocklistKeyIds and schedule it so the next leak is caught automatically.

Is my admin key safe? Admin keys are powerful. The input fields are marked secret (encrypted at rest by Apify, hidden in the UI and logs). The Actor only sends them to api.openai.com / api.anthropic.com. Create a dedicated admin key for this Actor and delete it whenever you stop using it.