Image generation
greenrouter exposes image models (gpt-image-2, gemini-3.1-flash-image) through
OpenAI-compatible image endpoints: /v1/images/generations (text → image) and
/v1/images/edits (image-to-image with reference images). Both are live and
authenticate with an sk-ru-… key, exactly like chat.
Endpoints
POST https://api.ru-llm.relay2.xyz/v1/images/generationsPOST https://api.ru-llm.relay2.xyz/v1/images/editsGenerate an image
curl https://api.ru-llm.relay2.xyz/v1/images/generations \ -H "Authorization: Bearer sk-ru-YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-image-2", "prompt": "A red panda coding at a laptop, soft studio lighting", "n": 1, "size": "1024x1024", "quality": "high" }'| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Image model ID — gpt-image-2 or gemini-3.1-flash-image. |
prompt | string | Yes | Text description of the image to generate. |
n | integer | No | Number of images to generate. Default: 1. |
size | string | No | Output resolution. gpt-image-2 accepts 1024x1024, 1536x1024, 1024x1536, and auto. |
quality | string | No | Rendering quality for gpt-image-2: low, medium, high, or auto. |
Response
The response follows the OpenAI images envelope. gpt-image-2 always returns
base64-encoded image data (b64_json); the gateway relays the payload
unchanged.
{ "created": 1710000000, "data": [ {"b64_json": "iVBORw0KGgoAAAANSUhEUgAA..."} ], "usage": { "input_tokens": 42, "output_tokens": 1568 }}Decode the first image to a PNG file:
curl ... | python3 -c "import sys,json,base64; \open('out.png','wb').write(base64.b64decode(json.load(sys.stdin)['data'][0]['b64_json']))"Image-to-image (edits)
To transform or extend an existing image, send a multipart/form-data request to
/v1/images/edits with one or more reference images and a prompt. This is the
surface for image-to-image and inpainting.
curl https://api.ru-llm.relay2.xyz/v1/images/edits \ -H "Authorization: Bearer sk-ru-YOUR_KEY" \ -F model="gpt-image-2" \ -F prompt="Put the panda on a snowy mountain at dawn" \ -F image[]="@panda.png" \ -F size="1024x1024"| Form field | Required | Description |
|---|---|---|
model | Yes | Image model ID (gpt-image-2). |
prompt | Yes | What to change or generate from the reference image(s). |
image[] | Yes | One or more reference image files (the source to edit). |
mask | No | Optional PNG mask marking the editable region (inpainting). |
n, size, quality | No | Same meaning as in generations. |
The response is the same OpenAI images envelope (base64 b64_json) as generations.
Billing
Billing basis depends on the model — see the Models & Pricing page and the console Pricing page for live rates.
gpt-image-2is billed per token, on theinput_tokens/output_tokensthe responseusageblock reports. Those counts scale withsizeandquality, so token billing is naturally resolution- and quality-aware.gemini-3.1-flash-imageis billed per generated image (theper_imagerate), charged once per image in thedataarray.
The charge settles against a fail-closed funds hold, so a zero-balance account is
rejected with 402 before the request reaches the provider.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
401 Unauthorized | Key missing or wrong | Pass a valid sk-ru-… key. |
402 Payment Required | Zero balance | Top up in the console → Billing. |
400 not an image model | Model ID is a chat/embedding model | Use gpt-image-2 or gemini-3.1-flash-image. |
400 unknown model | Model ID not in the catalog | Check GET /v1/models. |
400 expected multipart | /v1/images/edits sent as JSON | Send edits as multipart/form-data (use -F, not -d). |