Cost-Bounded Research
Deep ResearchThe Problem
Open-ended agent tasks — research, analysis, discovery — have no natural stopping point. Without a cost cap, a runaway loop or unexpectedly large input can consume an unbounded amount of tokens. You need a hard ceiling that the system respects, not a soft advisory that gets ignored.
The Pattern
Task starts
│
▼
┌─────────────────┐
│ budget tracker │ $0.00 / $2.00
└────────┬────────┘
│
▼
Agent executes
│
Budget check
after each step
│
┌───┴────┐
▼ ▼
Under Over budget
budget │
│ ▼
│ Halt gracefully
│ Return partial results
▼ + budget_exhausted: true
Continue
When to Use
- Any open-ended research or discovery task
- Multi-agent pipelines where cost compounds across workers
- Production tasks where you need predictable billing
When NOT to Use
- Tasks with a fixed, known scope where a budget cap adds no value
- When partial results on budget exhaustion are useless (better to fail loudly than return incomplete data silently)
Code Example
import { QueueAI } from "@queueai/sdk"
const queue = new QueueAI({ apiKey: process.env.QUEUEAI_API_KEY })
const task = await queue.submit({
name: "deep-research",
input: {
question: "What is the competitive landscape for AI orchestration tools?",
depth: "comprehensive",
},
model: { primary: "anthropic/claude-opus-4-8" },
budget: {
maxTokens: 100_000,
maxCostUsd: 2.00,
},
})
const result = await task.result()
if (result.budgetExhausted) {
console.log("Partial results returned — budget was hit")
}
from queueai import QueueAI
queue = QueueAI(api_key=os.environ["QUEUEAI_API_KEY"])
task = queue.submit(
name="deep-research",
input={
"question": "What is the competitive landscape for AI orchestration tools?",
"depth": "comprehensive",
},
model={"primary": "anthropic/claude-opus-4-8"},
budget={"max_tokens": 100_000, "max_cost_usd": 2.00},
)
result = task.result()
if result.get("budget_exhausted"):
print("Partial results returned — budget was hit")
See it in action: The
budget.maxCostUsdfield is available on every QueueAI task.