The Unexpected Bill: When Our AI System Started Billing Itself
The Unexpected Bill: When Our AI System Started Billing Itself
Building a fully autonomous trading research system sounds exciting — until you wake up to an unexpected API charge and realize your AI has been paying for itself out of your wallet.
Here's what happened, what we learned, and why we're actually glad it did.
The Setup
OCE runs an autonomous research loop around the clock, powered by Claude (Anthropic's AI) via the Claude Code CLI — a tool that works within our Max subscription, not the pay-per-token API. Or so we thought.
The Incident
One morning, a Discord notification arrived: an unexpected charge to the Anthropic API account.
We didn't initiate any API calls. The loop had been running normally. Yet somehow, Claude was billing us.
The investigation took about two hours. The culprit?
ANTHROPIC_API_KEY=sk-ant-xxxxxxxxxx
A leftover API key in our .env file. When ANTHROPIC_API_KEY is set in the environment, the claude -p CLI command silently switches from subscription mode (Max plan) to pay-per-token API mode. No warning. No confirmation. Just charges.
The fix was simple:
- Clear the key from
.env - Add
env.pop("ANTHROPIC_API_KEY", None)before everyclaude -pcall in the codebase - Lock it as a project-wide rule: never set ANTHROPIC_API_KEY in any environment file
The Server Outage We Mistook for Rate Limits
Around the same time, our loop started returning Credit balance is too low errors — which sounds exactly like hitting a rate limit. We spent hours investigating whether we'd overloaded our subscription.
We hadn't. Anthropic's servers were experiencing an outage (March 17-19). The error message was misleading, but the cause was entirely on their side.
This led to an important clarification from Anthropic support about our plan's actual limits.
What We Actually Learned About Max Plans
We've been operating under a misconception: that our Max plan switches from Opus to Sonnet at 20% utilization. A support agent had told us this — but it turned out they were describing the wrong tier.
After pushing back with our actual credential data (rateLimitTier: "default_claude_max_20x"), the correct information emerged:
| Plan | Opus → Sonnet threshold |
|---|---|
| Max 5x | 20% |
| Max 20x (ours) | 50% |
We're on the $200/month Max 20x plan. We have twice the Opus headroom we thought.
The Architecture Decision
With this clarified, we revisited whether to run Opus for hypothesis generation (the most creative phase of our research loop).
The answer: still Sonnet, across the board.
Why? We scaled from 3 to 5 parallel agents per phase. Running Opus × 5 simultaneous sessions would eat through the 50% threshold quickly — and the research loop runs 24 hours a day.
The tradeoff is straightforward: more diverse perspectives at Sonnet speed vs. deeper reasoning on fewer hypotheses. For an exploration system, breadth wins.
The Real Lesson
The incident taught us something more fundamental than "don't leave API keys lying around."
It reinforced a design principle we now call "prompts are creativity, code is enforcement."
Rules that matter — API key restrictions, spending limits, safety constraints — belong in code, not in documentation or memory. Our research loop now enforces this at every layer:
- The orchestrator strips
ANTHROPIC_API_KEYbefore every CLI call - The project CLAUDE.md bans
import anthropicentirely - Violation of these rules produces explicit errors, not silent failures
A system that can accidentally bill itself is a system that hasn't encoded its constraints deeply enough.
Current Status
The research loop is back online and running around the clock. Each cycle takes 1-3 hours — that's deliberate. We'd rather spend two hours building one solid hypothesis than burn through 20 shallow ones.
The lesson was well worth it.
OCE (Overnight Catalyst Edge) is an autonomous US equity trading research system. This post is part of our Build in Public series.
This is not investment advice. Past results don't guarantee future performance. All analysis reflects our internal research process only.