POST /v1/images/generations
POST/v1/images/generations
テキストプロンプトから画像を生成します。OpenAI DALL-E 互換形式です。
リクエスト
ヘッダー
| ヘッダー | 値 |
|---|
Authorization | Bearer {api_key} |
Content-Type | application/json |
ボディ
{
"model": "imagen-3",
"prompt": "A futuristic city skyline at sunset, digital art",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}
パラメーター
| パラメーター | 型 | 必須 | 説明 |
|---|
model | string | はい | 画像モデル ID。 |
prompt | string | はい | 生成したい画像のテキスト説明。 |
n | integer | いいえ | 画像数。デフォルトは 1。 |
size | string | いいえ | 画像サイズ。例: "1024x1024"。 |
quality | string | いいえ | "standard" または "hd"。 |
response_format | string | いいえ | "url"(デフォルト)または "b64_json"。 |
style | string | いいえ | "natural" または "vivid"。 |
レスポンス
{
"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
}
}
| フィールド | 型 | 説明 |
|---|
created | integer | Unix タイムスタンプ。 |
data[].url | string | 画像 URL(response_format が "url" の場合)。 |
data[].b64_json | string | Base64 画像データ(response_format が "b64_json" の場合)。 |
data[].revised_prompt | string | モデルが解釈したプロンプト。 |
ステータスコード
| ステータス | 説明 |
|---|
200 | 成功 |
400 | 不正なリクエスト、またはモデルが画像生成に非対応 |
401 | 認証なし |
402 | 残高不足 |
502 | 上流プロバイダーエラー |
例
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);