POST /v1/images/generations
POST/v1/images/generations
Generates images from a text prompt. OpenAI DALL-E compatible format.
Request
Headers
| Header | Value |
|---|
Authorization | Bearer {api_key} |
Content-Type | application/json |
Body
{
"model": "imagen-3",
"prompt": "A futuristic city skyline at sunset, digital art",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}
Parameters
| Parameter | Type | Required | Description |
|---|
model | string | Yes | Image model ID. |
prompt | string | Yes | Text description of the desired image. |
n | integer | No | Number of images. Default 1. |
size | string | No | Image dimensions, e.g. "1024x1024". |
quality | string | No | "standard" or "hd". |
response_format | string | No | "url" (default) or "b64_json". |
style | string | No | "natural" or "vivid". |
Response
{
"created": 1709123456,
"data": [
{
"url": "https://storage.example.com/generated-image.png",
"revised_prompt": "A futuristic city skyline at golden hour sunset..."
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}
| Field | Type | Description |
|---|
created | integer | Unix timestamp. |
data[].url | string | Image URL (when response_format is "url"). |
data[].b64_json | string | Base64 image data (when response_format is "b64_json"). |
data[].revised_prompt | string | The prompt as interpreted by the model. |
Status codes
| Status | Description |
|---|
200 | Success |
400 | Invalid request or model doesn't support image generation |
401 | Unauthorized |
402 | Insufficient balance |
502 | Upstream provider error |
Examples
curl -X POST https://api.modelmax.io/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MODELMAX_API_KEY" \
-d '{
"model": "imagen-3",
"prompt": "A watercolor painting of a mountain lake",
"n": 1,
"size": "1024x1024"
}'
from openai import OpenAI
client = OpenAI(api_key="your-key", base_url="https://api.modelmax.io/v1")
response = client.images.generate(
model="imagen-3",
prompt="A watercolor painting of a mountain lake",
n=1,
size="1024x1024",
)
print(response.data[0].url)
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "your-key", baseURL: "https://api.modelmax.io/v1" });
const response = await client.images.generate({
model: "imagen-3",
prompt: "A watercolor painting of a mountain lake",
n: 1,
size: "1024x1024",
});
console.log(response.data[0].url);