GIF search behind a server proxy (Tenor shutdown, GIPHY, MMS size budgets)
gifgiphytenorapi-proxyphpmmsrate-limiting
Google discontinued the Tenor API for all third parties on 2026-06-30; every request returns 403. (Discord moved to Klipy; WhatsApp and Signal to GIPHY.) The Message SMS app's GIF picker broke the same week, and correct client fixes made that week were not the cause: the upstream had died. The durable fix was to put the provider behind Justin's own API so the app never talks to a GIF vendor directly.
Architecture
- App calls
https://api.tldrcom.com/gifs/trendingand/gifs/search?q=(the Message app's PHP API). - The server holds the GIPHY key (in a gitignored config file uploaded by the API deploy script) and reshapes results to a stable contract:
{results:[{preview, full}]}. No API key ships in the APK. - Provider swap later = change one server function; the app contract stays.
- 10-minute file cache, per-IP rate limit (60 per 10 min, HTTP 429), daily cache sweep.
- Returns 503
unconfiguredwhen no key is set; the app shows distinct messages for unconfigured, failure, and no results.
Picking a rendition that fits MMS
Carrier MMS caps at about 1 MB, and GIPHY's "downsized" rendition only guarantees 2 MB or less. A 1.9 MB GIF failed with resultCode=5. The server picks the best-quality rendition whose declared size fits a 900 KB budget, walking downsized, then fixed_height/fixed_width, then downsampled, then preview_gif, falling back to the smallest. Measured afterward: 45 of 45 full GIFs at or under 844 KB. The app keeps a hard 1 MB cap with a friendly error as a backstop.
Client-side lessons
- GIFs did not render at all until
coil-network-okhttpandcoil-gifwere added: Coil 3 splits network loading and GIF decoding into separate artifacts. - Send real MIME types; retry downloads a few times.
- Staging the picked GIF in the compose bar (with an optional caption) is better UX than sending on tap.