When a tool call arrives with arguments you cannot parse, the model is almost never inventing malformed JSON at random. Three causes account for nearly all of it: the arguments...
An insufficient_quota error is a billing problem wearing a rate-limit costume. It arrives as HTTP 429, the same status as an ordinary rate limit, but it means your account has...
Usually the JSON is not invalid, it is incomplete or wrapped in prose. Regex repair is a symptom of not using constrained output.
If the reply stops mid-sentence the model did not fail, it hit your output ceiling. The response is a 200, so most code never notices.
A 529 is not your fault and there is nothing in the request to fix. It is retryable, but retrying badly makes an overloaded service worse.
A 401 is almost never a wrong key. It is usually a stale environment variable, whitespace, the wrong header, the wrong organisation, or a rotated key.
A 429 means either you are sending too fast, which backoff fixes, or your account has no credit, which retrying never fixes. Read the error code first.
The request failed because input tokens plus reserved max_tokens exceed the model's context window. Here is the arithmetic, the fixes in order of cost, and current context limits.

