Gemini-heal – rate limiting and MALFORMED_FUNCTION_CALL recovery for Gemini API
3 points
2 hours ago
| 1 comment
| github.com
| HN
emotixco
2 hours ago
[-]
We've been running Gemini in production at Emotix (AI research platform) for a few months. Three issues kept hitting us:

1. MALFORMED_FUNCTION_CALL — Gemini's function calling silently breaks when tool arguments contain large strings. Google acknowledged it as a P2 bug, still open. Adding a JSON-escaping instruction to the prompt cuts it by ~90%. When that's not enough, falling back to responseMimeType + responseSchema bypasses the broken code path entirely.

2. 429s with no backoff — The SDK throws but doesn't help you recover. We built an adaptive token-bucket that halves RPM on each 429 and slowly recovers, plus a circuit breaker for when the queue gets too deep.

3. JSON in markdown blocks — Even with responseMimeType: 'application/json', Gemini sometimes wraps output in ```json``` blocks. Small thing but breaks JSON.parse in production.

We extracted all three fixes into a standalone library.

Zero dependencies. TypeScript. MIT.

GitHub: https://github.com/emotix/gemini-heal npm: npm install gemini-heal

reply