Urgent.News

What's breaking now, across thousands of outlets.

Tech

4,474 of 5,369 Output Tokens Were Thinking: Reading Claude API Errors

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…

A peculiar issue arises with the Claude API: receiving an HTTP 200 status code alongside an empty text block. This results in JSON parsers reporting no JSON found, despite no error being thrown or logged. In this scenario, 4,474 out of 5,369 output tokens were allocated to thinking, leaving only 895 tokens for the actual response. The triage process for handling such failures now involves retrying, fixing the request, or waiting.

All API errors are returned in the same JSON format: a top-level error object containing a type and a message, along with a request_id. The classification should be based on the error.type, not the message text, as the wording can change over time. SDKs raise distinct exception classes for different status codes, so catching the exception class is essential.

There are four main error types: 400 (invalid_request_error), 429 (rate_limit_error), 529 (overloaded_error), 500 (api_error), and 504 (timeout_error). Each type requires a specific action: retrying for 400 and 429, waiting and retrying for 529, and backoff or moving long requests to streaming/batch API for 500 and 504.

The SDK already retries connection errors, 429s, and 5xx responses twice with exponential backoff, respecting the retry-after header. However, if an exception reaches your code, two additional retries are already performed. A 429 can signify a rate limit, monthly spend cap, or Claude Code workspace spend limit. Only the rate limit issue can be resolved by waiting. Mistaking a spend cap for a rate limit can lead to an endless loop of receiving the same 429 error.

Sometimes, an increase in organization usage can trigger a 429 due to an acceleration limit. The solution is to gradually increase traffic and maintain even usage patterns. A 400 error on a seemingly valid request occurs when the model drops a parameter. If the payload looks fine, check whether the model dropped a parameter, such as the thinking.type.enabled flag.

If the assistant message prefill is not supported by newer models, use structured output or the system prompt instead. When the tool_choice is set to type tool and any are not supported, some models reject forced tool calls. An unexpected 400 error can also arise from passing the temperature parameter, which is not officially documented.

The most frustrating issue is when the API returns an empty response with an HTTP 200 status code, indicating that the thinking tokens have consumed the entire max_tokens budget. The response text is truncated or missing, and no exception is raised. To diagnose this issue, examine the usage.output_tokens_details.thinking_tokens field.

If the output must arrive at a specific time, consider raising the max_tokens value or reducing the effort to minimize thinking token usage. In our case, breaking the task into multiple calls for one outline and one table of contents per post resolved the issue after three failed attempts.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

ACH Return Codes Explained: R01, R03, R10 & How to Handle Them

ACH Return Codes Explained: R01, R03, R10 & How to Handle Them ACH Return Codes Explained: R01, R03, R10 & How to Handle Them When you're building a payout system, ACH returns are inevitable.

  • R01 indicates insufficient funds in recipient's account
  • R03 signals no account found for provided routing/account numbers
  • R10 denotes unauthorized debit requiring fraud investigation

Common Freelancing Mistakes and How to Avoid Them

Freelancing offers professionals the freedom to choose projects, work with different clients, and build careers around their skills.

  • Lack of planning leads to common freelancing mistakes
  • Undervaluing services and poor presentation harm freelancers
  • Effective time management and contract adherence are key to success

How I Predict the Future: Gut Instinct, Verification, and Building

I've noticed something interesting about the way I think about technology. Sometimes, I get a gut feeling about how something should work, how a product could evolve, or how people's relationship with…

  • Intuitive sense about technology evolution guides exploration
  • Verification process determines worthiness of ideas
  • Focus on building products, not predicting future

More from Sunday 25 October →