今日已更新 412 条资讯 | 累计 19972 条内容
关于我们

5 Claude API Errors That Cost Me Money (And How I Trapped Them)

RAXXO Studios 2026年06月09日 08:07 4 次阅读 来源:Dev.to

Retry storms turned 1 timeout into 340 duplicate calls billed in 90 seconds Infinite tool loop ran 1,200 iterations before I noticed at 2am Partial stream cleanup stopped half-written DB writes corrupting records Trap every error class with a circuit breaker and a hard iteration cap Five Claude API errors quietly drained my account before I built guards around them. None of them threw a loud crash. They just kept billing while I slept. Here is exactly what broke, what it cost, and the traps I now run on every project. The Retry Storm That Billed 340 Times in 90 Seconds The most expensive mistake I made was naive retry logic. A single request timed out. My code caught the timeout and retried. The retry also timed out, so it retried again. Within 90 seconds I had fired 340 requests for one piece of work. The problem was that the Claude API had actually received and processed several of those requests. The timeout happened on my side waiting for the response, not on Anthropic's side. So I was paying for completed work I never saw, then paying again for the retry. My first version of the retry looked harmless. A while loop, a counter set to 5, a sleep of one second between attempts. The flaw was that the sleep was constant and the counter reset on every new job. Under load, jobs stacked, and each one spawned its own retry chain. That is how 1 timeout became 340 calls. The fix was exponential backoff with a hard ceiling and a request ID. I now generate a unique idempotency-style key per logical job and refuse to issue a second call for the same key until the first fully resolves or hard-fails. Backoff starts at 2 seconds and doubles up to 32 seconds, then gives up after 5 total attempts. attempt = 0 delay = 2 while attempt < 5 : try : return call_claude ( job_key ) except Timeout : attempt += 1 sleep ( delay + random_jitter ()) delay = min ( delay * 2 , 32 ) raise GiveUp ( job_key ) The jitter matters more than it looks. Without it, ten failed jobs all retry at the exact

本文内容来源于互联网,版权归原作者所有
查看原文