grok-imagine-image
Grok Imagine Imageは、画面の形と1Kまたは2Kの解像度を選び、テキストの説明から画像を作成します。正方形、縦長、ワイドなビジュアルに適しています。
モデルについて
この説明はモデルの機能を紹介するものです。Ailootで利用できる入力、出力、オプションは、選択したメソッドごとに以下に記載されています。
Grok Imagine Imageは、視覚的な生成のためのxAIのモデルです。シーンのテキスト説明を画像に変換します。モデル自体には元画像を扱う視覚入力もありますが、公表されたAilootの生成メソッドでは、入力はテキストのリクエストです。
一つのアイデアのバリエーション
一回のリクエストでは、nで1〜10枚の画像を指定できます。数を指定しない場合は、一枚を作成します。一つの説明に複数のバリエーションが必要な場合に便利です。別々の独立したシーンには、個別の説明を指定します。
画面の形と解像度
正方形の1:1、横長の16:9、縦長の9:16、4:3と3:4、写真の比率の3:2と2:3を選べます。autoは、説明からモデルが比率を選ぶモードで、既定で使用します。
生成には1Kと2Kが用意され、明示的に選ばない場合は1Kを使います。解像度とアスペクト比は、別々に設定します。前者は画像のサイズ、後者は画面の形を定めます。
視覚的な素材を扱う
xAIの視覚モードでは、元画像にテキストの指示を加えます。シーンの内容や見た目の変更を指定します。一回の編集結果を次の編集に使い、細部を段階的に調整できます。このモデル自体のモードは、公表されたテキストからの生成とは異なります。
モデルは画像を返します。結果の送信には、リンク先のファイルまたはbase64の画像データが用意されています。qualityでlow、medium、autoを選ぶ機能は、Image 2.0に関するもので、Grok Imagine Imageには適用されません。
Ailoot · 画像 POST /v1/images/generations grok-imagine-image
grok-imagine-imageはじめに
Grok Imagine Imageは、画面の形と1Kまたは2Kの解像度を選び、テキストの説明から画像を作成します。正方形、縦長、ワイドなビジュアルに適しています。
- 対応する入力
- テキスト
- 結果
- 画像
Ailootで利用可能 · 入力とメソッド
Ailoot · 画像 POST /v1/images/generations
- 入力の種類
text- 出力の種類
image- 出力形式
- 画像ファイル
| フィールド | 種類 | 要件 | 値と制限 | デフォルト |
|---|---|---|---|---|
フィールドmodel | 種類string | 要件必須 | 値と制限 grok-imagine-image | デフォルト— |
フィールドprompt | 種類string | 要件必須 | 値と制限 | デフォルト— |
フィールドn | 種類integer | 要件任意 | 値と制限 最小値: 1 最大値: 10 | デフォルト1 |
フィールドresponse_format | 種類string | 要件任意 | 値と制限 url, b64_json | デフォルトurl |
フィールドresolution | 種類string | 要件任意 | 値と制限 1k, 2k | デフォルト1k |
フィールドaspect_ratio | 種類string | 要件任意 | 値と制限 auto, 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, 21:9, 5:2 | デフォルトauto |
フィールドquality | 種類string | 要件非対応 | 値と制限 | デフォルト— |
入力素材の組み合わせ
テキストから画像へ · 必須: prompt
メソッドのパラメータとライフサイクル
| パラメータ | 仕様 |
|---|---|
パラメータmaterial_types | 仕様text |
パラメータrequired | 仕様model, prompt |
パラメータoptional_controls | 仕様null |
パラメータcontent_type | 仕様application/json |
ライフサイクル: synchronous_result_then_owned_library
GET /v1/media/tasks/{task_id} · 実際に返された task_id またはメディアライブラリのレコード
GET /v1/media/assets/{asset_id}/content
GET /v1/media/assets
GET /v1/media/assets/{asset_id}
メソッドの形式とIDは正確に記載しています。供給元の対応能力とリクエストの受け入れは別です。
料金
Ailootのメソッド料金
POST /v1/images/generations- 入力
- $0.002 入力画像あたり
- 出力
- $0.02 1K画像あたり
- 出力
- $0.02 2K画像あたり
Ailootはリクエスト前に見積額を確保します。結果の取得後、実測使用量に基づいて最終料金を精算します。ストリーミング時の精算には最終の使用量記録を使用します。金額の確保と精算の仕組み →
リクエスト例
Ailoot · 画像
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
export AILOOT_API_KEY
export AILOOT_API_KEY
: "${AILOOT_PROMPT_FILE:?Set your actual UTF-8 image brief}"
export AILOOT_PROMPT_FILE
python3 - <<'PY_REQUEST'
import json,os
from pathlib import Path
p=json.loads('{"model": "grok-imagine-image", "prompt": ""}')
f=Path(os.environ["AILOOT_PROMPT_FILE"])
if not f.is_file():raise SystemExit("Choose your actual UTF-8 brief")
p['prompt']=f.read_text(encoding="utf-8")
if not p['prompt'].strip():raise SystemExit("Brief must contain text")
Path("request.json").write_text(json.dumps(p,ensure_ascii=False))
PY_REQUEST
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/images/generations \
-H "Authorization: Bearer $AILOOT_API_KEY" -H 'Content-Type: application/json' \
--data-binary @request.json -D response-headers.txt -o result.json
python3 - <<'PY_RESULT'
import base64, json, os, subprocess
from pathlib import Path
from urllib.parse import urlsplit, urljoin
def save_images(items):
if not items: raise SystemExit("No completed images; retain the full response")
for index, item in enumerate(items):
encoded=item.get("b64_json")
uri=item.get("url", "")
if not encoded and uri.startswith("data:image/"):
header, separator, encoded=uri.partition(",")
if not separator or ";base64" not in header: raise SystemExit("Unsupported image data URI")
if encoded:
raw=base64.b64decode(encoded,validate=True)
elif uri:
uri=urljoin("https://api.ailoot.ai",uri)
parsed=urlsplit(uri)
if parsed.scheme!="https" or not parsed.netloc or parsed.username or parsed.password:
raise SystemExit("Invalid returned image URL")
owned=parsed.netloc=="api.ailoot.ai" and parsed.path.startswith("/v1/media/assets/") and parsed.path.endswith("/content")
args=["curl","--fail-with-body","--silent","--show-error",uri]
if owned: args += ["-H","Authorization: Bearer "+os.environ["AILOOT_API_KEY"]]
temporary=Path(f"image-{index}.bin")
subprocess.run(args+["-o",str(temporary)],check=True)
raw=temporary.read_bytes()
temporary.unlink()
else: raise SystemExit("Image has neither bytes nor URL")
if not raw: raise SystemExit("Empty image result")
ext="png" if raw.startswith(b"\x89PNG") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4]==b"RIFF" and raw[8:12]==b"WEBP" else "svg" if raw.lstrip().startswith((b"<svg",b"<?xml")) else "bin"
Path(f"image-{index}.{ext}").write_bytes(raw)
print("Every returned image saved; complete response metadata retained")
save_images(json.loads(Path("result.json").read_text())["data"])
PY_RESULT
from openai import OpenAI
import base64, json, os, subprocess
from pathlib import Path
from urllib.parse import urlsplit, urljoin
def save_images(items):
if not items: raise SystemExit("No completed images; retain the full response")
for index, item in enumerate(items):
encoded=item.get("b64_json")
uri=item.get("url", "")
if not encoded and uri.startswith("data:image/"):
header, separator, encoded=uri.partition(",")
if not separator or ";base64" not in header: raise SystemExit("Unsupported image data URI")
if encoded:
raw=base64.b64decode(encoded,validate=True)
elif uri:
uri=urljoin("https://api.ailoot.ai",uri)
parsed=urlsplit(uri)
if parsed.scheme!="https" or not parsed.netloc or parsed.username or parsed.password:
raise SystemExit("Invalid returned image URL")
owned=parsed.netloc=="api.ailoot.ai" and parsed.path.startswith("/v1/media/assets/") and parsed.path.endswith("/content")
args=["curl","--fail-with-body","--silent","--show-error",uri]
if owned: args += ["-H","Authorization: Bearer "+os.environ["AILOOT_API_KEY"]]
temporary=Path(f"image-{index}.bin")
subprocess.run(args+["-o",str(temporary)],check=True)
raw=temporary.read_bytes()
temporary.unlink()
else: raise SystemExit("Image has neither bytes nor URL")
if not raw: raise SystemExit("Empty image result")
ext="png" if raw.startswith(b"\x89PNG") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4]==b"RIFF" and raw[8:12]==b"WEBP" else "svg" if raw.lstrip().startswith((b"<svg",b"<?xml")) else "bin"
Path(f"image-{index}.{ext}").write_bytes(raw)
print("Every returned image saved; complete response metadata retained")
f=Path(os.environ["AILOOT_PROMPT_FILE"])
if not f.is_file():raise SystemExit("Set your actual UTF-8 image brief file")
request={'model': 'grok-imagine-image', 'prompt': ''}
request["prompt"]=f.read_text(encoding="utf-8")
client=OpenAI(base_url="https://api.ailoot.ai/v1",api_key=os.environ["AILOOT_API_KEY"],max_retries=0)
result=client.images.generate(**request)
Path("sdk-result.txt").write_text(str(result),encoding="utf-8")
save_images([{"b64_json":getattr(item,"b64_json",None),"url":getattr(item,"url",None)} for item in result.data])
import OpenAI from "openai";
import { readFileSync, writeFileSync } from "node:fs";
const key=process.env.AILOOT_API_KEY;
if(!key) throw new Error("Set your actual Ailoot API key");
const client=new OpenAI({baseURL:"https://api.ailoot.ai/v1",apiKey:key,maxRetries:0});
const request={"model": "grok-imagine-image", "prompt": ""};
if(!process.env.AILOOT_PROMPT_FILE)throw new Error("Set your actual UTF-8 image brief file");
request.prompt=readFileSync(process.env.AILOOT_PROMPT_FILE,"utf8");
const result=await client.images.generate(request);
writeFileSync("sdk-result.json",JSON.stringify(result,null,2));
if(!result.data?.length) throw new Error("No completed images");
for(let index=0;index<result.data.length;index++) {
const item=result.data[index];let encoded=item.b64_json,uri=item.url||"",raw;
if(!encoded && uri.startsWith("data:image/")) {
const comma=uri.indexOf(",");if(comma<0 || !uri.slice(0,comma).includes(";base64")) throw new Error("Unsupported image data URI");
encoded=uri.slice(comma+1);
}
if(encoded) {
if(encoded.length%4!==0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) throw new Error("Invalid Base64");
raw=Buffer.from(encoded,"base64");
} else if(uri) {
const u=new URL(uri,"https://api.ailoot.ai");
if(u.protocol!=="https:" || u.username || u.password) throw new Error("Invalid returned URL");
const owned=u.origin==="https://api.ailoot.ai" && u.pathname.startsWith("/v1/media/assets/") && u.pathname.endsWith("/content");
const response=await fetch(u,{headers:owned?{Authorization:"Bearer "+key}:{},redirect:"manual"});
if(!response.ok) throw new Error("Image content download failed: "+response.status);
raw=Buffer.from(await response.arrayBuffer());
} else throw new Error("Image has neither bytes nor URL");
if(!raw.length) throw new Error("Empty image result");
const ext=raw.subarray(0,4).equals(Buffer.from([137,80,78,71]))?"png":raw[0]===255&&raw[1]===216?"jpg":raw.toString("ascii",0,4)==="RIFF"&&raw.toString("ascii",8,12)==="WEBP"?"webp":raw.toString("utf8").trimStart().startsWith("<svg")||raw.toString("utf8").trimStart().startsWith("<?xml")?"svg":"bin";
writeFileSync(`image-${index}.${ext}`,raw);
}
console.log("Every returned image saved; sdk-result.json retains complete metadata");
結果を受け取って保存
Ailoot · 画像
返された画像をすべてダウンロードするか、Base64の内容を保存
GET /v1/media/tasks/{task_id}GET /v1/media/assets/{asset_id}/contentGET /v1/media/assetsGET /v1/media/assets/{asset_id}
完了した結果をすべて保存
完了した画像をすべて保存してください。返された各URLから取得するか、Base64の内容をデコードしてください。
すべてのデータ項目を保存してください。各 b64_json をデコードするか、返された署名付き URL すべてから取得してください。実際の MIME タイプ/バイト列に応じてファイル名の拡張子を選んでください。
元のレスポンスを確認する場合
画像の生成または編集の結果に確認が必要な場合は、元の operation_id/X-Client-Request-ID と、返された結果情報を保存してください。実際の task_id または asset_id の値を使い、メディアライブラリから自分が所有する既存の結果を取得してください。生成/編集リクエストを再送したり、operation_id からポーリング URL を組み立てたりしないでください。
レスポンスのフィールド
| フィールド | 種類 |
|---|---|
フィールドcreated | 種類integer |
フィールドdata[].url | 種類string |
フィールドdata[].b64_json | 種類base64 string |
フィールドusage | 種類object |
エラーと次の手順
| レスポンス | 条件 | 次の手順 |
|---|---|---|
レスポンス400 · invalid_request_error | 条件必須フィールド、素材の表現形式、またはパラメーター値が不正です | 次の手順新しい生成リクエストを送る前に、指定されたフィールドを修正してください。 |
レスポンスserver_error | 条件返されたレスポンスは、操作または結果の確認が必要であることを示しています | 次の手順最初に返された操作/タスク ID、リクエストヘッダー、レスポンスを保存し、その元の操作に対してサポートされている読み取りを継続してください。作成リクエストを再送しないでください。 |
エイリアス
モデルのエイリアス
Ailoot grok-imagine-image
メソッドパスのエイリアス
上記に表示されたメソッドパスを使用してください。
関連する呼び出し用ID
FAQ · grok-imagine-image
- 利用できる入力と結果は何ですか?
POST /v1/images/generations·grok-imagine-image:text→image- リクエストはどの項目を使用しますか?
POST /v1/images/generations·grok-imagine-image:model,prompt,n,response_format,resolution,aspect_ratio- どの制限が適用されますか?
POST /v1/images/generations·grok-imagine-image:n.minimum:1;n.maximum:10