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.

