Cost Protection with Multi-Layer Timeout Limits

James Phoenix
James Phoenix

Summary

Runaway LLM workflows can rack up hundreds of dollars in unexpected API costs. Implement multi-layer timeout protection at job level (GitHub Actions timeout-minutes), request level (max_tokens), and input level (sample size limits) to cap costs at predictable levels. For scheduled scans: $0.12/scan × 120 scans/month = $14.40/month maximum.

The Problem

Autonomous LLM workflows in CI/CD can enter infinite loops, process excessive files, or generate bloated responses, leading to surprise bills of $100+ from runaway API usage. Without hard limits, a single misconfigured job can consume an entire monthly budget in hours.

The Solution

Set strict timeout limits at multiple layers: GitHub Actions job-level timeouts (15 min), LLM request-level token caps (max_tokens: 4096), input sample size limits (50 files max), and model selection (fast, cheap Sonnet). This creates fail-safe protection where even if one layer fails, others prevent cost explosions.

Leanpub Book

Read The Meta-Engineer

A practical book on building autonomous AI systems with Claude Code, context engineering, verification loops, and production harnesses.

Continuously updated
Claude Code + agentic systems
View Book

Related Concepts

References

Topics
Api LimitsAutomation SafetyBudget ProtectionCost ControlGithub ActionsLlm WorkflowsRunaway PreventionScheduled JobsTimeouts

Newsletter

Become a better AI engineer

Weekly deep dives on production AI systems, context engineering, and the patterns that compound. No fluff, no tutorials. Just what works.

Join 306K+ developers. No spam. Unsubscribe anytime.


More Insights

Cover Image for The Semantic Triangle: Mock Screens, PoC Backend, and Spec File Beat Any One Alone

The Semantic Triangle: Mock Screens, PoC Backend, and Spec File Beat Any One Alone

Three artefacts. Three reduced ambiguities. One projection task instead of three inventions.

James Phoenix
James Phoenix
Cover Image for Contracts Parallelize Agents

Contracts Parallelize Agents

If you’re waiting for Agent A to finish before starting Agent B, you’re wasting time. Define the contract between them and dispatch both now.

James Phoenix
James Phoenix