Integration Guide

Set up Kill Switch financial protection for your project. Three integration paths, use whichever fits your architecture.

REST API Edge Agent CLI

Integration Paths

MethodBest ForSetup Time
REST APIDirect HTTP integration, CI/CD, webhooks~5 min
Edge AgentCloudflare Workers monitoring with local kill-switch~10 min
Spend GuardIn-app budget limits for GPU/AI services (RunPod, Gemini, etc.)~15 min

1. REST API

The Kill Switch API at https://api.kill-switch.net provides full programmatic control over monitoring, rules, and kill switches.

Quick Start

# Health check
curl https://api.kill-switch.net/

# List supported providers
curl https://api.kill-switch.net/providers

# List preset rules (no auth needed)
curl https://api.kill-switch.net/rules/presets

# Trigger a kill switch (requires auth)
curl -X POST https://api.kill-switch.net/rules/agent/trigger \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{
    "threatDescription": "RunPod spend exceeded $50 in 2 hours",
    "severity": "critical",
    "recommendedActions": [
      { "type": "disconnect", "target": "my-worker" }
    ],
    "autoExecute": false
  }'

Key Endpoints

EndpointAuthPurpose
GET /providersNoneList Cloudflare, GCP, AWS, RunPod with default thresholds
GET /rules/presetsNoneDDoS, cost-runaway, GPU-runaway, Lambda-loop, etc.
POST /cloud-accountsJWTConnect a cloud provider for monitoring
POST /checkJWTRun monitoring check on all accounts
POST /rules/agent/triggerJWTAI agent triggers a kill switch
POST /agent/reportAPI KeyEdge agent submits metrics
GET /analytics/overviewJWTFinOps dashboard (daily costs, savings)
POST /database/killJWTInitiate database kill sequence

Full API reference: API Docs (OpenAPI)

2. Edge Agent (Cloudflare Workers)

The edge agent is a lightweight Cloudflare Worker that runs in your account. Your API tokens never leave your infrastructure.

Security model: The agent queries Cloudflare's GraphQL API using your token locally, checks against thresholds, and only sends aggregated metrics to the Kill Switch API. If a threshold is exceeded, it disconnects the worker locally before reporting.

Deploy

# Clone and deploy
git clone https://github.com/divinci-ai/kill-switch.git
cd kill-switch/packages/agent

# Edit thresholds in wrangler.toml, then:
wrangler deploy

# Set your CF credentials (stays in your account)
wrangler secret put CLOUDFLARE_API_TOKEN
wrangler secret put CLOUDFLARE_ACCOUNT_ID

Configuration

# wrangler.toml
[vars]
GUARDIAN_API_URL = "https://api.kill-switch.net"
DO_REQUEST_THRESHOLD = "1000000"
DO_WALLTIME_HOURS_THRESHOLD = "100"
WORKER_REQUEST_THRESHOLD = "10000000"

[triggers]
crons = ["*/5 * * * *"]  # Check every 5 minutes

What It Monitors

MetricDefault ThresholdAction on Breach
Durable Object requests/day1,000,000Auto-disconnect routes
DO wall-time hours/day100 hoursAuto-disconnect routes
Worker requests/day10,000,000Auto-disconnect routes

3. Spend Guard (In-App Budget Limits)

For services the edge agent can't see (RunPod GPU, Google Gemini, external APIs), add the Spend Guard directly to your app. It uses D1 to track per-job costs and enforces daily budgets.

How It Works

  1. Before every generation request, checkSpendBudget() runs a single D1 query
  2. If any limit is exceeded, returns 429 with a clear message
  3. After job creation, recordSpend() logs the estimated cost
  4. When the provider reports completion, updateActualCost() replaces the estimate
  5. At 80% budget utilization, PagerDuty/Discord/Slack alerts fire
  6. At 100%, all generation is blocked

Install

# Copy spend-guard.ts into your project
cp kill-switch/INTEGRATION.md .  # Full setup instructions

# The spend_log D1 table auto-creates on first use
# No migration needed

Wire Into Your Generate Endpoint

import { checkSpendBudget, recordSpend } from "./services/spend-guard";

// Before processing
const budget = await checkSpendBudget("runpod", userId);
if (!budget.allowed) {
  return new Response(budget.reason, { status: 429 });
}

// After creating the job
await recordSpend("runpod", userId, jobId);

Default Budget Limits

