Generate Template Variants

Generate multiple size variants of a template using AI

Updated

POST
/v1/studio/templates/{templateId}/generate-variants
curl -X POST "https://api.orshot.com/v1/studio/templates/<TEMPLATE_ID>/generate-variants" \
  -H "Authorization: Bearer <ORSHOT_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "variants": [],
    "page_number": 1,
    "output": "<OUTPUT>"
  }'

Generate multiple size variants of an existing studio template using AI-powered layout adaptation. The AI intelligently repositions and resizes elements to fit new dimensions while maintaining visual hierarchy and design integrity.

By default, generated variants are added as new pages to the source template. You can also create them as separate templates using the output parameter.

Endpoint#

Endpoint
https://api.orshot.com/v1/studio/templates/:templateId/generate-variants

Request#

JavaScript
// Add variants as new pages to the same template
await fetch("https://api.orshot.com/v1/studio/templates/12345/generate-variants", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer <ORSHOT_API_KEY>",
  },
  body: JSON.stringify({
    variants: [
      { width: 1080, height: 1080 },
      { width: 1080, height: 1920 }
    ],
    output: "pages"
  }),
});
JavaScript
// Create new templates for each variant
await fetch("https://api.orshot.com/v1/studio/templates/12345/generate-variants", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer <ORSHOT_API_KEY>",
  },
  body: JSON.stringify({
    variants: [
      { width: 1080, height: 1080 },
      { width: 1080, height: 1920 },
      { width: 1200, height: 628 }
    ],
    output: "templates"
  }),
});
JSON
{
  "success": true,
  "source_template_id": "12345",
  "source_page": 1,
  "source_page_id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
  "output_mode": "pages",
  "variants": [
    {
      "variant_index": 0,
      "width": 1080,
      "height": 1080,
      "page_index": 1,
      "page_id": "generated-page-uuid-1",
      "page_name": "Variant 1080x1080"
    },
    {
      "variant_index": 1,
      "width": 1080,
      "height": 1920,
      "page_index": 2,
      "page_id": "generated-page-uuid-2",
      "page_name": "Variant 1080x1920"
    }
  ]
}
JSON
{
  "success": true,
  "source_template_id": "12345",
  "source_page": 1,
  "source_page_id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
  "output_mode": "templates",
  "variants": [
    {
      "variant_index": 0,
      "width": 1080,
      "height": 1080,
      "template_id": 12346,
      "template_name": "(1080x1080) Summer Sale"
    },
    {
      "variant_index": 1,
      "width": 1080,
      "height": 1920,
      "template_id": 12347,
      "template_name": "(1080x1920) Summer Sale"
    },
    {
      "variant_index": 2,
      "width": 1200,
      "height": 628,
      "template_id": 12348,
      "template_name": "(1200x628) Summer Sale"
    }
  ]
}
JSON
{
  "success": true,
  "source_template_id": "12345",
  "source_page": 1,
  "source_page_id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
  "output_mode": "pages",
  "variants": [
    {
      "variant_index": 0,
      "width": 1080,
      "height": 1080,
      "page_index": 1,
      "page_id": "generated-page-uuid-1",
      "page_name": "Variant 1080x1080",
      "thumbnail_url": "https://storage.orshot.com/cloud/w-50/renders/thumbnails/sq1.png"
    },
    {
      "variant_index": 1,
      "width": 1080,
      "height": 1920,
      "page_index": 2,
      "page_id": "generated-page-uuid-2",
      "page_name": "Variant 1080x1920",
      "thumbnail_url": "https://storage.orshot.com/cloud/w-50/renders/thumbnails/st1.png"
    }
  ]
}
JSON
{
  "success": true,
  "source_template_id": "12345",
  "source_page": 1,
  "source_page_id": "a1b2c3d4-5e6f-7890-abcd-ef1234567890",
  "output_mode": "templates",
  "variants": [
    {
      "variant_index": 0,
      "width": 1080,
      "height": 1080,
      "template_id": 12346,
      "template_name": "(1080x1080) Summer Sale",
      "thumbnails": {
        "success": true,
        "pages": [
          {
            "page": 1,
            "page_id": "tpl-1-page-uuid",
            "thumbnail_url": "https://storage.orshot.com/cloud/w-50/renders/thumbnails/sq2.png",
            "error": null
          }
        ]
      }
    },
    {
      "variant_index": 1,
      "width": 1080,
      "height": 1920,
      "template_id": 12347,
      "template_name": "(1080x1920) Summer Sale",
      "thumbnails": {
        "success": true,
        "pages": [
          {
            "page": 1,
            "page_id": "tpl-2-page-uuid",
            "thumbnail_url": "https://storage.orshot.com/cloud/w-50/renders/thumbnails/st2.png",
            "error": null
          }
        ]
      }
    }
  ]
}

Rate Limits#

LimitValue
Requests per minute30
Max variants per request10

The limit is 30 requests per minute per API key, shared by every /v1/studio template endpoint, including template reads. Renders are not counted.

URL Parameters#

ParameterTypeRequiredDescription
templateIdIntegerYesThe ID of the source template to generate variants from

Request Body Parameters#

ParameterTypeRequiredDefaultDescription
variantsArrayYes-Array of target dimensions for variants
page_numberIntegerNo1Which page of the template to use as source
outputStringNo"pages"Output mode: "pages" or "templates"

Variant Object Structure#

