Skip to main content

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.
image
file
required
The image to use as the basis for the variation. Must be a valid PNG file, less than 50MB, and square.
model
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.
n
integer
default:"1"
The number of images to generate. Must be between 1 and 10.
size
string
The size of the generated images for legacy variation-compatible routes. Supported values depend on the selected model.
response_format
string
default:"url"
The format in which the generated images are returned. Must be url or b64_json.
user
string
A unique identifier representing your end-user for abuse monitoring.

Response

created
integer
Unix timestamp of when the images were created.
data
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)
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"
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)
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));
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
$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";
}
{
  "created": 1706000000,
  "data": [
    {
      "url": "https://..."
    },
    {
      "url": "https://..."
    }
  ]
}

Notes

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.