Back to Services
Endpoints

ImaGen

POSThttps://api.onlysq.ru/ai/imagen

Generates an image based on the user's description.

Starting with patch 4.0.1 (November 29, 2025), every request to v2/imagen must have Authorization header.

json
{"Authorization": "Bearer apikey"}

Basic API key is openai.

Request

This endpoint expects an object.

  • model (string, required)

    The model name.

  • prompt (string, required)

    Description of what to generate.

  • ratio (string, optional)

    Aspect ratio. One of: 1:1, 16:9, 21:9, 3:2, 2:3, 4:5, 5:4, 3:4, 4:3, 9:16, 9:21. Default: 1:1.

Response

  • id (string) - Unique identifier.
  • created (int) - UNIX timestamp.
  • model (string) - Model that processed the request.
  • files (list) - Base64-encoded images.
  • size (dict) - width, height.
  • elapsed-time (float) - Time spent on generation.
  • usage (int) - Token-like counter from size.
  • user (int) - User id by API key.

Request Example

python
import requests, base64

h = {"Authorization": "Bearer openai"}
j = {
    "model": "flux",
    "prompt": "cat on a blue water wave",
    "ratio": "16:9"
}

r = requests.post("https://api.onlysq.ru/ai/imagen", json=j, headers=h)
r.raise_for_status()
c = r.json()

with open('pic.png', 'wb') as f:
    f.write(base64.b64decode(c["files"][0]))

print("Image saved successfully")

Generated Image Example

Executing the example saves the cat to pic.png

Generated cat on a blue water wave

prompt: "cat on a blue water wave" | model: flux | ratio: 16:9

Response Example

json
{
  "id": "imagen_u1nW43V9wAaWenrHifdqkzxSLNWIpXLVBMzJ4fnBsyNMx94w",
  "created": 1753881206,
  "model": "flux",
  "files": ["base64..."],
  "ratio": "16:9",
  "elapsed-time": 3.20550274848938,
  "usage": 152,
  "user": 0
}