# Video generation (/docs/video-generation)

A video takes minutes to generate, so it runs as a job: `POST /v1/videos` returns right away, you poll `GET /v1/videos/{id}` until the job is finished, then download the file from `GET /v1/videos/{id}/content`. The endpoints are listed under [Videos](/docs/api/videos/createVideo) in the API reference.

## Find a video model [#find-a-video-model]

The [Models](https://www.ohmygpt.com/models?family=video) page lists every video model with its price, accepted inputs and a try-it panel. From code, ask the catalog for models that output video:

```bash
curl "https://api.ohmygpt.com/v1/models?output_modalities=video&include_unavailable=true"
```

Each model carries what a request to it may ask for:

```json
{
  "id": "xai/grok-imagine-video",
  "name": "Grok Imagine Video",
  "available": true,
  "service": "video",
  "limits": { "video": { "seconds": [8, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15] }, "max_prompt_tokens": 4096 }
}
```

| Field | Meaning |
|---|---|
| `limits.video.seconds` | The lengths you can ask for. The first one is the default. |
| `pricing` | The price for each size the model takes. `size` must be one of these sizes. |
| `architecture.input_modalities` | Whether the model takes images, videos or audio as `media` (see [Frames and references](#frames-and-references)). |
| `available` | `false` means the model is available on request. |

### Models available on request [#models-available-on-request]

Some models are listed with their prices but are enabled per account. Without `include_unavailable=true` the catalog leaves them out. Calling one returns `503`, and the message links the model page:

```json
{
  "error": {
    "param": null,
    "code": "model_unavailable",
    "message": "The model `bytedance/doubao-seedance-2.0-260128` is available on request. Request it at https://www.ohmygpt.com/models/bytedance/doubao-seedance-2.0-260128 and our team will look into it.",
    "type": "server_error"
  }
}
```

Open that page and click **Request it now**. Add your email and what you'll use the model for so our team can reach you. A model that isn't in the catalog at all can be requested from the [Models](https://www.ohmygpt.com/models) page too: search for it, and the empty result offers **Let us know**. Once a model is enabled, your existing API keys can call it.

## Price a job before you send it [#price-a-job-before-you-send-it]

Video models are priced in one of two ways, shown on each model page:

- **Per second**, with a price for each size.
- **Per million output tokens**, with a price for each size, and a separate price when the job includes a reference video. The provider counts the tokens from the length and size of the video.

To get the price of a specific job, send the body you would send to `POST /v1/videos` to [`POST /v1/cost-estimates`](/docs/api/billing/createCostEstimate). Nothing is generated or charged:

```bash
curl https://api.ohmygpt.com/v1/cost-estimates \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "xai/grok-imagine-video", "prompt": "A paper boat drifting down a rainy street at dusk", "seconds": 5, "size": "1280x720"}'
```

```json
{
  "model": "xai/grok-imagine-video",
  "estimated_input_cost": "0 credits",
  "max_output_cost": "96250 credits",
  "max_total_cost": "96250 credits",
  "credits": 96250,
  "confidence": "exact",
  "estimated_input_tokens": 0,
  "max_output_tokens": 0
}
```

96,250 Credits is $0.385 (1 USD = 250,000 Credits): 5 seconds at 19,250 Credits per second for 1280×720. Leave out `seconds` and the estimate uses the default length, 8 seconds here, for 154,000 Credits. Token-priced models are estimated the same way; `doubao-seedance-2.5-260628` at the same `seconds` and `size` returns `"credits": 285863`. The estimate uses the prices your account pays, and `exact` means it is the amount the job is priced at when created.

## What a job costs [#what-a-job-costs]

- **At creation**, OhMyGPT prices the job from `seconds`, `size` and `media`, and reserves at least that amount from your balance until the job finishes. If your balance, minus what your other unfinished requests have reserved, can't cover it, the request fails with `402 insufficient_credits` and the job isn't created.
- **When the job finishes**, you are charged once, at the unit prices in effect when you created it, for what the provider reports it generated and processed: the length and size of the video, and inputs it charges for, such as the length of a reference video. That amount usually equals the estimate. It can differ when the provider generates a different length or resolution than requested, or counts input it charges for, such as a reference video.
- **Not charged**: jobs you cancel, jobs the model never accepted, and jobs the provider can no longer report on.
- **Failed, blocked or timed out**: charged only when the provider bills for the generation anyway, which most don't. Some providers charge for an output their content policy blocked. For content policy blocks and timeouts, the job's `error.message` says whether you were charged.

The charge shows on the [Usage](https://www.ohmygpt.com/usage) page once the job finishes.

## Create a video [#create-a-video]

`Idempotency-Key` is required. Use a new value for each job; sending the same key again returns the job it created instead of starting a second one, so a retry after a network error can't pay twice.

```bash
curl https://api.ohmygpt.com/v1/videos \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"model": "xai/grok-imagine-video", "prompt": "A paper boat drifting down a rainy street at dusk", "seconds": 5, "size": "1280x720"}'
```

The response is the job:

```json
{
  "id": "job-6f1d3c2a-8b4e-4f7a-9c1d-2e5b7a9f0c13",
  "object": "video",
  "model": "xai/grok-imagine-video",
  "status": "queued",
  "progress": 0,
  "seconds": 5,
  "size": "1280x720",
  "result_available": false,
  "created_at": "2026-11-23T08:00:00Z",
  "updated_at": "2026-11-23T08:00:01Z"
}
```

| Field | Rule |
|---|---|
| `model`, `prompt` | Required |
| `seconds` | One of the model's `limits.video.seconds`; the first one when left out. A number or a numeric string such as `"8"`, as the OpenAI SDK sends it |
| `size` | Width×height, one of the sizes in the model's pricing; when left out, `1280x720` if the model prices it, otherwise the first size in its pricing |
| `media` | Frames and references, see below |

Other top-level fields go to the model unchanged. They can't set the length, size, media or sound; use `seconds`, `size`, `media` and `audio` for those, or the request fails with `400`. Callback fields such as `callback_url` are refused too: poll the job for its result.

## Poll the job [#poll-the-job]

```bash
curl https://api.ohmygpt.com/v1/videos/$VIDEO_ID \
  -H "Authorization: Bearer $OHMYGPT_API_KEY"
```

Reading a job doesn't call the model, so polling every few seconds is fine.

| `status` | Meaning |
|---|---|
| `creating` | Not yet accepted by the model |
| `queued` | Waiting to start; the only state in which you can cancel |
| `in_progress` | Generating; `progress` is the percentage the model reports |
| `completed` | Done; download it while `result_available` is `true` |
| `failed` | `error.code` and `error.message` say why |
| `cancelled` | You cancelled it; not charged |

`completed`, `failed` and `cancelled` are final.

## Download the video [#download-the-video]

```bash
curl https://api.ohmygpt.com/v1/videos/$VIDEO_ID/content \
  -H "Authorization: Bearer $OHMYGPT_API_KEY" \
  -o video.mp4
```

The download is available until `result_url_expires_at`, 12 to 24 hours after the job finishes depending on the model. Save the file before then. After it expires, `result_available` turns `false` and the download answers `410`. `DELETE /v1/videos/{id}` clears an expired result; before expiry it answers `409`. The job itself stays readable.

## Cancel a job [#cancel-a-job]

```bash
curl -X POST https://api.ohmygpt.com/v1/videos/$VIDEO_ID/cancel \
  -H "Authorization: Bearer $OHMYGPT_API_KEY"
```

A job can be cancelled only while it is still queued with the model; the response is the job with `status: "cancelled"`, and it isn't charged. Once generation has started the request answers `409`. Models whose provider has no way to cancel answer `501`.

## Frames and references [#frames-and-references]

`media` turns a text-to-video request into image-to-video or reference-to-video. Each entry has a `type` and a `url`, which can be a public URL or a data URL:

```json
{
  "model": "qwen/happyhorse-1.1-i2v",
  "prompt": "The lighthouse beam sweeps across the bay as waves roll in",
  "seconds": 5,
  "size": "1280x720",
  "media": [{ "type": "first_frame", "url": "https://example.com/lighthouse.png" }]
}
```

| `type` | Needs a model that takes |
|---|---|
| `first_frame`, `last_frame`, `reference_image` | Image input |
| `reference_video` | Video input |
| `reference_audio` | Audio input |

Which roles and how many a model takes are on its model page; a role the model doesn't take fails with `400` before anything is generated.

## Complete example [#complete-example]

Create, poll and download in one script:

```python
import os
import time
import uuid

import requests

url = "https://api.ohmygpt.com/v1/videos"
headers = {"Authorization": "Bearer " + os.environ["OHMYGPT_API_KEY"]}

response = requests.post(
    url,
    headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
    json={
        "model": "xai/grok-imagine-video",
        "prompt": "A paper boat drifting down a rainy street at dusk",
        "seconds": 5,
        "size": "1280x720",
    },
)
response.raise_for_status()
job = response.json()

while job["status"] not in ("completed", "failed", "cancelled"):
    time.sleep(5)
    job = requests.get(f"{url}/{job['id']}", headers=headers).json()

if job["status"] == "completed":
    video = requests.get(f"{url}/{job['id']}/content", headers=headers)
    video.raise_for_status()
    with open("video.mp4", "wb") as f:
        f.write(video.content)
else:
    print(job.get("error"))
```

## List your jobs [#list-your-jobs]

`GET /v1/videos` lists your jobs, newest first, 20 per page by default (up to `limit=100`), with `next_cursor` for the next page. It reads your whole account, so it needs an admin key; turn on **Admin key** on the [API keys](https://www.ohmygpt.com/keys) page. Other keys get `403 permission_denied` and can still read a job by its ID.

## Errors [#errors]

When creating a job:

| Status | `code` | What to do |
|---|---|---|
| 400 | `missing_required_parameter` | Add the `Idempotency-Key` header. |
| 400 | `invalid_parameter` | The message lists the values the model takes, such as ``Invalid `seconds`: must be one of `1`, `2`, `3`, … `15`.`` Pick one of them. |
| 400 | `content_policy_violation` | The model refused the prompt or media. You weren't charged. Revise the prompt and create a new job. |
| 400 | `invalid_request` | The model couldn't create this video. Check the prompt and parameters. |
| 402 | `insufficient_credits` | Your balance can't cover the job's price. Top up on the [Billing](https://www.ohmygpt.com/billing) page, or wait for your other jobs to finish. |
| 503 | `model_unavailable` | The model is [available on request](#models-available-on-request), or can't take jobs right now. Follow the message. |

In `error.code` of a failed job:

| `error.code` | Meaning |
|---|---|
| `content_policy_violation` | The model blocked the request or the output. The message says whether you were charged. |
| `upstream_video_failed` | The model failed to generate; the message is the model's reason. Create a new job. |
| `model_timeout` | The model didn't finish within the time limit. The message says whether you were charged. |
| `model_unavailable` | The model can no longer report on this job. You weren't charged. |
| `upstream_create_rejected`, `upstream_create_ambiguous` | The job couldn't be created with the model. You weren't charged. Create a new job. |

When reading, downloading, cancelling or deleting, the reason is in `error.type`:

| Status | `error.type` | What to do |
|---|---|---|
| 404 | `job_not_found` | Check the job ID. A job is visible only to the account that created it. |
| 409 | `job_not_ready` | The video isn't ready to download, or isn't expired yet so it can't be deleted. Wait for `completed`. |
| 409 | `conflict_error` | The job has already started generating, or has finished, so it can't be cancelled. Read the job for its current status. |
| 410 | `result_expired` | The download expired. Create the video again. |
| 501 | `not_implemented` | This model can't cancel jobs. |
| 502 | `result_fetch_blocked` | The video couldn't be downloaded. Try again in a few seconds. |

The full list of status codes is on [Errors](/docs/errors).
