The Problem
Teams set a monthly search API budget and forget about it until they get a surprise bill. AI agents can burn through credits unpredictably during research-heavy tasks. By the time someone notices, the budget is already 3x over. No built-in alerting exists on most search API dashboards.
The Scavio Solution
Build a budget monitoring wrapper around Scavio API calls. Track cumulative credit usage in a local file or database. Alert via Slack or email when usage hits 50%, 75%, and 90% of the monthly budget. Optionally auto-pause non-critical searches when budget is exhausted.
Before
Team sets $50/month search budget. Agent runs a heavy research task on day 15. Usage hits $120 before anyone notices. Surprise bill at end of month.
After
Budget wrapper tracks every API call. Slack alert fires at 50% ($25), 75% ($37.50), and 90% ($45). Non-critical searches paused at 100%. No surprise bills.
Who It Is For
Engineering teams running AI agents with variable search volume who need budget controls and alerting to prevent surprise bills.
Key Benefits
- Real-time budget tracking per API call
- Configurable alerts at 50%, 75%, 90% thresholds
- Auto-pause non-critical searches at budget limit
- Prevents surprise bills from agent search bursts
- Works with any search API, optimized for Scavio
Python Example
import requests, os, json
from pathlib import Path
from datetime import datetime
API_KEY = os.environ["SCAVIO_API_KEY"]
H = {"x-api-key": API_KEY, "Content-Type": "application/json"}
MONTHLY_BUDGET = 10000 # credits
COST_PER_SEARCH = 1 # 1 credit = $0.005
BUDGET_FILE = Path("search_budget.json")
def load_budget() -> dict:
if BUDGET_FILE.exists():
data = json.loads(BUDGET_FILE.read_text())
if data.get("month") != datetime.now().strftime("%Y-%m"):
return {"month": datetime.now().strftime("%Y-%m"), "used": 0, "alerts_sent": []}
return data
return {"month": datetime.now().strftime("%Y-%m"), "used": 0, "alerts_sent": []}
def save_budget(budget: dict):
BUDGET_FILE.write_text(json.dumps(budget))
def check_alerts(budget: dict):
pct = budget["used"] / MONTHLY_BUDGET * 100
for threshold in [50, 75, 90]:
if pct >= threshold and threshold not in budget["alerts_sent"]:
print(f"ALERT: Search budget at {pct:.0f}% ({budget['used']}/{MONTHLY_BUDGET} credits)")
budget["alerts_sent"].append(threshold)
def budgeted_search(query: str, critical: bool = True) -> dict:
budget = load_budget()
if budget["used"] >= MONTHLY_BUDGET and not critical:
return {"error": "Budget exhausted", "used": budget["used"]}
resp = requests.post(
"https://api.scavio.dev/api/v1/search",
headers=H,
json={"query": query, "country_code": "us"},
timeout=10,
)
budget["used"] += COST_PER_SEARCH
check_alerts(budget)
save_budget(budget)
return resp.json()
result = budgeted_search("python async frameworks 2026")
print(f"Results: {len(result.get('organic_results', []))}")JavaScript Example
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
const fs = await import('fs');
const MONTHLY_BUDGET = 10000;
function loadBudget() {
const month = new Date().toISOString().slice(0,7);
try { const d = JSON.parse(fs.readFileSync('search_budget.json','utf8')); return d.month===month?d:{month,used:0,alertsSent:[]}; }
catch { return {month,used:0,alertsSent:[]}; }
}
function saveBudget(b) { fs.writeFileSync('search_budget.json', JSON.stringify(b)); }
function checkAlerts(budget) {
const pct = budget.used/MONTHLY_BUDGET*100;
for (const t of [50,75,90]) {
if (pct>=t && !budget.alertsSent.includes(t)) { console.log('ALERT: Budget at '+pct.toFixed(0)+'%'); budget.alertsSent.push(t); }
}
}
async function budgetedSearch(query, critical=true) {
const budget = loadBudget();
if (budget.used>=MONTHLY_BUDGET && !critical) return {error:'Budget exhausted'};
const r = await fetch('https://api.scavio.dev/api/v1/search', {method:'POST', headers:H, body:JSON.stringify({query, country_code:'us'})});
budget.used++;
checkAlerts(budget);
saveBudget(budget);
return r.json();
}
const r = await budgetedSearch('python async frameworks 2026');
console.log('Results: '+(r.organic_results||[]).length);Platforms Used
Web search with knowledge graph, PAA, and AI overviews
YouTube
Video search with transcripts and metadata
Community, posts & threaded comments from any subreddit
Amazon
Product search with prices, ratings, and reviews