> ## 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 quickstart: Generate videos with CometAPI

> Create a Sora 2 video job with CometAPI, poll status, and download completed video content with curl, Python, or Node.js.

## What you will build

You will submit a Sora 2 video job, store the returned video ID, poll until the job completes, and download the finished video content.

## Prerequisites

* A CometAPI API key stored in `COMETAPI_KEY`
* Python 3.10+ with `requests`, or Node.js 18+
* A server-side worker or job queue for polling

## API key, base URL, authentication

Create Sora jobs with:

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

Poll status with:

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

Download completed content with:

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

Authenticate with a Bearer token:

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

## Code examples

Use the tabs below for copyable examples in cURL, Python, and 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>

## Flow explanation

Sora generation is asynchronous. The create endpoint returns a video ID and an initial status. Poll `GET /v1/videos/<video_id>` until `status` is `completed` or `failed`. When the job is complete, download the file with `GET /v1/videos/<video_id>/content`.

Use exact `WxH` sizes. The Sora API reference documents standard landscape and portrait sizes, with larger Pro sizes for Pro model workflows.

## Common parameters

| Parameter         | Use                                                                        |
| ----------------- | -------------------------------------------------------------------------- |
| `model`           | Sora model ID. The reference example uses `sora-2`.                        |
| `prompt`          | Text prompt for the video.                                                 |
| `seconds`         | Clip duration. The API reference documents `4`, `8`, `12`, `16`, and `20`. |
| `size`            | Exact `WxH` output size, such as `1280x720` or `720x1280`.                 |
| `input_reference` | Optional reference image file for first-frame workflows.                   |

## Troubleshooting / FAQ

<AccordionGroup>
  <Accordion title="The create request fails">
    Use multipart form data. Sora create requests in the reference use form fields, not a JSON body.
  </Accordion>

  <Accordion title="The content download fails">
    Download content only after the status endpoint reports `completed`. Store the finished file in your own storage.
  </Accordion>

  <Accordion title="A Pro size does not work">
    Use larger Pro sizes only with a Pro model workflow. Start with `1280x720` for a first request.
  </Accordion>
</AccordionGroup>

## Next steps

* Read the [Create a Sora 2 video API reference](/api/video/sora-2/create).
* Poll with [Retrieve a Sora 2 video](/api/video/sora-2/retrieve).
* Download with [Retrieve Sora 2 video content](/api/video/sora-2/retrieve-content).
* Find available video models in [Models](/overview/models).
* Review [Use polling and webhooks for video generation](/guides/webhook-and-polling-for-video-generation).
* Estimate task cost with [Estimate request cost before calling a model](/guides/how-to-estimate-cost-before-calling-a-model).
