Generate Images
Create images. Standard image models return data[] synchronously; models configured as async-only return an image task first, then you poll GET /v1/images/generations/{task_id} for the result.
To use the Aliyun-native input / parameters request format, see Aliyun Image Generation.
Try It
/v1/images/generationshttps://api-platform.ope.aiAuthentication
Uses Bearer Token authentication.
- Header:
Authorization: Bearer <token> - Example:
Authorization: Bearer sk-xxxxxx
Request body (application/json)
| Field | Type | Required | Description | Default / Range |
|---|---|---|---|---|
model | string | Yes | Model for image generation | qwen-image-2.0 |
prompt | string | Yes | Text description of the image | - |
n | integer | No | Number of images to generate | Default: 1 |
size | string | No | Generated image size. Use lowercase x between width and height | Default: 1024x1024; example: 1024x1024 |
quality | string | No | Generation quality, passed through to the upstream model | Default: auto |
response_format | string | No | Synchronous response format | Default: b64_json; allowed: b64_json, url |
image | string / array / object | No | Image input. When provided, the request is treated as image edit mode. Supports image URLs, Data URLs/base64, arrays, or objects | - |
output_format | string | No | Output format for GPT Image style models | Passed through when supported by the model |
output_compression | integer | No | Output compression for GPT Image style models | Passed through when greater than 0 |
background | string | No | Background option for GPT Image style models | Passed through when supported by the model |
moderation | string | No | Moderation option for GPT Image style models | Passed through when supported by the model |
style | string | No | Style option for non-GPT Image models | Passed through when supported by the model |
user | string | No | End-user identifier, passed through upstream | - |
sequential_image_generation | string | No | Platform extension for sequential image generation | Allowed: disabled, auto |
watermark | boolean | No | Whether to request a watermark | Default: false |
stream | boolean | No | Streaming extension | true is not supported on the OpenAI image relay yet |
Tip: if
sizeuses a multiplication symbol instead of the letterx, the backend returns a parameter error. Use a value such as1024x1024.
Response modes
| Mode | Trigger | Response | Next step |
|---|---|---|---|
| Synchronous | Standard image models | OpenAI-style created, data[], and usage | Read data[].url or data[].b64_json directly |
| Async task | Model has features.async_only=true | image.generation.task object | Use the returned task_id with Get image generation task |
For async tasks, if the upstream only returns b64_json, the platform stores the image and returns a public url in the task result. Successful task results are retained for 24 hours.
Request examples
The domain below is an example:
https://api-platform.ope.ai.
- cURL
- JavaScript
- Go
- Python
- Java
- C#
curl -X POST "https://api-platform.ope.ai/v1/images/generations" \
-H "Authorization: Bearer $OPEAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-2.0",
"prompt": "Generate an image showcasing AI image generation capabilities.",
"size": "1024x1024",
"n": 1,
"quality": "auto"
}'
const url = "https://api-platform.ope.ai/v1/images/generations";
const apiKey = process.env.OPEAI_API_KEY;
const res = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "qwen-image-2.0",
prompt: "Generate an image showcasing AI image generation capabilities.",
size: "1024x1024",
n: 1,
quality: "auto",
}),
});
console.log(await res.json());
package main
import (
"bytes"
"fmt"
"net/http"
"os"
)
func main() {
body := []byte(`{"model":"qwen-image-2.0","prompt":"Generate an image showcasing AI image generation capabilities.","size":"1024x1024","n":1,"quality":"auto"}`)
req, _ := http.NewRequest("POST", "https://api-platform.ope.ai/v1/images/generations", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("OPEAI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println(resp.Status)
}
import os
import requests
resp = requests.post(
"https://api-platform.ope.ai/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ.get('OPEAI_API_KEY')}",
"Content-Type": "application/json",
},
json={"model": "qwen-image-2.0", "prompt": "Generate an image showcasing AI image generation capabilities.", "size": "1024x1024", "n": 1, "quality": "auto"},
timeout=60,
)
print(resp.json())
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("OPEAI_API_KEY");
String url = "https://api-platform.ope.ai/v1/images/generations";
String json = """
{ "model": "qwen-image-2.0", "prompt": "Generate an image showcasing AI image generation capabilities.", "size": "1024x1024", "n": 1, "quality": "auto" }
""";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
public class Program
{
public static async Task Main()
{
var apiKey = Environment.GetEnvironmentVariable("OPEAI_API_KEY");
var url = "https://api-platform.ope.ai/v1/images/generations";
var json = """
{ "model": "qwen-image-2.0", "prompt": "Generate an image showcasing AI image generation capabilities.", "size": "1024x1024", "n": 1, "quality": "auto" }
""";
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var resp = await http.PostAsync(url, content);
Console.WriteLine((int)resp.StatusCode);
Console.WriteLine(await resp.Content.ReadAsStringAsync());
}
}
Image input example
Clients still call /v1/images/generations. When image is provided, the platform treats the request as image edit mode; OpenAI / Azure upstream channels forward it to the upstream image edit endpoint.
curl -X POST "https://api-platform.ope.ai/v1/images/generations" \
-H "Authorization: Bearer $OPEAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen-image-2.0",
"prompt": "Keep the subject and change the background to a clean product studio.",
"image": "https://example.com/input.png",
"size": "1024x1024",
"quality": "auto"
}'
Response examples
- Sync 200
- Async 200
- Error
{
"created": 1777440000,
"data": [
{
"url": "https://example.com/generated-image.png",
"b64_json": "",
"revised_prompt": "Generate an image showcasing AI image generation capabilities."
}
],
"usage": {
"generated_images": 1,
"total_tokens": 100,
"input_tokens": 24,
"output_tokens": 76,
"input_tokens_details": {
"text_tokens": 24,
"image_tokens": 0
}
}
}
{
"id": "image_2f9b9a3d8c1e4f5a6b7c8d9e",
"task_id": "image_2f9b9a3d8c1e4f5a6b7c8d9e",
"object": "image.generation.task",
"status": "QUEUED",
"created_at": 1777440000,
"model": "gpt-image-2",
"prompt": "Generate an image showcasing AI image generation capabilities.",
"size": "1024x1024",
"quality": "auto",
"mode": "generation"
}
{
"error": {
"message": "response_format must be one of: b64_json, url",
"type": "invalid_request_error",
"code": "invalid_image_request"
}
}