> ## 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.

# Görsel Varyasyonu Oluştur

> Verilen bir görselin varyasyonunu oluşturur

## Genel Bakış

Bu endpoint, eski OpenAI uyumlu variation istemcileri için korunur. Güncel image-to-image iş akışları için önerilen yol değildir; mümkünse `/v1/images/edits` ile `gpt-image-2` veya `/v1/images/generations` ile `nano-banana-pro` gibi bir image-to-image modeli kullanın. `multipart/form-data` gerektirir.

## İstek Gövdesi

**Senkron istek zaman aşımı:** Bazı yönlendirilmiş görsel sağlayıcıları son görseli inline döndürür ve üretimin tamamlanmasını bekler. Yüksek çözünürlüklü veya yüksek kaliteli istekler bir dakikaya yakın ya da daha uzun sürebilir; bu yüzden HTTP istemcisi zaman aşımını en az `120s` olarak ayarlayın. Oluşturma yanıtı `status: "pending"`, `task_id` veya `poll_url` içeriyorsa, dönen `poll_url` ile polling yapın.

<ParamField body="image" type="file" required>
  Varyasyon için temel olarak kullanılacak görsel. Geçerli bir PNG dosyası, 50MB'dan küçük ve kare olmalıdır.
</ParamField>

<ParamField body="model" type="string" required>
  Eski variation uyumlu rotalar için zorunlu model kimliği. Örtük varsayılan yoktur; güncel image-to-image iş akışları için güncel bir modelle `/v1/images/edits` veya `/v1/images/generations` tercih edin.
</ParamField>

<ParamField body="n" type="integer" default="1">
  Oluşturulacak görsel sayısı. 1 ile 10 arasında olmalıdır.
</ParamField>

<ParamField body="size" type="string">
  Eski variation uyumlu rotalarda üretilen görüntülerin boyutu. Desteklenen değerler seçilen modele bağlıdır.
</ParamField>

<ParamField body="response_format" type="string" default="url">
  Oluşturulan görsellerin döndürüleceği format. `url` veya `b64_json` olmalıdır.
</ParamField>

<ParamField body="user" type="string">
  Kötüye kullanım izleme için son kullanıcınızı temsil eden benzersiz tanımlayıcı.
</ParamField>

## Yanıt

<ResponseField name="created" type="integer">
  Görsellerin oluşturulduğu Unix zaman damgası.
</ResponseField>

<ResponseField name="data" type="array">
  Oluşturulan görsel varyasyonları dizisi.

  Her nesne şunları içerir:

  * `url` (string): Varyasyon görselinin URL'si (response\_format `url` ise)
  * `b64_json` (string): Base64 kodlu görsel (response\_format `b64_json` ise)
</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 Yanıt theme={null}
  {
    "created": 1706000000,
    "data": [
      {
        "url": "https://..."
      },
      {
        "url": "https://..."
      }
    ]
  }
  ```
</ResponseExample>

## Notlar

<Note>
  Bu, legacy uyumluluk endpointidir. Güncel önerilen görüntü modeli kataloğuna dahil değildir. Yeni entegrasyonlar için `/v1/images/edits` ile `gpt-image-2` veya `/v1/images/generations` içinde `operation: "image-to-image"` ve güncel bir image-to-image modeli kullanın.
</Note>
