Free AI Image Generation with OpenRouter and Gemini Nano-Banana: Create Stunning Images Using Text Prompts and Base64 Decoding
A new combination of free AI tools is making image generation more accessible than ever. By pairing OpenRouter’s unified API platform with Google’s latest image model, Gemini 2.5 Flash Image—dubbed “Nano-Banana” in playful circles—users can now create high-quality AI-generated images without cost or complex setup. The Nano-Banana model, officially known as Gemini 2.5 Flash Image, stands out for its ability to preserve the core identity of original images while applying creative edits. In a test, a photo of the author’s dog Pepe was transformed into a 90s sitcom dad with a hat and cape—still clearly recognizable as Pepe, with no distortions or glitches. This consistency comes from the model’s strong memory of the source image, a key improvement over other AI tools that often lose the original’s essence. The model runs through OpenRouter, a free API aggregator that connects to over 300 language and image models. OpenRouter’s model routing feature ensures reliability: if one endpoint fails or is overloaded, the system automatically switches to a backup, keeping requests flowing. This is especially valuable in regions like China, where access to major platforms like Google or GitHub is restricted. To use the model, users need only a few simple steps. First, install required packages: Pillow for image handling and requests for API communication. Then, send a prompt to the OpenRouter API using the model identifier google/gemini-2.5-flash-image-preview:free. The response returns a Base64-encoded string representing the generated image. Base64 encoding is used because APIs typically transmit data in text format, and images are binary. Converting them to Base64 allows safe transmission in JSON payloads. While this method increases file size, it simplifies integration across systems. To turn the Base64 string back into a visible image, decode it using Python’s base64 and PIL libraries. The decoded byte stream is loaded into a PIL Image object and can be saved or displayed directly. Two reusable functions streamline the process: one generates the image from a prompt and returns the Base64 string, the other takes that string, decodes it, and saves the image with a user-defined filename. These functions can be wrapped in a simple loop to generate multiple images interactively. Despite its strengths, the current version only supports fixed 1024x1024 pixel outputs, and aspect ratio customization remains unsupported. Free users are limited to 20 requests per minute and 1,000 per day if they have at least 10 credits. Higher usage is capped by Cloudflare’s DDoS protection, which blocks unusually high traffic. Overall, this setup offers a powerful, low-cost way to experiment with AI image generation. With the combination of OpenRouter’s reliability and Gemini Nano-Banana’s creative precision, anyone with a basic Python setup can turn ideas into visuals—no Photoshop required.