OpenAI & Claude Cost Monitor + Leaked API Key Kill-Switch
Pricing
Pay per event
OpenAI & Claude Cost Monitor + Leaked API Key Kill-Switch
Monitor OpenAI and Anthropic Claude API spend and usage, get Slack/Discord budget alerts, and auto-disable leaked or runaway API keys. Daily, monthly and per-key spend limits via the official Admin APIs. Schedule every 15 min. Demo mode, dry run, allowlist.
Pricing
Pay per event
Rating
0.0
(0)
Developer
jet_mythology
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
a month ago
Last modified
Categories
Features
Share
OpenAI & Claude API cost monitor: spend limits, budget alerts and a leaked-key kill-switch
Monitor your OpenAI and Anthropic Claude API usage and costs, get Slack or Discord budget alerts, and automatically shut down a leaked or runaway API key before it drains your account.
A leaked API key can burn your OpenAI or Anthropic (Claude) budget overnight. Whoever finds it doesn't need your password or your card: every request they send is billed to you, at full speed, while you sleep.
This Actor is an independent budget guard and kill switch. Run it on an Apify schedule (for example every 15 minutes): it reads your real spend from the official OpenAI and Anthropic Admin APIs, alerts you on Slack, Discord or any webhook when a limit is crossed, and, if you allow it, automatically disables the API keys that are burning money.
Why now: the October 2026 hosting-provider leaks
In the week of October 21, 2026, several platforms where developers store API keys as environment variables had security incidents:
- Railway investigated suspicious access to customers' build/environment secrets and asked all customers to revoke and rotate their keys (TechCrunch on X). Developers publicly reported OpenAI, Claude and OpenRouter keys stored only on Railway being drained.
- Zeabur announced it was shutting down after an attacker reportedly used an admin key that had never expired (report).
- A leak at OpenCode Console was reported to expose stored OpenAI, Anthropic and Google keys (report).
The same week, a Claude user reported being billed $515.76 against a $1 usage limit (r/ClaudeAI). Provider-side limits can be soft or delayed. Rotating keys fixes the leak you know about; this Actor watches for the one you don't.
Use cases
- Hard budget cap for OpenAI and Claude API usage: daily and monthly spend limits that are enforced, not just e-mailed.
- Leaked or stolen API key detection: a per-key (OpenAI) / per-workspace (Anthropic) daily limit flags the one key that suddenly spends.
- LLM cost alerts for teams and agencies: one Slack or Discord message when a client project or agent loop goes over budget.
- Runaway AI agent protection: stop an infinite loop or a bad deploy from spending all night.
How it works
- Checks spend on every run:
- OpenAI: today's and month-to-date cost from
GET /v1/organization/costs, grouped per project and per API key, so it points to the exact key that is spending. - Anthropic: today's and month-to-date cost from the Claude Admin API cost report (
GET /v1/organizations/cost_report), grouped per workspace.
- OpenAI: today's and month-to-date cost from
- Compares it to your limits: a daily org limit, a monthly org limit, and an optional per-key (OpenAI) / per-workspace (Anthropic) daily limit that catches a single leaked key even while your total still looks normal.
- Alerts you on Slack, Discord or any HTTPS webhook: one alert per breach per UTC day (no spam every 15 minutes), plus an alert every time keys are disabled, and an alert if a check fails.
- Pulls the plug (opt-in,
mode = disable):- Anthropic: offending keys are set to
status: "inactive". This is reversible in the Claude Console. - OpenAI: there is no documented "pause key" endpoint for project keys, so offending project keys are deleted, or, if you choose it, their whole project is archived. Both are irreversible: you create new keys afterwards.
- Anthropic: offending keys are set to
Safety controls: allowlist production keys or projects/workspaces, restrict actions to some projects/workspaces only, blocklist keys you know were exposed (they are killed first as soon as any limit is hit), and dry run to see exactly what would be disabled without touching anything.
Try it now with demo mode: leave the keys empty and the Actor runs on simulated data, at no per-event charge, so you can see the output and test your webhook.
Quick setup (10 minutes)
- Create an Admin key (normal project keys cannot read costs):
- OpenAI: platform.openai.com → Settings → Organization → Admin keys (Organization Owner only),
sk-admin-.... - Anthropic: Claude Console → Settings → Admin keys (organization admin),
sk-ant-admin....
- OpenAI: platform.openai.com → Settings → Organization → Admin keys (Organization Owner only),
- Paste the key(s) into the input. The fields are secret: encrypted by Apify, hidden in the UI, never written to the log or dataset.
- Set a daily and/or monthly limit in USD. Tip: also set a per-key / per-workspace daily limit a bit above your normal daily usage; that is what catches a leaked key early.
- Add your Slack or Discord webhook URL.
- Run once in Alert only mode and check the numbers in the dataset.
- Switch to Disable keys with Dry run on, check the planned actions, then turn dry run off.
Schedule it
- In Apify Console open Schedules → Create new.
- Cron:
*/15 * * * *(every 15 minutes) or0 * * * *(hourly). - Add Actor → pick this Actor with your saved input (or save the input as a Task and schedule the task).
- Optional: enable "run failed" emails in Settings → Notifications. With Mark the run as failed if a provider check fails on (default), a wrong key or a provider outage reaches you by email.
Provider cost data updates with a delay (minutes to hours), so checking more often than every 10–15 minutes does not add protection.
Input
| Field | Meaning |
|---|---|
openaiAdminKey / anthropicAdminKey | Admin keys (secret). Leave both empty for a demo run. |
dailyLimitUsd | Max spend today (UTC), whole organization, per provider. |
monthlyLimitUsd | Max month-to-date spend (UTC), per provider. |
perKeyOrWorkspaceDailyLimitUsd | Max spend today for one OpenAI key / one Anthropic workspace. When set, only units over this limit are treated as offending ("precise mode"). |
mode | alert (default, never touches keys) or disable (kill switch). |
disableScope | offending = keys (OpenAI) / workspaces (Anthropic) that spent in the breached period; all = every active key in scope. |
openaiDisableAction | delete_keys (default) or archive_projects. |
dryRun | Show what would be disabled, change nothing. |
protectedKeyIds, protectedProjectOrWorkspaceIds | Never touched. Use default for Anthropic's default workspace. |
onlyProjectOrWorkspaceIds | Only act inside these. |
blocklistKeyIds | Disabled first whenever any limit is exceeded. |
webhookUrl | Slack / Discord / generic webhook (secret field). |
alertEveryRun | Re-alert on every run while over the limit (default: once per breach per UTC day). |
failOnError | Mark the run as failed when a provider check fails (default: on). |
demoMode | Force simulated data. |
If you set no limit at all, a default daily limit of $10 is used.
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, key names and the provider's own redacted hints are stored, never key values.
Pricing
Pay per event:
- Spend check: $0.002 per provider per successful check. Every 15 minutes ≈ $0.19/day ≈ $5.80/month per provider (≈ $11.50/month for OpenAI + Anthropic). Hourly ≈ $1.45/month per provider.
- Key disabled: $0.05 per key actually deactivated/deleted or project archived. Dry runs and alerts cost nothing extra.
- Demo runs and failed checks are not charged per event.
Limitations (please read)
- Best effort, not a guarantee. Provider billing data lags (typically minutes, sometimes hours). 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.
- It detects leaks by their spend. It does not scan hosting providers or code for exposed keys, and it does not rotate keys for you.
- Costs are computed in UTC days/months, as reported by the providers.
- OpenAI key deletion and project archiving are irreversible. Keep
dryRunon until you are sure, and allowlist your production keys. - OpenAI costs not tied to an API key count toward org totals but cannot be attributed to a key (
unattributedTodayUsd). - Anthropic reports cost per workspace, not per key. In
offendingmode every active key of an offending workspace is deactivated. Put each app in its own workspace for precise kills. Keys without a workspace appear underdefault. - OpenAI admin keys and user/organization keys are not touched; only project API keys.
- 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; AnthropicGET /v1/organizations/cost_report,GET /v1/organizations/api_keys,POST /v1/organizations/api_keys/{id}. - OpenRouter, Google Gemini and other providers are not supported yet.
- Not affiliated with OpenAI, Anthropic, Railway, Zeabur or OpenCode.
FAQ
I hosted on Railway (or another affected platform). What should I do right now? First, rotate every key that was stored there, in the OpenAI and Anthropic consoles. This Actor does not replace rotation. Then schedule it with a per-key / per-workspace daily limit, so a key you forgot, or the next leak, is caught by its spending.
Why not just use the provider's own usage limit? Keep it on. But provider limits can be soft, delayed, or apply only to some products, and users have reported spending far above their configured limit. An independent check that can actually revoke keys is a second line of defense.
How fast does it react? At your schedule's interval plus the provider's billing delay. With a 15-minute schedule, it acts on the first run where the cost shows up in the Admin API.
Will it kill my production key by mistake?
Not if you allowlist it (protectedKeyIds / protectedProjectOrWorkspaceIds). Start with alert mode, then disable with dryRun on to see exactly what would be touched.
I already know which keys were exposed. Can I target them?
Put their IDs in blocklistKeyIds: they are disabled first as soon as any limit is exceeded. To shut a key down immediately, revoke it in the provider console.
Is my admin key safe?
Admin keys are powerful. The input fields are secret (encrypted at rest by Apify, hidden in the UI and logs), and secrets are redacted from error messages. The Actor sends them only to api.openai.com / api.anthropic.com. Create a dedicated admin key for this Actor and delete it when you stop using it.
Does it work with OpenRouter or Gemini? Not yet: only OpenAI and Anthropic.