Image generation
Create and edit images with text prompts
The model that creates the images is called “Dialogue” and has an address of POST https://alprouter.com/api/v1/chat/completions. When we send text containing the content that needs to be displayed in the image, the image will be stored at the address message.images.
import base64
from openai import OpenAI
client = OpenAI(
base_url="https://alprouter.com/api/v1",
api_key="alp-your-key",
)
answer = client.chat.completions.create(
model="google/gemini-nano-banana-2.1",
messages=[{"role": "user", "content": "Please draw a paper airplane that flies over the sunset-hued sea."}],
)
# data:image/png;base64,... format. Depending on the model JPEGmay also be returned
url = answer.choices[0].message.images[0]["image_url"]["url"]
kind = url.split(";")[0].split("/")[1]
with open(f"image.{kind}", "wb") as file:
file.write(base64.b64decode(url.split(",", 1)[1]))The form of the answer
The image is located at the address data:image/png;base64,…. If you decode the file name using base64 from the commas that follow, you’ll get the image file. If there is any text added to the model description, it will be included in content.
{
"choices": [
{
"message": {
"role": "assistant",
"content": "",
"images": [
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgo..." } }
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 23,
"completion_tokens": 1811,
"completion_tokens_details": { "reasoning_tokens": 691, "image_tokens": 1120 },
"cost": 0.038817
}
}The images that are created are not saved. Please save the files immediately upon receiving the answers.
The proportions and size of the images
It’s set to image_config. If the value isn’t very high, the model will choose it automatically.
{
"model": "google/gemini-nano-banana-2.1",
"messages": [{ "role": "user", "content": "A snow-covered mountain landscape" }],
"image_config": { "aspect_ratio": "16:9", "image_size": "2K" }
}aspect_ratio:1:1,3:2,2:3,3:4,4:3,4:5,5:4,9:16,16:9,21:9,1:4,4:1,1:8,8:1image_size:1K,2K,4K. There are sizes that are not accepted by the model. If a size that isn’t accepted is sent, it will be marked as “400”.modalities: If it’s not very many, then it’s["image", "text"]. If I just want to receive images without any text, then I’ll send it to["image"].quality: It only accepts GPT Image models. It can be eitherlow,medium,high, orauto. If the number is small, it’smedium. The higher the quality, the more image tokens will be generated.
The GPT Image and FLUX models are created in a 1K size. The proportions are in the form of square boxes: 1:1, 3:2, and 2:3. 4:3·16:9 represents the width, while 3:4·9:16 represents the height. The GPT Image can modify images (up to 4 images at a time). If no proportions are specified, it will use the proportions of the received image. FLUX, on the other hand, only deals with converting text into images. The images sent to the GPT Image are calculated based on the image input price.
The Alibaba Cloud graphic model is created using 1K and 2K. The default size is 1K. The proportions are chosen from the options provided: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3. If there are no graphics involved, and only the proportions are used, then a square will be created.
Repairing the picture
Please replace the image with image_url. Also, write down the text that will replace the image. The image can be sent using a https URL or a data URL. The way to send it is similar to what’s shown in Images and documents.
{
"model": "google/gemini-nano-banana-2.1",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "Change the sky to a starry night" },
{ "type": "image_url", "image_url": { "url": "data:image/png;base64,iVBORw0KGgo..." } }
]
}
]
}You can continue editing the image in the same conversation. Keep images in the assistant message when sending the next request.
The Qwen Image 3.0·2.1 series and the Wan 2.7 Image series use the last three images in the input set as the final images. If no ratios are specified, Qwen will choose the image with the closest ratio to the last image in the set. In contrast, Wan will follow the ratio of the input image. Z-Image Turbo, on the other hand, creates images based on text descriptions.
Fees
The images are also calculated as tokens. One image of a size of 1K corresponds to 1,120 tokens. The cost of larger images varies depending on the model used. The price of image tokens is higher than that of text tokens, so it’s calculated separately. The number of tokens used can be determined using usage.completion_tokens_details.image_tokens.
Qwen Image 3.0 and 3.0 Pro also have a charge for the input images. In the case of 3.0 Pro, the cost of 2K output is higher than that of 1K output. For the other Alibaba Cloud image models, the prices for both 2K and 1K outputs are the same. In contrast, models like 2.1 and Wan do not charge any additional fee for the input images.
| Models | Input | Text Printing | Image Output | One picture (1K) |
|---|---|---|---|---|
google/gemini-nano-banana-2.1 | 2,430 credits | 12,150 credits | 48,600 credits | About 54.4 credits |
google/gemini-3-pro-image | 3,240 credits | 19,440 credits | 194,400 credits | About 217.7 credits |
google/gemini-3.1-flash-image | 810 credits | 4,860 credits | 97,200 credits | About 108.9 credits |
google/gemini-3.1-flash-lite-image | 405 credits | 2,430 credits | 48,600 credits | About 54.4 credits |
qwen/qwen-image-3.0-pro | 0 credits | 57,857 credits | 57,857 credits | About 64.8 credits |
qwen/qwen-image-3.0 | 0 credits | 43,393 credits | 43,393 credits | About 48.6 credits |
qwen/qwen-image-2.1-pro | 0 credits | 57,857 credits | 57,857 credits | About 64.8 credits |
qwen/qwen-image-2.1-turbo | 0 credits | 23,143 credits | 23,143 credits | About 25.9 credits |
alibaba/wan-2.7-image-pro | 0 credits | 108,482 credits | 108,482 credits | About 121.5 credits |
alibaba/wan-2.7-image | 0 credits | 43,393 credits | 43,393 credits | About 48.6 credits |
alibaba/z-image-turbo | 0 credits | 21,696 credits | 21,696 credits | About 24.3 credits |
openai/gpt-image-2.5-sunburst | 8,100 credits | 48,600 credits | 48,600 credits | About 54.4 credits |
openai/gpt-image-2.5-flare | 8,100 credits | 48,600 credits | 48,600 credits | About 54.4 credits |
openai/gpt-image-2 | 8,100 credits | 48,600 credits | 48,600 credits | About 54.4 credits |
openai/gpt-image-1.5 | 8,100 credits | 16,200 credits | 51,840 credits | About 58.1 credits |
openai/gpt-image-1-mini | 3,240 credits | 12,960 credits | 12,960 credits | About 14.5 credits |
black-forest-labs/flux.2-pro | 0 credits | 43,393 credits | 43,393 credits | About 48.6 credits |
black-forest-labs/flux.2-flex | 0 credits | 72,321 credits | 72,321 credits | About 81 credits |
black-forest-labs/flux-1.1-pro | 0 credits | 57,857 credits | 57,857 credits | About 64.8 credits |
black-forest-labs/flux.1-kontext-pro | 0 credits | 57,857 credits | 57,857 credits | About 64.8 credits |
The input and output prices are based on 1 million tokens. The tokens that were considered during the model design are also taken into account when calculating the output price.
Things to know:
- Even with
streamenabled, images are returned in one response when generation is complete. Look for them indelta.images. - It usually takes a few seconds to tens of seconds to complete the drawing. The Qwen Image 3.0 series can take almost a minute to complete one image. Please set a reasonable time limit for the request.
- If it violates Alibaba Cloud’s safety standards, Alibaba Cloud will report it as an
content_filtererror. For other models, there may be no graphical representation, and the value offinish_reasoncan be changed tocontent_filter. Please resend the request with the correct information. tools,response_format,n,temperatureare not accepted.- The model used for creating the image can only be referenced as
/chat/completions. - The images created by the AI are not marked with any indication that they were created by the AI. (This is something that the supplier has added.)