An HTTP proxy for the Google Gemini image-generation API. It accepts a simple JSON request, forwards it to Gemini, and returns the first generated image as base64.
POST / with a JSON body:
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | yes | The text prompt. |
mode | string | yes | "generate" or "edit". |
imageData | string | yes for edit | Base64-encoded source image (no data URI). |
imageMime | string | optional | MIME type of the source image (image/png). |
- generate ā sends only the text prompt.
- edit ā sends the image data first, then the text prompt.
generationConfig.responseModalities is set to ["TEXT", "IMAGE"].
{ "imageData": "<base64>", "mimeType": "image/png" }
GET /returns a JSON status message.OPTIONS /handles the CORS preflight.- Every response returns HTTP 200 with permissive CORS headers ā errors are
reported in the JSON body (
{ "error": "..." }), never via the status code.
The API key is read from an environment variable (never hardcoded):
š Add GEMINI_API_KEY here: https://www.val.town/x/maoyvi/gemini-image-proxy/environment-variables?key=GEMINI_API_KEY
The originally requested model gemini-2.0-flash-preview-image-generation is no longer
served at generateContent (returns 404). This proxy uses gemini-2.5-flash-image, the
current model supporting image output via generateContent. Image generation requires a
Gemini API key with billing enabled ā free-tier keys return 429 RESOURCE_EXHAUSTED.
curl -X POST https://maoyvi--36ff510265c311f1ba5c1607ee4eb77e.web.val.run \ -H "Content-Type: application/json" \ -d '{"prompt":"a tiny red cube on a white background","mode":"generate"}'