# google_ai: Improve error messages and handle retries \(\#64865\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/fa6aeecf2ac2bc7a631aef80e0ce9abcc0737266)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: fa6aeecf2ac2bc7a631aef80e0ce9abcc0737266

Requested commit: fa6aeecf2ac2bc7a631aef80e0ce9abcc0737266

Commit: fa6aeecf2ac2bc7a631aef80e0ce9abcc0737266

Tree: 977336e8639361904d727c092a1b034b35628756

Author: Bennet Bo Fenner

Committer: GitHub

## Message

````
google_ai: Improve error messages and handle retries (#64865)

This improves error message handling for Google AI, previously we were
not classifying at all and were always using
`LanguageModelCompletionError::Other(...)`. This has the positive side
effect that we now automatically retry when a model is overloaded (which
very frequently happens with the free flash models).

Before:
```
failed to stream completion: error during streamGenerateContent, status code: 400, body: {
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_INVALID",
        "domain": "googleapis.com",
        "metadata": {
          "service": "generativelanguage.googleapis.com"
        }
      },
      {
        "@type": "type.googleapis.com/google.rpc.LocalizedMessage",
        "locale": "en-US",
        "message": "API key not valid. Please pass a valid API key."
      }
    ]
  }
}
```

After:
```
API key not valid. Please pass a valid API key.
```

Another example, previously we would just show "failed to stream
completion":

<img width="685" height="65" alt="image"
src="https://github.com/user-attachments/assets/76ddde40-9dc0-4093-a6d5-ee3a9dfb7a32"
/>


Release Notes:

- Improved error handling when using Google AI as a provider
````

## Parents

- [ee43be113e362502f8f7c030db5e797126577973](https://git.cafe/gitcafe/zed/commit/ee43be113e362502f8f7c030db5e797126577973?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/fa6aeecf2ac2bc7a631aef80e0ce9abcc0737266?format=markdown)
