バッチ
POST /v1/renders/batch は単一のリクエストで最大 50 個のイメージをレンダリングします。アイテムは並行して実行され、アイテムごとに課金されます。1つのアイテムで失敗が発生しても、他のアイテムは中止されません。
# 2つの形式
1つのテンプレート、複数の変更セット — 一般的なケース:
curl https://api.mostlyrender.com/v1/renders/batch \
-H "Authorization: Bearer mr_live_…" \
-H "Content-Type: application/json" \
-d '{
"template": "tpl_abc",
"output": "png",
"items": [
{ "title": "One" },
{ "title": "Two" },
{ "title": "Three" }
]
}'
各アイテムは modifications オブジェクト、または { "modifications": {…}, "output": "…" } の形式でアイテムごとにフォーマットをオーバーライドできます。
異なるレンダリング — 1回の呼び出しで異なるテンプレート:
{
"renders": [
{ "template": "tpl_a", "modifications": { "title": "A" }, "output": "png" },
{ "template": "tpl_b", "modifications": { "title": "B" }, "output": "pdf" }
]
}
# レスポンス
{
"results": [
{ "id": "rnd_1", "url": "https://img.mostlyrender.com/mostlyrender/renders/rnd_1.png", "output": "png" },
{ "error": "render failed" }
],
"count": 2,
"ok": 1
}
results は位置指定です — 各エントリはレンダリング結果または { "error" } オブジェクトのいずれかです。count は処理合計数です。ok は成功した数です。
# SDK
res = mr.render_batch(
template_id="tpl_abc",
output="png",
items=[{"title": "One"}, {"title": "Two"}, {"title": "Three"}],
)
print(res["count"], res["ok"])
50を超えるバッチの場合は、複数のリクエストに分割するか、非同期ジョブを使用してください。