POST https://api.onlysq.ru/ai/v2
Generates an image based on the user's description.
Request
This endpoint expects an object.
model
string Required
The name of a OnlySq AI model which will process the request
prompt
string Required
A request to the model describing items, landscapes, and other elements that the user wishes to see in the image.
width
int Optional
Width of the desired image, in pixels.
max
: 2048default
: 1024
height
int Optional
Height of the desired image, in pixels.
max
: 2048default
: 1024
count
int Optional
The number of images corresponding to the requested description.
max
: 4default
: 1
Response
id
string
Unique identifier for the generated reply. Useful for submitting feedback.
created
int
Timestamp in UNIX format.
model
string
The model that processed the request.
files
list
The list contains images encoded in base64 utf-8 strings.
size
dict
Contains:
width
intCount of width pixels.
height
intCount of height pixels.
elapsed-time
float
Time spent on generation. Can be translated into another format, such as elapsed_time:.2f
usage
int
Improvised token counter based on image height and width.
user
int
Unique of user by API key. Useful for submitting feedback.
Examples
Request examples
The simplest request example:
import requests, base64
# Use only for images lower or eq 1024x1024
j = {
"model": "kandinsky",
"prompt": "Cat"
}
r = requests.post("https://api.onlysq.ru/ai/imagen", json=j)
c = r.json()
with open('pic.png', 'wb') as f:
f.write(base64.b64decode(c.get("files")[0]))
Request example for high-resolution images (more than 1024x1024):
import requests
import base64
j = {
"model": "kandinsky",
"prompt": "Cat",
"width": 1366,
"height": 768,
"count": 1
}
r = requests.post("https://api.onlysq.ru/ai/imagen", json=j, stream=True)
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")
Executing one of the presented examples will save the image of the cat to the file pic.png.
Response example
{
"id": "imagen_xp0c8AQqE4o1Uu54blAn2hTGdLjpAXpdRplJQYORn9qCZywk",
"created": 1745854652,
"model": "kandinsky",
"count": 3,
"files": [
"base64",
"of",
"pictures"
],
"size": {
"width": 1366,
"height": 768
},
"elapsed-time": 19.22223396191839,
"usage": 1311,
"user": 0
}