Skip to content

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/generations
POST https://api.ru-llm.relay2.xyz/v1/images/edits

Generate 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"
}'
FieldTypeRequiredDescription
modelstringYesImage model ID — gpt-image-2 or gemini-3.1-flash-image.
promptstringYesText description of the image to generate.
nintegerNoNumber of images to generate. Default: 1.
sizestringNoOutput resolution. gpt-image-2 accepts 1024x1024, 1536x1024, 1024x1536, and auto.
qualitystringNoRendering 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 fieldRequiredDescription
modelYesImage model ID (gpt-image-2).
promptYesWhat to change or generate from the reference image(s).
image[]YesOne or more reference image files (the source to edit).
maskNoOptional PNG mask marking the editable region (inpainting).
n, size, qualityNoSame 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-2 is billed per token, on the input_tokens / output_tokens the response usage block reports. Those counts scale with size and quality, so token billing is naturally resolution- and quality-aware.
  • gemini-3.1-flash-image is billed per generated image (the per_image rate), charged once per image in the data array.

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

SymptomCauseFix
401 UnauthorizedKey missing or wrongPass a valid sk-ru-… key.
402 Payment RequiredZero balanceTop up in the console → Billing.
400 not an image modelModel ID is a chat/embedding modelUse gpt-image-2 or gemini-3.1-flash-image.
400 unknown modelModel ID not in the catalogCheck GET /v1/models.
400 expected multipart/v1/images/edits sent as JSONSend edits as multipart/form-data (use -F, not -d).