The Problem
An AI agent running an autonomous research loop makes 50+ search API calls in a single session, burning through a month of search budget in minutes. There is no native cap in LangChain, CrewAI, or similar frameworks.
The Scavio Solution
Wrap the search function in a credit counter that raises an exception and returns partial results when the session limit is hit. One decorator, zero framework changes required.
Before
Agent starts a research task. Each subtask spawns more searches. After 80 calls, the monthly credit allotment is gone. The agent completes but the bill is 4x expected. No warning was issued.
After
Agent is initialized with a 20-credit cap. After 20 searches, BudgetExceeded is raised. The agent catches it, returns the research gathered so far, and stops. Total session cost: $0.10.
Who It Is For
Developers building autonomous agents with LangChain, CrewAI, or custom loops where search is called in unbounded loops without cost visibility.
Key Benefits
- Hard cap prevents runaway spend regardless of agent loop depth
- Partial results are returned gracefully instead of failing silently
- Works with any search provider that charges per call
- Per-session or per-run budget, configurable at call time
Python Example
import functools
import requests
class BudgetExceeded(Exception): pass
class SearchBudget:
def __init__(self, cap): self.cap = cap; self.used = 0
def charge(self):
self.used += 1
if self.used > self.cap: raise BudgetExceeded(f"{self.used}/{self.cap} credits used")
def make_capped_search(cap_credits):
budget = SearchBudget(cap_credits)
def search(query, **kwargs):
budget.charge()
r = requests.post("https://api.scavio.dev/api/v1/search",
json={"query": query, "num_results": kwargs.get("n", 5)},
headers={"x-api-key": "your-scavio-api-key"}, timeout=15)
r.raise_for_status()
return r.json().get("organic_results", [])
search.budget = budget
return search
# Usage
search = make_capped_search(cap_credits=20)
try:
results = search("best python frameworks 2026")
except BudgetExceeded as e:
print(f"Stopped: {e}")JavaScript Example
function makeCappedSearch(cap, apiKey) {
let used = 0;
return async function search(query, n = 5) {
used++;
if (used > cap) throw new Error(`Budget exceeded: ${used}/${cap}`);
const res = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey },
body: JSON.stringify({ query, num_results: n })
});
return (await res.json()).organic_results ?? [];
};
}