Hello Team,
I am developing an Android application using Kotlin, Firebase Vertex AI, and the Gemini Flash model for image analysis. Recently, the app has been failing intermittently with the following errors in the Firebase console:
UNAVAILABLE
DECODE_PREEMPTED (“Preempted out of decode queue by a higher priority request”)
INTERNAL
Is this happening due to server-side bottlenecks or capacity limits on the free tier? How can we handle or mitigate these preemption errors in an Android/Kotlin production environment?
Any guidance or best practices would be greatly appreciated. Thank you!
DECODE_PREEMPTED says it directly: your request was bumped from the decode queue by higher-priority traffic. So it’s capacity on Google’s side, not your code. Paid tiers get priority, so on the free tier you’ll likely see it most att peak hours.
What worked for us in a mobile image-analysis app with a Gemini step:
- Treat UNAVAILABLE, DECODE_PREEMPTED and 503 as retryable. Backoff with jitter, 2 to 3 tries, then fall back to a different pinned model version. Retry INTERNAL once at most.
- Pin a model version instead of a -latest alias. Almost all our overload errors came from the alias.
- Downscale images before sending. Smaller requests spend less time in prefill. Firebase AI Logic also has a media resolution setting now.
- Log error code, model name and latency per request on the client, with a request id. Then you can see whethe failures cluster by model, time of day or region instead of guessing.
That last point is why we built end-to-end traces into WildEdge.dev (disclosure: I work on it). Each scan is one trace with the on-device models and the Gemini call side by side, so you can tell whether a slow or failed result came from the phone or the API.
Hello,
UNAVAILABLE (503) errors are unrelated to your quota. They mean the service is temporarily overloaded and can’t serve your request, and they are more common at certain times of the day. Please see this pinned post for how to handle them. In short: add backoff and retry in your app, starting with a small number of retries and a short timeout and increasing them if the errors continue.
INTERNAL (500) errors mean an unexpected error occurred on the server, and the API errors guide recommends retrying the request.
Your app calls Gemini through Firebase AI Logic. For questions about the Firebase SDK or the Firebase console, please contact Firebase Support.