Each variant in the variants array should include:

FieldTypeRequiredDescription
widthIntegerYesTarget width in pixels (1-5000)
heightIntegerYesTarget height in pixels (1-5000)
nameStringNoCustom name for the generated page or template. Without it, a page is named Variant <width>x<height> and a template (<width>x<height>) <source template name>

Output Modes#

ModeDescription
pagesAdds each variant as a new page to the source template
templatesCreates a new template for each variant in the same workspace

Query Parameters#

ParameterTypeRequiredDefaultDescription
includeThumbnailsBooleanNofalseWhen true, thumbnails are rendered for each newly created variant and returned inline in the response. When false or absent, thumbnails are generated asynchronously. Shape of the inline thumbnail depends on output mode (see below).

Response Fields#

Common Fields#

FieldTypeDescription
successBooleanWhether the operation was successful
source_template_idStringID of the source template
source_pageIntegerPage number used as source
source_page_idStringStable id of the source page. Use this to reliably reference the source page even after template pages are reordered
output_modeStringThe output mode used
variantsArrayArray of generated variant results

Variant Result Fields (varies by output mode)#

FieldOutput ModeTypeDescription
variant_indexAllIntegerIndex of this variant in the request
widthAllIntegerWidth of the variant
heightAllIntegerHeight of the variant
page_indexpagesInteger0-based index of the new page in the template. Its page number is page_index + 1
page_idpagesStringId of the new page
page_namepagesStringName of the new page
thumbnail_urlpagesString|nullOnly present when ?includeThumbnails=true. Public URL of the thumbnail PNG for this variant's page. null if rendering this page failed
thumbnail_errorpagesStringPresent only when ?includeThumbnails=true and this variant's thumbnail failed to render. Contains the error message
thumbnailstemplatesObjectOnly present when ?includeThumbnails=true. See Thumbnails Object Structure below
template_idtemplatesIntegerID of the newly created template
template_nametemplatesStringName of the newly created template
errorAllStringError message if this variant was generated but could not be saved

If the AI could not produce a size, that size is missing from variants and is not billed. Compare variant_index with your request to find it.

Thumbnails Object Structure#

When ?includeThumbnails=true is passed with output: "templates", each new template variant includes a nested thumbnails object:

FieldTypeDescription
successBooleantrue if at least one page rendered successfully
pages[].pageInteger1-based page number
pages[].page_idStringStable id of the page
pages[].thumbnail_urlString|nullPublic URL of the thumbnail PNG. null if this page failed
pages[].errorString|nullError message if this page failed. null on success

For output: "pages", each variant entry gets a flat thumbnail_url field instead (the variant itself represents a single page), with an optional thumbnail_error field if rendering failed.

When ?includeThumbnails is not passed, thumbnails are generated asynchronously after the response. For pages mode, they appear on the source template; for templates mode, on each newly created template.

How AI Variant Generation Works#

The AI reads the source page, and its thumbnail when it has one, then places each layer on the new canvas. It changes only position, size, font size, rotation, image fit and text fit. Text, images and colors stay the same.

  1. Fill the canvas: The main image and the headline are enlarged to fill the new size, with about 20px margins. Hero images take roughly 40 to 50% of the height.
  2. Backgrounds: Background layers are stretched to cover the whole canvas.
  3. Groups: A shape behind a text layer moves with that text. Texts that shared a left, center or right edge keep sharing it.
  4. Text: Text is never cut off. Long text wraps into a taller box.
  5. Overlap: Layers are kept apart. Overlap from the source is kept only when it does not grow.

Supported Transformations#

FromToBehavior
LandscapeSquareStacks layers top to bottom: headline, then subtext or logo, then the hero image
LandscapePortraitSame as square: stacked top to bottom, hero image usually the largest layer
Any otherAny otherNo fixed strategy. Layers are moved and resized to fill the new canvas

Error Responses#

Status CodeErrorDescription
400Validation failedInvalid variants array or dimensions
400Invalid page_numberSpecified page doesn't exist in template
401UnauthorizedThe OAuth token is invalid or expired. Refresh it
403Insufficient AI creditsNot enough AI credits, your plan has no AI credits, or your subscription is inactive or paused. The response includes credits_required and credits_available
403Access ForbiddenInvalid API key, your plan does not include this endpoint, or a payment is overdue (see code)
404Template not foundThe template isn't in your workspace
423stage_lockedWith output: "pages": an approval flow locks the template. See Approvals
429Rate limit exceededToo many requests (max 30/min)
500Internal server errorAI generation or server error
503No variants generatedThe AI returned no usable variant. No credits are used. Try again, or simplify the source page

Best Practices#

  1. Source Quality: Use a well-designed source template for best AI results
  2. Batch Sizes: Generate up to 10 variants per request for optimal performance
  3. Output Selection:
    • Use pages to keep all variants in one template (carousels)
    • Use templates for independent templates that render separately
  4. Page Selection: For multi-page templates, specify which page to use as source
  5. Dimensions: AI works best when aspect ratio changes aren't too extreme
Was this page helpful?

Ready to automate?

Start rendering images, PDFs and videos from your templates in under 2 minutes. Free plan, no credit card.

Get your API key
  • Image, PDF and video generation via API
  • Visual editor with AI and smart layouts
  • Zapier, Make, MCP and 40+ integrations
  • White-label embed for your own app
  • 100 free credits a month, no credit card required