# ByteDance API에서 마이그레이션

> ByteDance 자체 API용으로 작성한 코드를 Kerox로 옮깁니다. 요청 본문은 그대로 유지한 채 감싸서 보내고, 호스트와 키를 변경한 뒤 Kerox 방식으로 결과를 가져옵니다.

ByteDance 모델에 `"format": "native"` 설정을 추가하면 ByteDance 자체 요청 본문을 그대로 받으므로, 이미 보내고 있는 파라미터는 바꿀 필요가 없습니다. 변경할 부분은 호스트, 키, `model` 필드와 콜백을 지정하는 위치, 그리고 결과를 가져오는 방식입니다. 다른 모델에는 이 옵션이 없으며 [Kerox 파라미터 이름](https://kerox.ai/ko/docs/models.md)을 사용합니다. ByteDance 모델에서도 이 이름을 사용할 수 있습니다.

<a id="changes"></a>

## 변경할 사항
| ByteDance 코드에서 | Kerox에서 |
| --- | --- |
| ByteDance 엔드포인트 | `POST https://api.kerox.ai/v1/tasks` 엔드포인트를 이미지와 영상에 공통으로 사용 |
| ByteDance API 키 | Kerox API 키: `Authorization: Bearer $KEROX_API_KEY` ([빠른 시작](https://kerox.ai/ko/docs/quickstart.md#key)) |
| `model`: ByteDance 모델 이름 | `model`: Kerox 모델 ID(예: `bytedance/seedream-5.5`) ([모델](https://kerox.ai/ko/docs/models.md)) |
| 요청 본문의 나머지 부분 | 변경 없이 `input` 안에 유지되며, 바로 옆에 `"format": "native"` 필드가 위치 |
| `callback_url` | `webhook_url`, `model` 필드 옆 최상위 수준에 위치 ([Webhook](https://kerox.ai/ko/docs/webhooks.md)) |
| 응답에 포함된 결과 | 응답에는 작업의 `id` 값이 즉시 포함됩니다. `GET /v1/tasks/{id}` 엔드포인트를 폴링하거나 Webhook 알림을 기다린 뒤 `outputs` 필드에서 파일을 읽습니다([작업](https://kerox.ai/ko/docs/tasks.md#polling)) |

ByteDance의 일부 매개변수는 다르게 처리됩니다.

- **허용되지만 무시됨**: `service_tier`, `priority`, `safety_identifier`. 이 매개변수가 포함된 요청 본문도 수정 없이 작동합니다. 이 값들은 모델에 전달되지 않으며 ByteDance의 기본값이 적용됩니다.
- **위치 변경**: `callback_url` 필드는 최상위 `webhook_url` 필드로 이동합니다.
- **제거 필요**: `execution_expires_after`, `response_format`, `stream`. 이 매개변수가 포함된 요청 본문은 HTTP `400` `invalid_request` 오류와 함께 거부되며, `param` 값에 해당 필드 이름이 표시됩니다.

<a id="examples"></a>

## 변경 전후
이미지 요청입니다. `response_format` 항목은 빠지며, 결과는 항상 `outputs`에 파일 URL로 반환됩니다.


```json
{
  "model": "<ByteDance model name>",
  "prompt": "a quiet coastal lighthouse at dusk",
  "size": "2K",
  "response_format": "url",
  "watermark": false
}
```
```json
{
  "model": "bytedance/seedream-5.5",
  "format": "native",
  "input": {
    "prompt": "a quiet coastal lighthouse at dusk",
    "size": "2K",
    "watermark": false
  }
}
```


영상 요청입니다. `callback_url` 항목은 `webhook_url`(으)로 옮겨지며, `service_tier` 항목은 남겨 두어도 무시됩니다.


```json
{
  "model": "<ByteDance model name>",
  "content": [{ "type": "text", "text": "a red fox running through fresh snow" }],
  "ratio": "16:9",
  "resolution": "720p",
  "duration": 5,
  "service_tier": "default",
  "callback_url": "https://your-app.example.com/webhooks/kerox"
}
```
```json
{
  "model": "bytedance/seedance-2.5",
  "format": "native",
  "webhook_url": "https://your-app.example.com/webhooks/kerox",
  "input": {
    "content": [{ "type": "text", "text": "a red fox running through fresh snow" }],
    "ratio": "16:9",
    "resolution": "720p",
    "duration": 5,
    "service_tier": "default"
  }
}
```


<a id="native"></a>

## 보내기
영상 요청을 전송한 모습입니다. 각 모델이 이 형식에서 받는 입력은 `GET /v1/models/{id}`의 `input_schema`와(과) 해당 [모델 페이지](https://kerox.ai/ko/docs/models.md)의 ByteDance 형식 섹션에서 확인할 수 있습니다.


```bash
curl -X POST https://api.kerox.ai/v1/tasks \
  -H "Authorization: Bearer $KEROX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "bytedance/seedance-2.5",
    "format": "native",
    "input": {
      "content": [
        { "type": "text", "text": "a red fox running through fresh snow" }
      ],
      "ratio": "16:9",
      "resolution": "720p",
      "duration": 5
    }
  }'
```
```python
import os
import requests

resp = requests.post(
    "https://api.kerox.ai/v1/tasks",
    headers={
        "Authorization": f"Bearer {os.environ['KEROX_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "model": "bytedance/seedance-2.5",
        "format": "native",
        "input": {
            "content": [
                {"type": "text", "text": "a red fox running through fresh snow"}
            ],
            "ratio": "16:9",
            "resolution": "720p",
            "duration": 5,
        },
    },
    timeout=30,
)
print(resp.json())
```
```javascript
const res = await fetch('https://api.kerox.ai/v1/tasks', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.KEROX_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'bytedance/seedance-2.5',
    format: 'native',
    input: {
      content: [
        { type: 'text', text: 'a red fox running through fresh snow' },
      ],
      ratio: '16:9',
      resolution: '720p',
      duration: 5,
    },
  }),
});
console.log(await res.json());
```


응답과 그 이후의 모든 과정은 다른 모든 작업과 동일합니다. [작업 및 폴링](https://kerox.ai/ko/docs/tasks.md#polling)을 참고하시기 바랍니다.
