This repository is a reference implementation for a Hackathon 2026 poster generation project.
It demonstrates how to use Python with the OpenRouter API and the model:
google/gemini-3.1-flash-image-preview
If you want examples in other SDKs/languages, see the official OpenRouter API page:
- Calling OpenRouter from Python via the OpenAI-compatible client
- Building multimodal user input:
- pure text
- pure image
- text + multiple images
- Sending local image files (auto-encoded to Base64 data URLs)
- Decoding generated Base64 image outputs and saving to disk
example.py: main reference scriptresource/: input image assets for promptsgenerated_images/: output folder for generated poster images
- Python 3.10+
openaiPython package
Install dependency:
pip install openai- Open
example.py - Set your OpenRouter API key:
API_KEY = "ENTER_YOUR_KEY_HERE"- Configure input mode and prompt:
INPUT_MODE = "text+image" # "pure text" | "pure image" | "text+image"
INPUT_TEXT = "Your poster instructions..."
INPUT_IMAGES = ["resource/flyer.jpeg", "resource/speaker image.jpg"]- Run:
python example.pyGenerated images will be saved in generated_images/.
Use only a text prompt:
INPUT_MODE = "pure text"
INPUT_TEXT = "Design a clean academic seminar poster..."
INPUT_IMAGES = []Use one or more reference images without text:
INPUT_MODE = "pure image"
INPUT_IMAGES = ["resource/flyer.jpeg"]Combine instructions with one or more references:
INPUT_MODE = "text+image"
INPUT_TEXT = "Create a CS seminar poster in this style..."
INPUT_IMAGES = ["resource/flyer.jpeg", "resource/speaker image.jpg"]To check the remaining credit for a specific key, you can call the key information endpoint and read the limit_remaining field from the returned JSON. Replace YOUR_API_KEY in the following command with the API key you have.
Example:
curl https://openrouter.ai/api/v1/auth/key -H "Authorization: Bearer YOUR_API_KEY" | python3 -c "import sys, json; print(json.load(sys.stdin)['data']['limit_remaining'])"- This repo is meant as reference code for hackathon development, not a production-ready framework.
- Keep your API key private. Do not commit real keys to public repositories.
- Model behavior and output format may change over time; always verify against the latest OpenRouter docs.
- OpenRouter model API page: https://openrouter.ai/google/gemini-3.1-flash-image-preview/api