# Dosyalar ve girdiler

> Bir görevde kendi görsel, video veya ses dosyanızı kullanın: Dosyayı POST /v1/files ile yükleyin, ardından döndürülen URL'yi görev girdisine ekleyin.

Bu sayfada, diskinizdeki bir referans görselden tamamlanmış bir göreve kadar olan süreç anlatılır. `KEROX_API_KEY` içinde bir API anahtarına ve `frame.png` adlı, en fazla 4 MB boyutunda bir PNG dosyasına ihtiyacınız vardır (daha büyük dosyalar için: [Büyük dosyalar](#presigned)). Dosyayı hangi girdinin kabul ettiği (örneğin referans görseller için `images`) her [modelin sayfasında](https://kerox.ai/tr/docs/models.md) listelenir.

<a id="upload"></a>

## Dosya yükleyin ve kullanın
`POST /v1/files` isteği, dosya `file` form alanında gönderildiğinde HTTP `201` ve hemen `ready` durumunda olan bir dosya nesnesi döndürür. Bu nesnenin `url` değerini görevin `input` alanına ekleyin. Bu örnekte değer `images` olarak eklenir.


```bash
# Needs curl and jq, and a PNG up to 4 MB named frame.png.
set -euo pipefail
AUTH="Authorization: Bearer $KEROX_API_KEY"

# 1. Upload: HTTP 201, and the file is ready at once.
FILE_URL=$(curl -sS --fail-with-body -X POST https://api.kerox.ai/v1/files \
  -H "$AUTH" -F "file=@frame.png" | jq -r .url)
echo "Uploaded $FILE_URL"

# 2. Use its url in the task's input.
curl -sS --fail-with-body -X POST https://api.kerox.ai/v1/tasks \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d "$(jq -n --arg url "$FILE_URL" '{
    model: "bytedance/seedream-5.5",
    input: { prompt: "a quiet coastal lighthouse at dusk, in the style of the reference image", images: [$url] }
  }')" | jq '{id, status}'
```
```python
# pip install requests
import os
import requests

headers = {"Authorization": f"Bearer {os.environ['KEROX_API_KEY']}"}

# 1. Upload: HTTP 201, and the file is ready at once.
with open("frame.png", "rb") as fh:
    resp = requests.post(
        "https://api.kerox.ai/v1/files",
        headers=headers,
        files={"file": ("frame.png", fh, "image/png")},
        timeout=60,
    )
resp.raise_for_status()
file_url = resp.json()["url"]
print("Uploaded", file_url)

# 2. Use its url in the task's input.
task = requests.post(
    "https://api.kerox.ai/v1/tasks",
    headers=headers,
    json={
        "model": "bytedance/seedream-5.5",
        "input": {"prompt": "a quiet coastal lighthouse at dusk, in the style of the reference image", "images": [file_url]},
    },
    timeout=60,
)
task.raise_for_status()
print(task.json()["id"], task.json()["status"])
```
```javascript
// Node.js 18 or later: fetch, FormData and Blob are built in.
import fs from 'node:fs/promises';

const headers = { Authorization: `Bearer ${process.env.KEROX_API_KEY}` };

// 1. Upload: HTTP 201, and the file is ready at once.
const form = new FormData();
const bytes = await fs.readFile('frame.png');
form.append('file', new Blob([bytes], { type: 'image/png' }), 'frame.png');
const upload = await fetch('https://api.kerox.ai/v1/files', {
  method: 'POST',
  headers,
  body: form,
});
if (upload.status !== 201) {
  throw new Error(`HTTP ${upload.status}: ${await upload.text()}`);
}
const { url: fileUrl } = await upload.json();
console.log('Uploaded', fileUrl);

// 2. Use its url in the task's input.
const res = await fetch('https://api.kerox.ai/v1/tasks', {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'bytedance/seedream-5.5',
    input: { prompt: 'a quiet coastal lighthouse at dusk, in the style of the reference image', images: [fileUrl] },
  }),
});
const task = await res.json();
if (res.status !== 201) throw new Error(`HTTP ${res.status}: ${task.error.message}`);
console.log(task.id, task.status);
```


Yükleme, zaten `ready` durumundaki dosya nesnesini döndürür:


```json
{
  "id": "file_01JD8XB9D3F5G7H9J1K3M5N7P9",
  "object": "file",
  "filename": "frame.png",
  "content_type": "image/png",
  "size": 68,
  "status": "ready",
  "url": "https://cdn.kerox.ai/u/file_01JD8XB9D3F5G7H9J1K3M5N7P9/frame.png",
  "expires_at": "2026-11-27T08:00:52.215Z"
}
```


Ardından görevi [Hızlı Başlangıç](https://kerox.ai/tr/docs/quickstart.md#submit) bölümündeki gibi okuyun. Görev `input_fetch_failed` ile başarısız olursa dosya indirilememiştir: dosyayı yeniden yükleyin (dosyalar 7 gün saklanır).

<a id="presigned"></a>

## Büyük dosyalar (200 MB'a kadar)
4 MB'ın üzerindeki dosyaları üç adımda yükleyin: dosyanın adını, türünü ve tam boyutunu JSON olarak `POST /v1/files` adresine gönderin; baytları, `upload_headers` içindeki tüm başlıklarla birlikte döndürülen `upload_url` adresine (15 dakika geçerlidir) `PUT` ile gönderin; ardından `status` değeri `ready` olana kadar `GET /v1/files/{id}` ile durumu kontrol edin. Yükleme, bildirdiğiniz `content_type` ve `size` için imzalanır; bu nedenle farklı bir boyut veya tür reddedilir. `upload_headers` `If-None-Match: *` içerir: yükleme URL'leri tek kullanımlıktır ve dosya zaten yüklenmişken (veya silinmişken) yapılan bir `PUT` HTTP `412` döndürür.

İstek gövdesi (JSON):

| Alan | Tür | Zorunlu | Açıklama |
| --- | --- | --- | --- |
| `filename` | string | Evet | Dosyanın adı, 1–200 karakter |
| `content_type` | string | Evet | [Aşağıda listelenen](#retention) türlerden biri |
| `size` | integer | Evet | Dosyanın bayt cinsinden tam boyutu, en fazla 200 MB |

Bu Qwen örneği için her kenarı 384 ile 3072 piksel arasında olan, en fazla 10 MB boyutunda bir PNG kullanın. Bir PUT isteği HTTP `412` döndürdükten sonra dosya kimliğiyle dosyanın durumunu sorgulayın: dosya hazırsa URL'sini kullanın. Dosya silinmişse veya hiç hazır olmadıysa yeni bir yükleme isteyin ve PUT isteğini bu yeni yükleme URL'sine gönderin.


```bash
API_ORIGIN=${KEROX_API_ORIGIN:-https://api.kerox.ai}
# Needs curl and jq. The file is frame.png.
set -euo pipefail
AUTH="Authorization: Bearer $KEROX_API_KEY"

# 1. Ask for an upload URL. "size" is the exact size in bytes.
FILE=$(curl -sS --fail-with-body -X POST "$API_ORIGIN/v1/files" \
  -H "$AUTH" -H "Content-Type: application/json" \
  -d "$(jq -n --argjson size "$(wc -c < frame.png | tr -d ' ')" \
    '{filename: "frame.png", content_type: "image/png", size: $size}')")
FILE_ID=$(echo "$FILE" | jq -r .id)
FILE_URL=$(echo "$FILE" | jq -r .url)

# 2. PUT the bytes with every header in upload_headers.
HEADERS=()
while IFS= read -r header; do HEADERS+=(-H "$header"); done \
  < <(echo "$FILE" | jq -r '.upload_headers | to_entries[] | "\(.key): \(.value)"')
curl -sS --fail-with-body -X PUT "$(echo "$FILE" | jq -r .upload_url)" \
  "${HEADERS[@]}" --data-binary @frame.png

# 3. Wait until the file is ready (up to 30 seconds).
for _ in $(seq 30); do
  STATUS=$(curl -sS --fail-with-body "$API_ORIGIN/v1/files/$FILE_ID" \
    -H "$AUTH" | jq -r .status)
  [ "$STATUS" = "ready" ] && break
  sleep 1
done
[ "$STATUS" = "ready" ]

# 4. Submit with the ready HTTPS URL.
curl -fsS -X POST "$API_ORIGIN/v1/tasks" -H "$AUTH" -H "Content-Type: application/json" \
  -d "$(jq -n --arg url "$FILE_URL" '{model:"alibaba/qwen-image-2.0",input:{prompt:"Paint this scene in watercolor",images:[$url]}}')" | jq -er .id
```
```python
# pip install requests
import os
import time
import requests

api = os.environ.get("KEROX_API_ORIGIN", "https://api.kerox.ai")

headers = {"Authorization": f"Bearer {os.environ['KEROX_API_KEY']}"}
with open("frame.png", "rb") as fh:
    data = fh.read()

# 1. Ask for an upload URL. "size" is the exact size in bytes.
resp = requests.post(
    f"{api}/v1/files",
    headers=headers,
    json={"filename": "frame.png", "content_type": "image/png", "size": len(data)},
    timeout=30,
)
resp.raise_for_status()
file_obj = resp.json()

# 2. PUT the bytes with every header in upload_headers.
requests.put(
    file_obj["upload_url"], headers=file_obj["upload_headers"], data=data, timeout=300
).raise_for_status()

# 3. Wait until the file is ready (up to 30 seconds).
for _ in range(30):
    check = requests.get(
        f"{api}/v1/files/{file_obj['id']}", headers=headers, timeout=30
    )
    check.raise_for_status()
    status = check.json()["status"]
    if status == "ready":
        break
    time.sleep(1)
else:
    raise SystemExit("The upload never became ready")

# 4. Submit with the ready HTTPS URL.
task = requests.post(
    f"{api}/v1/tasks", headers=headers, timeout=60,
    json={"model": "alibaba/qwen-image-2.0", "input": {"prompt": "Paint this scene in watercolor", "images": [file_obj["url"]]}},
)
task.raise_for_status()
print(task.json()["id"])
```
```javascript
const api = process.env.KEROX_API_ORIGIN || 'https://api.kerox.ai';
// Node.js 18 or later: fetch is built in.
import fs from 'node:fs/promises';

const headers = { Authorization: `Bearer ${process.env.KEROX_API_KEY}` };
const data = await fs.readFile('frame.png');

// 1. Ask for an upload URL. "size" is the exact size in bytes.
const res = await fetch(`${api}/v1/files`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    filename: 'frame.png',
    content_type: 'image/png',
    size: data.byteLength,
  }),
});
if (res.status !== 201) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const fileObj = await res.json();

// 2. PUT the bytes with every header in upload_headers.
const put = await fetch(fileObj.upload_url, {
  method: 'PUT',
  headers: fileObj.upload_headers,
  body: data,
});
if (!put.ok) throw new Error(`Upload failed: HTTP ${put.status}`);

// 3. Wait until the file is ready (up to 30 seconds).
let status = 'pending';
for (let i = 0; i < 30 && status !== 'ready'; i++) {
  const check = await fetch(`${api}/v1/files/${fileObj.id}`, { headers });
  if (!check.ok) throw new Error(`HTTP ${check.status}: ${await check.text()}`);
  status = (await check.json()).status;
  if (status !== 'ready') await new Promise((resolve) => setTimeout(resolve, 1000));
}
if (status !== 'ready') throw new Error('The upload never became ready');

// 4. Submit with the ready HTTPS URL.
const task = await fetch(`${api}/v1/tasks`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'alibaba/qwen-image-2.0',
    input: { prompt: 'Paint this scene in watercolor', images: [fileObj.url] },
  }),
});
if (!task.ok) throw new Error(`HTTP ${task.status}: ${await task.text()}`);
console.log((await task.json()).id);
```


1. adımın yanıtı aşağıdaki gibidir (`upload_url` imzalı ve uzun bir URL'dir; burada kısaltılmıştır). Her yükleme bu dosya nesnesini döndürür:


```json
{
  "id": "file_01JD8XB2K7M9P3Q5R8S1T4V6W0",
  "object": "file",
  "filename": "frame.png",
  "content_type": "image/png",
  "size": 68,
  "status": "pending",
  "url": "https://cdn.kerox.ai/u/file_01JD8XB2K7M9P3Q5R8S1T4V6W0/frame.png",
  "expires_at": "2026-11-27T08:00:41.437Z",
  "upload_url": "https://…/u/file_01JD8XB2K7M9P3Q5R8S1T4V6W0/frame.png?X-Amz-Signature=…",
  "upload_headers": {
    "content-type": "image/png",
    "if-none-match": "*"
  }
}
```


| Alan | Açıklama |
| --- | --- |
| `id` | Dosya kimliği (`file_...`) |
| `object` | Her zaman `"file"` |
| `filename` | Gönderdiğiniz ad |
| `content_type` | Gönderdiğiniz tür |
| `size` | Bayt cinsinden boyut |
| `status` | `pending` dosya verileri alınana kadar, ardından `ready`; [silindiğinde](#delete) veya `expires_at` zamanı geçtiğinde `deleted` |
| `url` | Bir görevin `input` alanına yazılacak adres; silindiğinde `null` |
| `upload_url` | Yalnızca önceden imzalanmış yükleme: baytların `PUT` ile gönderileceği yer, 15 dakika geçerlidir |
| `upload_headers` | Yalnızca önceden imzalanmış yükleme: `PUT` ile gönderilecek başlıklar (`Content-Type` ve `If-None-Match: *`) |
| `expires_at` | Dosyanın silineceği zaman; oluşturulduktan 7 gün sonra |

<a id="ways"></a>

## Dosya iletmenin diğer yolları
Her alanın kabul ettiği biçimler için modelin parametre tablosuna veya `unified.input_schema` belgesine bakın. `images` alanı; tüm Qwen Image modellerinde, Wan 2.7 Image / Pro, Wan 3.0 / Prime `first_frame`, `last_frame`, `images`, `videos`, `audios`, `file` ve `link` modellerinde ve Seedance `videos` (2.0, Fast, Mini ve 2.5) modellerinde herkese açık HTTPS URL'leri gerektirir. Yerel bir dosya için yukarıdaki büyük dosya örneği dosyayı yükler ve dönen `url` değerini Qwen'e gönderir. Herkese açık mevcut bir görsel için bu gövdeyi `POST /v1/tasks` adresine gönderin.


```json
{
  "model": "alibaba/qwen-image-2.0",
  "input": {
    "prompt": "Paint this scene in watercolor",
    "images": [
      "https://kerox.ai/icon-512.png"
    ]
  }
}
```


Seedream 5.5 `images` satır içi görselleri de kabul eder. Bu PNG, 32 × 32 boyutunda bir renk örneğidir. Satır içi dosyaların toplamı en fazla 3 MB, isteğin tamamı ise en fazla 4 MB olabilir.


```json
{
  "model": "bytedance/seedream-5.5",
  "input": {
    "prompt": "Paint this scene in watercolor",
    "images": [
      "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAKklEQVR4nGPgSa+lKWIYtWDUglELRi0YtWDUglELRi0YtWDUglELhooFAJ0VwC5Gic1rAAAAAElFTkSuQmCC"
    ]
  }
}
```


<a id="retention"></a>

## Durum kontrolü ve saklama süresi
- Önceden imzalanmış bir yüklemeyi kontrol etmek için `GET /v1/files/{id}` çağrısını yapın: baytlar ulaşana kadar `"pending"`, ardından `"ready"` döner.
- Yüklenen dosyalar **7 gün** sonra otomatik olarak silinir. [Siz silerseniz](#delete) daha erken silinir.
- Yüklemeler şu içerik türlerini kabul eder: `image/jpeg`, `image/jpg`, `image/png`, `image/webp`, `image/bmp`, `image/tiff`, `image/gif`, `image/avif`, `image/heic`, `image/heif`, `video/mp4`, `video/quicktime`, `video/webm`, `audio/wav`, `audio/x-wav`, `audio/wave`, `audio/vnd.wave`, `audio/mpeg`, `audio/mp4`. Başka herhangi bir `content_type` için HTTP `400` (`invalid_request`) döner. Her model bunların yalnızca bir kısmını kabul eder. Biçim ve çözünürlük sınırları için modelin `input_schema` bölümüne bakın.

<a id="delete"></a>

## Bir yüklemeyi silme
`DELETE /v1/files/{id}`, yüklenen bir dosyayı depolama alanından ve CDN önbelleğinden hemen siler. Silinen dosya geri getirilemez. Dosyayı yalnızca onu yükleyen hesap silebilir. Diğer kimlikler için HTTP `404` (`not_found`) döner. Dosyayı tekrar silmek aynı nesneyi döndürür.

Bu dosyayı girdi olarak kullanan ve hâlâ `processing` durumunda olan bir görev bu durumda `input_fetch_failed` hatasıyla başarısız olabilir (tutarın tamamı iade edilir). Girdileri, onları kullanan görevler tamamlandıktan sonra silin.

Silme işleminden sonra eski bağlantı artık dosyayı sunmaz. Bağlantı boş bir dosya döndürür ve bu dosya birkaç gün içinde temizlenir. Hâlâ devam eden bir `PUT` isteği veya aynı `upload_url` için daha sonra yapılan bir istek HTTP `412` döndürür: dosya bu bağlantıda bir daha sunulamaz.


```bash
# FILE_ID is the id POST /v1/files returned.
curl -sS --fail-with-body -X DELETE "https://api.kerox.ai/v1/files/$FILE_ID" \
  -H "Authorization: Bearer $KEROX_API_KEY"
```
```python
# pip install requests
import os
import requests

# FILE_ID is the id POST /v1/files returned.
resp = requests.delete(
    f"https://api.kerox.ai/v1/files/{os.environ['FILE_ID']}",
    headers={"Authorization": f"Bearer {os.environ['KEROX_API_KEY']}"},
    timeout=30,
)
resp.raise_for_status()
print(resp.json()["status"])  # deleted
```
```javascript
// Node.js 18 or later: fetch is built in.
// FILE_ID is the id POST /v1/files returned.
const res = await fetch(`https://api.kerox.ai/v1/files/${process.env.FILE_ID}`, {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${process.env.KEROX_API_KEY}` },
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
const fileObj = await res.json();
console.log(fileObj.status); // deleted
```


Yanıt, dosyanın silme işleminden sonraki hâlidir:

```json
{
  "id": "file_01JD8XB2Q7M4T8N3K5P6R1S0VA",
  "object": "file",
  "filename": "frame.png",
  "content_type": "image/png",
  "size": 482113,
  "status": "deleted",
  "url": null,
  "expires_at": "2026-11-21T09:30:00Z"
}
```

| Alan | Silme işleminden sonra |
|---|---|
| `status` | `deleted`. 7 günü geçmiş bir dosya da `GET /v1/files/{id}` içinde aynı şekilde görünür |
| `url` | `null` |
| `expires_at` | Silme işleminin zamanına çekilir |
| `filename`, `content_type`, `size` | Değişmez |