LimitDefaultProtects Against
Global daily spend$50/dayTotal platform runaway
Per-user daily jobs100/daySingle-account abuse
RunPod daily spend$25/dayGPU cost explosion
RunPod job timeout30 minStuck/infinite GPU jobs
Max concurrent GPU jobs8Parallel job flood
VEO daily requests200/dayAPI quota burn
TTS daily requests500/dayTTS abuse

4. Alerting

Alerts fire automatically when spend approaches limits.

ChannelTriggerBehavior
PagerDuty80% warning, 95% criticalPages on-call, deduped per severity/day
DiscordSame thresholdsRich embed with per-provider breakdown
SlackSame thresholdsText message with severity emoji

Configure PagerDuty

# Store routing key in Cloudflare Secrets Store
wrangler secrets-store secret create \
  0b7ac993cf26413ea6e2f1b5ede20b25 \
  --name PAGERDUTY_ROUTING_KEY \
  --scopes workers --remote

# Bind in wrangler.toml
[[secrets_store_secrets]]
binding = "PAGERDUTY_ROUTING_KEY"
store_id = "0b7ac993cf26413ea6e2f1b5ede20b25"
secret_name = "PAGERDUTY_ROUTING_KEY"
CLI available: Install with npm install -g @kill-switch/cli and run ks onboard to connect any provider interactively. See the CLI docs for details.

5. Supported Providers

ProviderResources MonitoredKill Actions
CloudflareWorkers, Durable Objects, R2, D1, Queues, Stream, ZonesDisconnect routes, disable workers.dev, delete worker
GCPCompute Engine, GKE, BigQuery, Cloud Functions, GCSStop instances, scale down, disable billing
AWSEC2, Lambda, RDS, ECS, EKS, SageMaker, S3Stop instances, throttle concurrency, disable functions
RunPodGPU Pods (on-demand & spot), Serverless Endpoints, Network VolumesStop pod, terminate pod, scale down endpoints
RedisRedis Cloud, AWS ElastiCache, Self-hosted (memory, connections, ops/sec)Kill connections, scale down, flush, pause cluster
MongoDBAtlas clusters, Self-hosted (storage, connections, ops/sec)Kill connections, isolate (IP whitelist), pause/scale cluster
OpenAIGPT API token usage, request counts, daily costRotate credentials (manual)
AnthropicClaude API token usage, daily costRotate credentials (manual)
xAI (Grok)Grok API token usage, daily costRotate credentials (manual)
ReplicateGPU predictions, model usage, daily costRotate credentials (manual)
SnowflakeWarehouse credits, query costs, data scanningScale down warehouse, suspend warehouse
VercelFunction invocations, bandwidth, build minutesScale down, disable service
DatadogHost count, log ingestion, custom metricsRotate credentials, mute monitors
NeonServerless Postgres compute hours, storage, data transferScale down, delete project
Neo4j AuraGraph DB instances, memory, storage, instance countPause instance, scale down, delete

6. RunPod Setup Guide

RunPod is a GPU cloud platform popular for ML training and inference. Kill Switch monitors your GPU pods, serverless endpoints, and network volumes — and can automatically shut down runaway resources before the bill arrives.

Credentials

RunPod uses a single API key for authentication — simpler than AWS or GCP.

  1. Go to runpod.io/console/user/settings
  2. Scroll to API Keys and click Create API Key
  3. Copy the key — it will only be shown once

Connect via CLI or dashboard:

# CLI (one command)
ks onboard --provider runpod \
  --runpod-api-key "YOUR_API_KEY" \
  --name "ML Training" \
  --shields cost-runaway,gpu-runaway

# Or connect at https://app.kill-switch.net/accounts/connect/runpod
Permissions: The API key needs read access for monitoring. If you want auto-kill actions (stop/terminate pods, scale down endpoints), it also needs write access. RunPod API keys have full access by default.

What's Monitored

ResourceMetrics TrackedCost Estimation
GPU Pods (on-demand)Running count, GPU type, uptimePer-GPU hourly rate × 24h (A100: $1.64/hr, H100: $3.29/hr, RTX 4090: $0.69/hr)
GPU Pods (spot)Running count, preemption risk~70% discount from on-demand rates
Serverless EndpointsActive workers, min/max scalingStandby worker hourly cost
Network VolumesStorage size (GB)$0.07/GB/month

