Skip to content
Docs ·Image generation

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:1
  • image_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 either low, medium, high, or auto. If the number is small, it’s medium. 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.

ModelsInputText PrintingImage OutputOne picture (1K)
google/gemini-nano-banana-2.12,430 credits12,150 credits48,600 creditsAbout 54.4 credits
google/gemini-3-pro-image3,240 credits19,440 credits194,400 creditsAbout 217.7 credits
google/gemini-3.1-flash-image810 credits4,860 credits97,200 creditsAbout 108.9 credits
google/gemini-3.1-flash-lite-image405 credits2,430 credits48,600 creditsAbout 54.4 credits
qwen/qwen-image-3.0-pro0 credits57,857 credits57,857 creditsAbout 64.8 credits
qwen/qwen-image-3.00 credits43,393 credits43,393 creditsAbout 48.6 credits
qwen/qwen-image-2.1-pro0 credits57,857 credits57,857 creditsAbout 64.8 credits
qwen/qwen-image-2.1-turbo0 credits23,143 credits23,143 creditsAbout 25.9 credits
alibaba/wan-2.7-image-pro0 credits108,482 credits108,482 creditsAbout 121.5 credits
alibaba/wan-2.7-image0 credits43,393 credits43,393 creditsAbout 48.6 credits
alibaba/z-image-turbo0 credits21,696 credits21,696 creditsAbout 24.3 credits
openai/gpt-image-2.5-sunburst8,100 credits48,600 credits48,600 creditsAbout 54.4 credits
openai/gpt-image-2.5-flare8,100 credits48,600 credits48,600 creditsAbout 54.4 credits
openai/gpt-image-28,100 credits48,600 credits48,600 creditsAbout 54.4 credits
openai/gpt-image-1.58,100 credits16,200 credits51,840 creditsAbout 58.1 credits
openai/gpt-image-1-mini3,240 credits12,960 credits12,960 creditsAbout 14.5 credits
black-forest-labs/flux.2-pro0 credits43,393 credits43,393 creditsAbout 48.6 credits
black-forest-labs/flux.2-flex0 credits72,321 credits72,321 creditsAbout 81 credits
black-forest-labs/flux-1.1-pro0 credits57,857 credits57,857 creditsAbout 64.8 credits
black-forest-labs/flux.1-kontext-pro0 credits57,857 credits57,857 creditsAbout 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 stream enabled, images are returned in one response when generation is complete. Look for them in delta.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_filter error. For other models, there may be no graphical representation, and the value of finish_reason can be changed to content_filter. Please resend the request with the correct information.
  • tools, response_format, n, temperature are 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.)