# 빠른 시작

> 첫 이미지를 생성하고 파일로 저장합니다. 로그인하고, 키를 만들고, 작업을 제출하고, 작업 상태를 반복 조회(폴링)한 다음 결과를 다운로드합니다.

이 페이지를 마치면 API 호출 한 번으로 만든 PNG 파일이 디스크에 저장됩니다. 필요한 것은 이메일 주소, 0보다 큰 잔액, 그리고 `curl`와(과) [`jq`](https://jqlang.org)(또는 `requests`을(를) 설치한 Python 3, 또는 Node.js 18+)입니다. 계정에 잔액이 있으면 약 2분이면 완료됩니다.

다음 페이지에서는 각 모델 그룹의 요청 하나를 처음부터 끝까지 안내합니다. [Seedance API](https://kerox.ai/ko/seedance-api), [Kling API](https://kerox.ai/ko/kling-api), [AI 이미지 생성 API](https://kerox.ai/ko/ai-image-generator-api), [텍스트 영상 변환 API](https://kerox.ai/ko/text-to-video-api), [이미지 영상 변환 API](https://kerox.ai/ko/image-to-video-api).

<a id="key"></a>

## 키 발급 및 충전
1. [Console](https://kerox.ai/ko/console/api-keys)에 이메일로 받은 6자리 코드로 로그인합니다. 처음 로그인하면 계정이 생성됩니다.
2. **API** → **API 키**를 열고 키를 생성합니다. 전체 키는 생성할 때 한 번만 표시되므로 그때 바로 복사해 두어야 합니다.
3. **지갑**을 열고 사용 가능한 잔액을 확인합니다. 자금이 필요하면 해당 화면에서 카드 또는 Alipay로 충전합니다([충전](https://kerox.ai/ko/docs/pricing-billing.md#topups) 참고). 잔액이 작업의 예상 비용을 충당하지 못하면 해당 작업은 HTTP `402`로 거부됩니다.

키를 환경 변수에 저장합니다. 모든 요청은 이 키를 `Authorization: Bearer <your-api-key>`로 전송합니다. 키는 서버에만 보관하고 브라우저 앱에는 절대 넣지 않아야 합니다. 키 교체 방법과 선택적으로 설정할 수 있는 한도는 [API 키](https://kerox.ai/ko/docs/authentication.md)에서 설명합니다.


```bash
export KEROX_API_KEY="kx_live_your_api_key_here"
```


<a id="submit"></a>

## 제출, 상태 조회(폴링), 다운로드
하나의 스크립트로 전체 과정을 처리합니다. `POST /v1/tasks` 요청은 작업의 `id` 및 `status: "processing"` 값을 포함한 HTTP `201` 응답을 반환합니다. 스크립트는 `status` 값이 `succeeded` 또는 `failed`이 될 때까지 3초마다 `GET /v1/tasks/{id}`로 폴링한 다음, 파일을 저장하거나 실패 원인을 출력합니다. 10분이 지나면 클라이언트는 대기를 중단합니다. 이 경우 출력된 작업 ID를 보관해 두었다가 나중에 다시 폴링하면 됩니다. 서버 시간 초과는 `failed` 및 `error.code: "timeout"` 값으로 표시됩니다. 새 작업은 실패가 확인된 후에만 요청해야 합니다([시간 초과](https://kerox.ai/ko/docs/tasks.md#retention)).


```bash
# Needs curl and jq. KEROX_API_KEY is your key.
set -euo pipefail
API=https://api.kerox.ai/v1
AUTH="Authorization: Bearer $KEROX_API_KEY"
BODY='{
  "model": "bytedance/seedream-5.5",
  "input": {
    "prompt": "editorial portrait of a ceramicist in morning sunlight, 35mm film",
    "resolution": "2K"
  }
}'

# 1. Submit: HTTP 201 with the task's id.
TASK_ID=$(curl -sS --fail-with-body -X POST "$API/tasks" \
  -H "$AUTH" -H "Content-Type: application/json" -d "$BODY" | jq -r .id)
echo "Submitted $TASK_ID"

# 2. Poll every 3 seconds, for up to 10 minutes.
DEADLINE=$(( $(date +%s) + 600 ))
STATUS=processing
while [ "$STATUS" = "processing" ] && [ "$(date +%s)" -lt "$DEADLINE" ]; do
  sleep 3
  REM=$(( DEADLINE - $(date +%s) ))
  [ "$REM" -le 0 ] && break
  [ "$REM" -gt 30 ] && REM=30
  TASK=$(curl -sS --fail-with-body --max-time "$REM" "$API/tasks/$TASK_ID" -H "$AUTH")
  STATUS=$(echo "$TASK" | jq -r .status)
done

# 3. Save the file, or show why it failed.
if [ "$STATUS" = "processing" ]; then
  echo "Still running: TASK_ID=$TASK_ID, read it later with GET /v1/tasks/{id}"
  exit 1
elif [ "$STATUS" != "succeeded" ]; then
  echo "Task $TASK_ID is $STATUS: $(echo "$TASK" | jq -c .error)"
  exit 1
fi
curl -sS --fail-with-body -o result.png "$(echo "$TASK" | jq -r '.outputs[0].url')"
echo "Saved result.png"
```
```python
# pip install requests
import os
import time
import requests

API = "https://api.kerox.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['KEROX_API_KEY']}"}

# 1. Submit: HTTP 201 with the task's id.
resp = requests.post(
    f"{API}/tasks",
    headers=HEADERS,
    json={
        "model": "bytedance/seedream-5.5",
        "input": {
            "prompt": "editorial portrait of a ceramicist in morning sunlight, 35mm film",
            "resolution": "2K",
        },
    },
    timeout=60,
)
if resp.status_code != 201:
    raise SystemExit(f"HTTP {resp.status_code}: {resp.json()['error']}")
task = resp.json()
print("Submitted", task["id"])

# 2. Poll every 3 seconds, for up to 10 minutes.
deadline = time.time() + 600
while task["status"] == "processing" and time.time() < deadline:
    time.sleep(3)
    remaining = max(1, min(30, deadline - time.time()))
    poll = requests.get(f"{API}/tasks/{task['id']}", headers=HEADERS, timeout=remaining)
    poll.raise_for_status()
    task = poll.json()

# 3. Save the file, or show why it failed.
if task["status"] == "processing":
    raise SystemExit(f"Still running: task {task['id']}, read it again later")
if task["status"] != "succeeded":
    raise SystemExit(f"Task {task['id']} is {task['status']}: {task['error']}")
file = requests.get(task["outputs"][0]["url"], timeout=60)
file.raise_for_status()
with open("result.png", "wb") as fh:
    fh.write(file.content)
print("Saved result.png")
```
```javascript
// Node.js 18 or later: fetch is built in.
import fs from 'node:fs/promises';

const API = 'https://api.kerox.ai/v1';
const headers = { Authorization: `Bearer ${process.env.KEROX_API_KEY}` };

// 1. Submit: HTTP 201 with the task's id.
const res = await fetch(`${API}/tasks`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'bytedance/seedream-5.5',
    input: {
      prompt: 'editorial portrait of a ceramicist in morning sunlight, 35mm film',
      resolution: '2K',
    },
  }),
});
let task = await res.json();
if (res.status !== 201) throw new Error(`HTTP ${res.status}: ${task.error.message}`);
console.log('Submitted', task.id);

// 2. Poll every 3 seconds, for up to 10 minutes.
const deadline = Date.now() + 10 * 60 * 1000;
while (task.status === 'processing' && Date.now() < deadline) {
  await new Promise((resolve) => setTimeout(resolve, 3000));
  const poll = await fetch(`${API}/tasks/${task.id}`, {
    headers,
    signal: AbortSignal.timeout(Math.max(1000, Math.min(30_000, deadline - Date.now()))),
  });
  if (!poll.ok) throw new Error(`HTTP ${poll.status}`);
  task = await poll.json();
}

// 3. Save the file, or show why it failed.
if (task.status === 'processing') {
  throw new Error(`Still running: task ${task.id}, read it later with GET /v1/tasks/{id}`);
}
if (task.status !== 'succeeded') {
  throw new Error(`Task ${task.id} is ${task.status}: ${JSON.stringify(task.error)}`);
}
const file = await fetch(task.outputs[0].url);
if (!file.ok) throw new Error(`Download failed: HTTP ${file.status}`);
await fs.writeFile('result.png', Buffer.from(await file.arrayBuffer()));
console.log('Saved result.png');
```


요청 응답이 `201` 외의 값이면 본문은 오류 객체입니다. 각 코드의 의미와 대처 방법은 [오류](https://kerox.ai/ko/docs/errors.md#next-steps)에서 확인할 수 있습니다.

> **결과물은 7일 이내에 저장**
>
> 생성된 파일은 작업이 완료되고 7일이 지나면 더 이상 사용할 수 없습니다(`expires_at`). 필요한 파일은 자체 스토리지에 보관해야 합니다([보존 기간](https://kerox.ai/ko/docs/tasks.md#retention)).

<a id="webhook"></a>

### 폴링 대신 `webhook_url` 사용
아래 기본 요청은 폴링을 사용합니다. 콜백을 받으려면 요청 시 사용자의 공개 HTTPS 수신 주소를 지정하고, 전달이 지연될 경우 폴링할 수 있도록 작업 ID를 보관해 두어야 합니다. 자세한 내용은 [Webhook](https://kerox.ai/ko/docs/webhooks.md)에서 확인할 수 있습니다.


```json
{
  "model": "bytedance/seedream-5.5",
  "input": {
    "prompt": "editorial portrait of a ceramicist in morning sunlight, 35mm film",
    "resolution": "2K"
  }
}
```


<a id="result"></a>

## 결과 읽기
스크립트가 마지막에 읽은 작업은 다음과 같습니다. `succeeded` 상태에서는 파일이 `outputs`에 담깁니다. 파일마다 항목이 하나씩 있으며, 각 항목에는 `type` 및 `url` 값이 포함됩니다. `cost` 값은 USD로 정산된 금액입니다(가격: [모델](https://kerox.ai/ko/docs/models.md)). `failed` 상태에서는 사유가 `error`에 표시되며 보류된 금액은 환불됩니다. `input`에는 요청을 해당 모델 고유의 파라미터 형식으로 변환한 결과가 표시됩니다(이 예에서는 `resolution` 값이 `size` 값으로 변환되었습니다). 전체 필드: [작업 객체](https://kerox.ai/ko/docs/tasks.md#submit-response).


```json
{
  "id": "task_01JD8X9B4Q2M7T8N3K5P6R1S0V",
  "object": "task",
  "model": "bytedance/seedream-5.5",
  "status": "succeeded",
  "source": "api",
  "format": "unified",
  "input": {
    "prompt": "editorial portrait of a ceramicist in morning sunlight, 35mm film",
    "size": "2K"
  },
  "outputs": [
    {
      "type": "image",
      "url": "https://cdn.kerox.ai/t/task_01JD8X9B4Q2M7T8N3K5P6R1S0V/5f2b8c1e9d3a4f6b8a7c0d1e2f3a4b5c/0.png",
      "content_type": "image/png",
      "width": 2048,
      "height": 2048
    }
  ],
  "outputs_deleted": false,
  "error": null,
  "cost": {
    "amount": "0.0280",
    "currency": "USD",
    "status": "settled"
  },
  "metadata": null,
  "warnings": [],
  "created_at": "2026-11-20T08:01:02Z",
  "started_at": "2026-11-20T08:01:02Z",
  "completed_at": "2026-11-20T08:01:10Z",
  "expires_at": "2026-11-27T08:01:10Z"
}
```


<a id="next"></a>

## 다음 단계
- [Webhook](https://kerox.ai/ko/docs/webhooks.md): 작업이 완료되면 사용자 서버에서 작업 정보를 받습니다.
- [파일 및 입력](https://kerox.ai/ko/docs/files.md): 참조 이미지를 업로드하고 작업에 사용합니다.
- [MCP 서버](https://kerox.ai/ko/docs/mcp.md): Claude Code 또는 Cursor에서 Kerox를 호출할 수 있습니다.
