> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Image Variation

> Creates a variation of a given image

## Overview

This endpoint is retained for legacy OpenAI-compatible variation clients. It is not the recommended path for current image-to-image workflows; use `/v1/images/edits` with `gpt-image-2` or `/v1/images/generations` with an image-to-image model such as `nano-banana-pro` when possible. Requires `multipart/form-data` content type.

## Request Body

**Synchronous request timeout:** Some routed image providers return the final image inline and wait for generation to finish. High-resolution or high-quality requests can take close to a minute or longer, so set your HTTP client timeout to at least `120s`. If the create response includes `status: "pending"`, `task_id`, or `poll_url`, follow the returned `poll_url` instead.

<ParamField body="image" type="file" required>
  The image to use as the basis for the variation. Must be a valid PNG file, less than 50MB, and square.
</ParamField>

<ParamField body="model" type="string" required>
  Required model identifier for legacy variation-compatible routes. There is no implicit default; for current image-to-image workflows, prefer `/v1/images/edits` or `/v1/images/generations` with a current model.
</ParamField>

<ParamField body="n" type="integer" default="1">
  The number of images to generate. Must be between 1 and 10.
</ParamField>

<ParamField body="size" type="string">
  The size of the generated images for legacy variation-compatible routes. Supported values depend on the selected model.
</ParamField>

<ParamField body="response_format" type="string" default="url">
  The format in which the generated images are returned. Must be `url` or `b64_json`.
</ParamField>

<ParamField body="user" type="string">
  A unique identifier representing your end-user for abuse monitoring.
</ParamField>

## Response

<ResponseField name="created" type="integer">
  Unix timestamp of when the images were created.
</ResponseField>

<ResponseField name="data" type="array">
  Array of generated image variations.

  Each object contains:

  * `url` (string): URL of the variation image (if response\_format is `url`)
  * `b64_json` (string): Base64-encoded image (if response\_format is `b64_json`)
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/images/variations" \
    -H "Authorization: Bearer sk-your-api-key" \
    -F "model=your-legacy-variation-model" \
    -F "image=@cat.png" \
    -F "n=2" \
    -F "size=1024x1024"
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-your-api-key",
      base_url="https://api.tokenlab.sh/v1"
  )

  response = client.images.create_variation(
      model="your-legacy-variation-model",
      image=open("cat.png", "rb"),
      n=2,
      size="1024x1024"
  )

  for image in response.data:
      print(image.url)
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from 'openai';
  import fs from 'fs';

  const client = new OpenAI({
    apiKey: 'sk-your-api-key',
    baseURL: 'https://api.tokenlab.sh/v1'
  });

  const response = await client.images.createVariation({
    model: 'your-legacy-variation-model',
    image: fs.createReadStream('cat.png'),
    n: 2,
    size: '1024x1024'
  });

  response.data.forEach(image => console.log(image.url));
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "fmt"
      "io"
      "mime/multipart"
      "net/http"
      "os"
  )

  func main() {
      body := &bytes.Buffer{}
      writer := multipart.NewWriter(body)

      writer.WriteField("model", "your-legacy-variation-model")

      file, _ := os.Open("cat.png")
      defer file.Close()
      part, _ := writer.CreateFormFile("image", "cat.png")
      io.Copy(part, file)

      writer.WriteField("n", "2")
      writer.WriteField("size", "1024x1024")
      writer.Close()

      req, _ := http.NewRequest("POST", "https://api.tokenlab.sh/v1/images/variations", body)
      req.Header.Set("Authorization", "Bearer sk-your-api-key")
      req.Header.Set("Content-Type", writer.FormDataContentType())

      client := &http.Client{}
      resp, _ := client.Do(req)
      defer resp.Body.Close()

      result, _ := io.ReadAll(resp.Body)
      fmt.Println(string(result))
  }
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://api.tokenlab.sh/v1/images/variations');

  $image = new CURLFile('cat.png', 'image/png', 'cat.png');

  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer sk-your-api-key'
      ],
      CURLOPT_POSTFIELDS => [
          'model' => 'your-legacy-variation-model',
          'image' => $image,
          'n' => 2,
          'size' => '1024x1024'
      ]
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  $data = json_decode($response, true);
  foreach ($data['data'] as $image) {
      echo $image['url'] . "\n";
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "created": 1706000000,
    "data": [
      {
        "url": "https://..."
      },
      {
        "url": "https://..."
      }
    ]
  }
  ```
</ResponseExample>

## Notes

<Note>
  This is a legacy compatibility endpoint. It is not included in the current recommended image model catalog. For new integrations, use `/v1/images/edits` with `gpt-image-2`, or `/v1/images/generations` with `operation: "image-to-image"` and a current image-to-image model.
</Note>
