4,474 of 5,369 Output Tokens Were Thinking: Reading Claude API Errors A developer documented a triage approach for Claude API failures that surface as HTTP 200 responses with empty text blocks, tracing one case where 4,474 of 5,369 output tokens were consumed by thinking, leaving only 895 for the answer. The writeup recommends branching on the error.type field rather than message text, distinguishing 429 rate limits from spend caps by the presence of a retry-after header, and checking stop_reason for max_tokens truncation. It also catalogs parameter rejections on newer models, including assistant message prefill, fixed budget_tokens thinking, modified thinking blocks, and forced tool_choice. The most confusing Claude API failure is not a 400, a 429, or a 529. It is an HTTP 200 with an empty text block. Nothing was thrown and nothing was logged as an error, yet your JSON parser reports "no JSON found". In our case the cause was thinking tokens eating the whole max tokens budget: 4,474 of 5,369 output tokens went to thinking, which left 895 for the answer. This post is the triage order we use now. It separates "retry", "fix the request", and "wait", and it catches the failures that never produce an error at all. The longer write-up, with the full status table, is on the original post https://my-blog.org/claude-code/post/claude-api-errors-empty-response?utm source=devto&utm medium=referral&utm campaign=claude-api-errors-empty-response . Every API error comes back as the same JSON object: a top-level error with a type and a message , plus a request id . { "type": "error", "error": { "type": "rate limit error", "message": "..." }, "request id": "req ..." } Branch on error.type , never on the message text. The docs say wording can change, and the SDK raises a different exception class per status code, so catch the class. A string comparison on the message will break silently one day. The first-pass reading: invalid request error : the request is wrong. Retrying the same request gives the same result. rate limit error : a limit of some kind. Which kind matters, see the next section. overloaded error : temporary overload across all users. Wait and retry. It is not an account problem. api error and 504 timeout error : server-side. Back off, or move long requests to streaming or the batch API. One more detail: the SDK already retries connection errors, 429s, and 5xx responses twice with exponential backoff, honoring retry-after . If an exception reached your code, two more attempts already happened. A 429 can be a rate limit, a monthly spend cap for your usage tier, or a Claude Code workspace spend limit. Only the first one clears if you wait. The tell is the retry-after header. A rate limit sends it. A spend cap does not, and it keeps failing until access reopens. If you treat a spend cap as a rate limit and add backoff, you get a loop that receives the same 429 all day. php import anthropic def classify 429 err: anthropic.RateLimitError - str: ra = err.response.headers.get "retry-after" if ra is None: return "cap-type: stop retrying, check spend caps and workspace limits" return f"rate-type: retry after {ra}s" Rarely, a sudden jump in organization usage can trigger a 429 from an acceleration limit. The fix there is to ramp traffic up gradually and keep usage patterns even. When the payload looks fine, check whether the model dropped a parameter. These are the messages that mattered to us: | Message fragment | Cause | Fix | |---|---|---| | "does not support assistant message prefill" | Newer models reject a prefilled last assistant message | Use structured output or the system prompt | | "thinking.type.enabled" is not supported | Fixed budget tokens thinking was removed on newer models | thinking: {type: "adaptive"} plus effort | | "thinking blocks ... cannot be modified" | You edited or dropped the previous assistant turn's thinking blocks | Send them back unchanged | | tool choice: type "tool" and "any" are not supported | Some models reject forced tool calls | auto plus strict tool use | One observation that is not in the official error docs: our LLM wrapper has a comment saying not to pass temperature , left behind after an old example that included it returned a 400. Treat that as our environment's experience, not a documented rule. Thinking tokens count toward max tokens . If thinking spends the budget first, the response ends with stop reason: "max tokens" and the text block is truncated or missing. The status is 200 and no exception is raised. Our case: a call asking for a content plan as JSON returned an empty string and failed with "JSON not found". We then walked a four-step misdiagnosis: That last point is the discriminator. If the prompt had pushed the model toward prose instead of JSON, the raw response would not be empty. Only an empty raw string supports the "thinking used the budget" diagnosis. php def diagnose empty resp - str | None: text = "".join b.text for b in resp.content if b.type == "text" if text.strip : return None thinking = getattr getattr resp.usage, "output tokens details", None , "thinking tokens", None return f"empty response: stop reason={resp.stop reason}, " f"output={resp.usage.output tokens}, thinking={thinking}" The field to read is usage.output tokens details.thinking tokens . When streaming, it only appears on the final message delta event. There are two official fixes: raise max tokens so thinking and text both fit, or lower effort so thinking spends less. We added a third. We cut what a single call has to produce: instead of "plan N posts at once", we ask for one outline, then one table of contents per post. The call that had failed three times passed on the first try. The rule of thumb: if the output must arrive in one piece, use the official fixes. If it can be split, split it. stop reason and thinking tokens . thinking.type , tool choice . Do not retry unchanged. retry-after present means rate-type; absent means cap-type, so stop the loop. request id if it persists. Give that ID to support. /mcp , and if only the first call fails, raise MCP TIMEOUT . If a Claude Code MCP tool fails only on its first call in a session, suspect a cold start. One of our search-console servers times out on the first call and works once a lightweight tool has woken it. | Control | What it adjusts | Example | |---|---|---| | MCP TIMEOUT env var | Server startup wait | MCP TIMEOUT=10000 claude | | Per-server timeout in .mcp.json | Tool execution time in ms | "timeout": 600000 | | MAX MCP OUTPUT TOKENS | Tool output token cap | Default 25,000 | The caution that matters most: do not retry a timed-out write. A timeout means "result unknown", not "failed". Resending a write that already landed applies the change twice, so check whether it took effect first. Two things this table does not cover. The subscription limit messages in the Claude Code UI, such as "You've hit your session limit", are plan notices, not HTTP errors. And any automation that reports "success" while producing nothing belongs to the same family as the empty response. For the full status table, the FAQ, and the related posts on this, see the complete guide on my-blog.org https://my-blog.org/claude-code/post/claude-api-errors-empty-response?utm source=devto&utm medium=referral&utm campaign=claude-api-errors-empty-response . Free tools I keep on my own site: 34 calculators and how-to guides https://my-blog.org/tools?utm source=devto&utm medium=referral&utm campaign=claude-api-errors-empty-response - loans, severance pay, take-home salary, savings vs deposits. New ones go out in one email, no ads.