Kill Switch uses RunPod's costPerHr field from the API when available. For pods where this isn't reported, it falls back to built-in GPU pricing estimates.

Kill Actions

ActionApplies ToReversibleWhat Happens
stop-podGPU PodsYesStops the pod. Container disk and network volume data are preserved. Restart anytime.
terminate-podGPU PodsNoTerminates the pod. Container disk is destroyed. Network volume data survives. Use as a last resort.
scale-downServerless EndpointsYesSets workersMin and workersMax to 0. No new requests are processed. Scale back up in the dashboard.
stop-pod vs terminate-pod: The default kill action for RunPod is stop-pod, which preserves your data. terminate-pod is only used when auto-delete is explicitly enabled or when a violation reaches critical severity (2x threshold). Your network volumes are always safe — they are never deleted by kill actions.

Default Thresholds

These are applied automatically when you connect a RunPod account. Adjust them in the dashboard or via the API.

ThresholdDefaultWhat It Protects Against
GPU Pod count4 podsForgotten or leaked pods left running
Spot Pod count8 podsSpot pod sprawl (higher limit since they're cheaper)
Serverless Workers10 workersEndpoint autoscaling runaway
Network Volume storage500 GBUnbounded data accumulation
Daily cost$50/dayOverall spend cap
Monthly spend limit$1,500/monthBilling shock prevention

Violations at 1x threshold trigger a warning. At 2x threshold, severity escalates to critical and auto-kill actions execute (if enabled).

7. Redis Setup Guide

Monitor Redis Cloud, AWS ElastiCache, or self-hosted Redis instances for memory spikes, connection overload, and cost runaway.

Credentials

Self-hosted: Provide a Redis URL (redis://user:pass@host:6379).

Redis Cloud: Account Key + Secret Key from Redis Cloud API Keys, plus your Subscription ID.

ElastiCache: AWS Access Key + Secret Key + Region + Cluster ID.

ks onboard --provider redis --redis-url "redis://user:pass@host:6379" --name "Production Redis"
# Or connect at https://app.kill-switch.net/accounts/connect/redis

Default Thresholds

ThresholdDefault
Memory Usage512 MB
Connected Clients100
Commands/sec10,000
Daily Cost$25/day

8. MongoDB Setup Guide

Monitor MongoDB Atlas clusters or self-hosted instances for storage growth, connection overload, and cost spikes.

Credentials

Atlas: Create API keys at Organization > Access Manager > API Keys. Needs "Project Read Only" + "Project Cluster Manager" roles.

Self-hosted: Provide a MongoDB URI (mongodb+srv://user:pass@host/db).

ks onboard --provider mongodb --atlas-public-key PUB --atlas-private-key PRIV --atlas-project-id PROJ --cluster-name Cluster0
# Or connect at https://app.kill-switch.net/accounts/connect/mongodb

Default Thresholds

ThresholdDefault
Storage10 GB
Active Connections200
Operations/sec5,000
Daily Cost$30/day

9. OpenAI Setup Guide

Monitor GPT API token usage, request counts, and daily spend. Catch runaway agent loops before they drain your budget.

Credentials

  1. Go to platform.openai.com/api-keys
  2. Create a new API key (starts with sk-)
  3. Optionally provide your Organization ID from Settings
ks onboard --provider openai --openai-api-key "sk-..." --name "Production OpenAI"
# Or connect at https://app.kill-switch.net/accounts/connect/openai

Default Thresholds

ThresholdDefault
Tokens/day1,000,000
Requests/day10,000
Daily Cost$50/day

10. Anthropic Setup Guide

Monitor Claude API token usage and daily spend.

Credentials

  1. Go to console.anthropic.com/settings/keys
  2. Create a new API key (starts with sk-ant-)
ks onboard --provider anthropic --anthropic-api-key "sk-ant-..." --name "Production Claude"
# Or connect at https://app.kill-switch.net/accounts/connect/anthropic

Default Thresholds

ThresholdDefault
Tokens/day1,000,000
Daily Cost$50/day

11. xAI (Grok) Setup Guide

Monitor Grok API token usage and daily spend.

Credentials

  1. Go to console.x.ai/api-keys
  2. Create a new API key
ks onboard --provider xai --xai-api-key "xai-..." --name "Grok API"
# Or connect at https://app.kill-switch.net/accounts/connect/xai

Default Thresholds

ThresholdDefault
Tokens/day1,000,000
Daily Cost$50/day

12. Replicate Setup Guide

Monitor GPU prediction costs, model usage, and daily spend on Replicate.

Credentials

  1. Go to replicate.com/account/api-tokens
  2. Create a new token (starts with r8_)
ks onboard --provider replicate --replicate-api-token "r8_..." --name "ML Predictions"
# Or connect at https://app.kill-switch.net/accounts/connect/replicate

Default Thresholds

ThresholdDefault
Predictions/day100
GPU Hours/day4
Daily Cost$25/day

13. Snowflake Setup Guide

Monitor Snowflake warehouse credits, query costs, and data scanning. Auto-suspend warehouses on threshold breach.

Credentials

Provide your Snowflake account name (from the URL), username, and password.

ks onboard --provider snowflake --snowflake-account "xy12345.us-east-1" \
  --snowflake-username "USER" --snowflake-password "PASS" \
  --warehouse "COMPUTE_WH" --name "Production Snowflake"
# Or connect at https://app.kill-switch.net/accounts/connect/snowflake

Kill Actions

ActionWhat HappensReversible
scale-downResize warehouse to X-SMALLYes
stop-instancesSuspend warehouse entirelyYes

Default Thresholds

ThresholdDefault
Credits/day10
Warehouses3
Daily Cost$100/day

14. Vercel Setup Guide

Monitor Vercel function invocations, bandwidth usage, and build minutes.

Credentials

  1. Go to vercel.com/account/tokens
  2. Create a new token with appropriate scope
  3. Optionally provide your Team ID (from Team Settings)
ks onboard --provider vercel --vercel-api-token "TOKEN" --name "Production Vercel"
# Or connect at https://app.kill-switch.net/accounts/connect/vercel

Default Thresholds

ThresholdDefault
Function Invocations/day100,000
Bandwidth/day100 GB
Daily Cost$50/day

15. Datadog Setup Guide

Monitor Datadog host count, log ingestion volume, and custom metrics costs.

Credentials

You need both an API Key and an Application Key:

  1. API Key: Organization Settings > API Keys
  2. Application Key: Organization Settings > Application Keys
  3. Optionally specify --datadog-site eu for EU region (default: US)
ks onboard --provider datadog --datadog-api-key "KEY" --datadog-application-key "APP_KEY" --name "Production Datadog"
# Or connect at https://app.kill-switch.net/accounts/connect/datadog

Default Thresholds

ThresholdDefault
Host Count50
Log Ingestion/day10 GB
Daily Cost$100/day

16. Neon Setup Guide

Monitor Neon serverless Postgres compute hours, storage, and data transfer. Scale down or pause a runaway project before the bill spikes.

Credentials

  1. Go to console.neon.tech > Account Settings > API Keys
  2. Create an API key and copy it (shown once)
  3. Find your Project ID under Project Settings
# Connect at the dashboard (Neon onboarding is dashboard-driven):
# https://app.kill-switch.net/accounts/connect/neon
#   API key:    neon_api_key_...
#   Project ID: your-project-id

Kill Actions

ActionWhat HappensReversible
scale-downSuspend all compute endpoints (autosuspend)Yes
deleteDelete the project (last resort)No

Default Thresholds

ThresholdDefault
Compute80 CU-hrs/month
Storage400 MB
Data Transfer4 GB
Daily Cost$1/day (monthly limit $30)

17. Neo4j Aura Setup Guide

Monitor Neo4j Aura graph database instances — memory, storage, and instance count. Pause or scale down before idle instances rack up cost.

Credentials

  1. Go to console.neo4j.io > Account > API Credentials
  2. Create credentials — you get a Client ID and Client Secret
  3. Optionally note a specific Instance ID (otherwise all instances are monitored)
# CLI (one command):
ks onboard --provider neo4j \
  --neo4j-client-id "CLIENT_ID" \
  --neo4j-client-secret "CLIENT_SECRET" \
  --name "Production Neo4j" --shields cost-runaway
# Or connect at https://app.kill-switch.net/accounts/connect/neo4j

Kill Actions

ActionWhat HappensReversible
pause-clusterPause the Aura instanceYes
scale-downResize to a smaller tierYes
deleteDelete the instance (last resort)No

Default Thresholds

ThresholdDefault
Running Instances3
Memory8 GB
Storage16 GB
Daily Cost$20/day (monthly limit $600)

Need Help?