> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sora 2 API 빠른 시작: CometAPI로 비디오 생성

> CometAPI로 Sora 2 비디오 작업을 생성하고, 상태를 폴링한 뒤, 완료된 비디오 콘텐츠를 curl, Python 또는 Node.js로 다운로드합니다.

## 만들 내용

Sora 2 비디오 작업을 제출하고, 반환된 비디오 ID를 저장한 다음, 작업이 완료될 때까지 폴링하고, 완성된 비디오 콘텐츠를 다운로드합니다.

## 사전 요구 사항

* `COMETAPI_KEY`에 저장된 CometAPI API 키
* `requests`가 있는 Python 3.10+ 또는 Node.js 18+
* 폴링을 위한 서버 측 워커 또는 작업 큐

## API 키, 기본 URL, 인증

다음으로 Sora 작업을 생성합니다:

```text theme={null}
POST https://api.cometapi.com/v1/videos
```

다음으로 상태를 폴링합니다:

```text theme={null}
GET https://api.cometapi.com/v1/videos/<video_id>
```

다음으로 완료된 콘텐츠를 다운로드합니다:

```text theme={null}
GET https://api.cometapi.com/v1/videos/<video_id>/content
```

Bearer 토큰으로 인증합니다:

```text theme={null}
Authorization: Bearer $COMETAPI_KEY
```

## 코드 예제

아래 탭에서 cURL, Python, Node.js로 된 복사 가능한 예제를 사용할 수 있습니다.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/videos \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -F model=sora-2 \
    -F "prompt=A paper boat drifts across a calm pond at sunrise" \
    -F seconds=4 \
    -F size=1280x720

  curl "https://api.cometapi.com/v1/videos/<video_id>" \
    -H "Authorization: Bearer $COMETAPI_KEY"

  curl "https://api.cometapi.com/v1/videos/<video_id>/content" \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    --output sora-result.mp4
  ```

  ```python Python theme={null}
  import os
  import time
  from pathlib import Path

  import requests

  api_key = os.environ["COMETAPI_KEY"]
  headers = {"Authorization": f"Bearer {api_key}"}

  create_response = requests.post(
      "https://api.cometapi.com/v1/videos",
      headers=headers,
      data={
          "model": "sora-2",
          "prompt": "A paper boat drifts across a calm pond at sunrise",
          "seconds": "4",
          "size": "1280x720",
      },
      timeout=60,
  )
  create_response.raise_for_status()
  video_id = create_response.json()["id"]

  for _ in range(60):
      status_response = requests.get(
          f"https://api.cometapi.com/v1/videos/{video_id}",
          headers=headers,
          timeout=30,
      )
      status_response.raise_for_status()
      status = status_response.json()
      if status["status"] == "completed":
          content_response = requests.get(
              f"https://api.cometapi.com/v1/videos/{video_id}/content",
              headers=headers,
              timeout=120,
          )
          content_response.raise_for_status()
          Path("sora-result.mp4").write_bytes(content_response.content)
          break
      if status["status"] == "failed":
          raise RuntimeError(status)
      time.sleep(5)
  else:
      raise TimeoutError("Sora job did not finish in time")
  ```

  ```javascript Node.js theme={null}
  import fs from "node:fs/promises";

  const form = new FormData();
  form.append("model", "sora-2");
  form.append("prompt", "A paper boat drifts across a calm pond at sunrise");
  form.append("seconds", "4");
  form.append("size", "1280x720");

  const createResponse = await fetch("https://api.cometapi.com/v1/videos", {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
    body: form,
  });

  if (!createResponse.ok) {
    throw new Error(await createResponse.text());
  }

  const { id } = await createResponse.json();

  for (let attempt = 0; attempt < 60; attempt += 1) {
    const statusResponse = await fetch(`https://api.cometapi.com/v1/videos/${id}`, {
      headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
    });

    if (!statusResponse.ok) {
      throw new Error(await statusResponse.text());
    }

    const status = await statusResponse.json();
    if (status.status === "completed") {
      const contentResponse = await fetch(
        `https://api.cometapi.com/v1/videos/${id}/content`,
        { headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` } },
      );
      const videoBuffer = Buffer.from(await contentResponse.arrayBuffer());
      await fs.writeFile("sora-result.mp4", videoBuffer);
      break;
    }
    if (status.status === "failed") {
      throw new Error(JSON.stringify(status));
    }
    await new Promise((resolve) => setTimeout(resolve, 5000));
  }
  ```
</CodeGroup>

## 흐름 설명

Sora 생성은 비동기식입니다. 생성 엔드포인트는 비디오 ID와 초기 status를 반환합니다. `status`가 `completed` 또는 `failed`가 될 때까지 `GET /v1/videos/<video_id>`를 폴링하세요. 작업이 완료되면 `GET /v1/videos/<video_id>/content`로 파일을 다운로드하세요.

정확한 `WxH` 크기를 사용하세요. Sora API 레퍼런스에는 표준 가로형 및 세로형 크기와 함께, Pro model 워크플로를 위한 더 큰 Pro 크기가 문서화되어 있습니다.

## 공통 파라미터

| Parameter         | 용도                                                           |
| ----------------- | ------------------------------------------------------------ |
| `model`           | Sora model ID입니다. 참조 예제에서는 `sora-2`를 사용합니다.                  |
| `prompt`          | 비디오용 텍스트 프롬프트(Prompt)입니다.                                    |
| `seconds`         | 클립 길이입니다. API 레퍼런스에는 `4`, `8`, `12`, `16`, `20`이 문서화되어 있습니다. |
| `size`            | `1280x720` 또는 `720x1280`과 같은 정확한 `WxH` 출력 크기입니다.             |
| `input_reference` | 첫 프레임 워크플로용 선택적 참조 이미지 파일입니다.                                |

## 문제 해결 / FAQ

<AccordionGroup>
  <Accordion title="생성 요청이 실패합니다">
    multipart form data를 사용하세요. 레퍼런스의 Sora 생성 요청은 JSON body가 아니라 form 필드를 사용합니다.
  </Accordion>

  <Accordion title="콘텐츠 다운로드가 실패합니다">
    status 엔드포인트가 `completed`를 보고한 후에만 콘텐츠를 다운로드하세요. 완료된 파일은 자체 스토리지에 저장하세요.
  </Accordion>

  <Accordion title="Pro size가 작동하지 않습니다">
    더 큰 Pro size는 Pro model 워크플로에서만 사용하세요. 첫 요청은 `1280x720`부터 시작하세요.
  </Accordion>
</AccordionGroup>

## 다음 단계

* [Sora 2 비디오 생성 API 레퍼런스](/api/video/sora-2/create)를 읽어보세요.
* [Sora 2 비디오 조회](/api/video/sora-2/retrieve)로 폴링하세요.
* [Sora 2 비디오 콘텐츠 조회](/api/video/sora-2/retrieve-content)로 다운로드하세요.
* [Models](/ko/overview/models)에서 사용 가능한 비디오 모델을 확인하세요.
* [비디오 생성을 위한 polling 및 webhook 사용](/ko/guides/webhook-and-polling-for-video-generation)을 검토하세요.
* [모델 호출 전 요청 비용 추정](/ko/guides/how-to-estimate-cost-before-calling-a-model)으로 작업 비용을 추정하세요.
