feat: add GEMINI_API_KEY and Pollinations.ai fallbacks for image generation#11
Open
nadimtuhin wants to merge 2 commits into
Open
feat: add GEMINI_API_KEY and Pollinations.ai fallbacks for image generation#11nadimtuhin wants to merge 2 commits into
nadimtuhin wants to merge 2 commits into
Conversation
…ration Adds two optional image generation backends that activate before the browser-cookie session, giving users more flexibility and resilience: **1. Google Generative Language API (`GEMINI_API_KEY`)** Set `GEMINI_API_KEY` to a Google AI Studio key to use the official API for text-to-image generation. Tried first when the env var is present. Supports `GEMINI_IMAGE_API_MODEL` override (default: `gemini-2.5-flash-image`). **2. Pollinations.ai fallback (`GEMINI_USE_POLLINATIONS=1`)** Zero-auth, no-key-required fallback via https://pollinations.ai (MIT licence, free tier). Uses `curl_cffi` Chrome impersonation — required because Pollinations blocks plain HTTP clients. Opt-in via env var so existing users are unaffected. Both paths are tried only for simple text-to-image requests (no `files`, no `conversation_id`) and short-circuit before the library session is initialised, so cookie-based editing/chat flows are unchanged. **Why Pollinations?** Users occasionally hit `ImageGenerationBlocked` when image-gen SIDCC has rotated out of Chrome's SQLite store. A zero-auth fallback lets the tool remain useful in those windows without requiring a manual cookie refresh. **New env vars:** - `GEMINI_API_KEY` — Google AI Studio API key - `GEMINI_IMAGE_API_MODEL` — model override for the API path (default: `gemini-2.5-flash-image`) - `GEMINI_USE_POLLINATIONS` — set to `1` to enable Pollinations fallback Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers URL encoding, Chrome impersonation, and error handling for _pollinations_generate_image without requiring network, an API key, or browser cookies — runs in CI as-is. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users hit
ImageGenerationBlockedwhen the image-gen SIDCC rotates out of Chrome's SQLite store between uses. Currently there's no way to generate images in that window without a manual cookie refresh.Solution
Two optional fallback backends, both opt-in via env vars so existing users are completely unaffected:
1. Google AI Studio API key (
GEMINI_API_KEY)Uses the official
generativelanguage.googleapis.comendpoint. Tried first when the env var is present; falls back to the cookie session on 429 or error. Supports an optional model override:2. Pollinations.ai (
GEMINI_USE_POLLINATIONS=1)export GEMINI_USE_POLLINATIONS=1Zero-auth, no-account-required image generation via Pollinations.ai (free, MIT-licenced service). Uses
curl_cffiChrome impersonation — plainurllibgets a 403. Generates images using the Flux model.Behaviour
Both paths are attempted only for simple text-to-image requests (
promptonly, nofiles, noconversation_id). Editing, chat, and file-upload flows are completely unchanged.Priority order when both are configured:
GEMINI_API_KEY— official API, highest qualityGEMINI_USE_POLLINATIONS=1— zero-auth fallbackTesting
Checklist
PermissionErrorhandled gracefully in path checkscurl_cffialready in the dependency tree)🤖 Generated with Claude Code