# Edit videos with source clips and references

> OpenGen video-edit modifies an existing workspace-private clip via input.sourceVideo (uploaded up to 100 MiB or reused from an owned prior job output) or top-level previousJobId. Inspect each model's exact override restrictions with GET /v1/models/{provider}/{model}?operation=video-edit because models like FLUX 3 Video preserve source duration and dimensions, estimate cost with POST /v1/pricing/estimate, and submit once with a persisted Idempotency-Key.

## Agent Prompt

```text
Walk me through a video-edit generation on OpenGen (https://opengen.dev):
1. Discover models supporting video-edit via GET https://opengen.dev/v1/models?operation=video-edit (or MCP find_models with operation="video-edit").
2. Inspect the exact model via GET https://opengen.dev/v1/models/{provider}/{model}?operation=video-edit (or MCP get_model, e.g. id="bfl/flux-3-video" or "xai/grok-imagine-video", operation="video-edit") to check which override fields (duration, resolution, aspectRatio, audio) are forbidden vs allowed.
3. Upload the source MP4/WebM via POST https://opengen.dev/v1/assets (presigned PUT up to 100 MiB) or reuse an owned OpenGen video output via POST https://opengen.dev/v1/assets with source="job_output" (or pass top-level previousJobId when supported).
4. Run POST https://opengen.dev/v1/pricing/estimate (or MCP estimate_cost) and wait for my confirmation of the selected route and maxCostMicros spend ceiling.
5. Submit once with a persisted Idempotency-Key via POST https://opengen.dev/v1/generations or MCP generate, and follow read-only via job_get until delivered.
```

OpenGen `video-edit` transforms an existing private video clip (`input.sourceVideo`) or continues a prior owned generation (`previousJobId`) with prompt-guided lighting, weather, object, or style edits. Because providers enforce very different override rules on video editing, OpenGen validates every field before admission instead of silently discarding unsupported parameters.

## 1. Check per-model `video-edit` constraints

| Model                                                                                                     | Route(s) & verification scope                                                                                                                              | Required source                  | Forbidden / restricted fields on `video-edit`                                                                                                                                               |
| --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [FLUX 3 Video](/bfl/flux-3-video) (`bfl/flux-3-video`)                                                    | `bfl-undisclosed/bfl-flux-3-video` (active BFL adapter; live-verified for `text-to-video` `720p`/`5s`, `video-edit` remains `documented`)                  | `sourceVideo` or `previousJobId` | Preserves source clip length (up to 15s), dimensions (downscales >720p to 720p), and audio; `duration`, `resolution`, `aspectRatio`, and `audio` are rejected. Published tariff: `$0.03/s`. |
| [Grok Imagine Video](/xai/grok-imagine-video?variant=xai%2Fgrok-imagine-video) (`xai/grok-imagine-video`) | `xai-undisclosed/xai-grok-imagine-video` (live-verified for `video-edit` at `720p`/`3s`; other durations/resolutions remain `documented`)                  | `sourceVideo` or `previousJobId` | Preserves source clip duration (`duration` is rejected); accepts `resolution` (`480p`/`720p`), `aspectRatio`, `audio`, and up to `7` image `references`.                                    |
| [Kling 4.0](/kling/kling-4.0) (`kling/kling-4.0`)                                                         | `kling-ap-southeast-1/kling-kling-4.0`, `runway-undisclosed/kling-kling-4.0` (live-verified for `text-to-video` `720p`/`3s`; `video-edit` is `documented`) | `sourceVideo` or `previousJobId` | Accepts `prompt` (required), `duration`, `resolution`, `references`, and `elements`; `audio` is always on.                                                                                  |
| [Gemini Omni 1.2 Flash](/google/gemini-omni-1.2-flash) (`google/gemini-omni-1.2-flash`)                   | Documented routes                                                                                                                                          | `sourceVideo` or `previousJobId` | Supports stateful `previousJobId` continuation pinned to the originating deployment and model version.                                                                                      |

```bash tab="cURL"
curl --fail-with-body \
  "https://opengen.dev/v1/models?operation=video-edit"

curl --fail-with-body \
  "https://opengen.dev/v1/models/bfl/flux-3-video?operation=video-edit"
```

```ts tab="TypeScript"
const origin = process.env.OPENGEN_API_URL ?? 'https://opengen.dev';
const detail = await fetch(`${origin}/v1/models/bfl/flux-3-video?operation=video-edit`).then((r) =>
  r.json(),
);
console.log(detail.model.generationProfiles[0].commonArguments);
```

```python tab="Python"
import os
import httpx

origin = os.environ.get("OPENGEN_API_URL", "https://opengen.dev")
with httpx.Client(timeout=30.0) as client:
    detail = client.get(
        f"{origin}/v1/models/bfl/flux-3-video",
        params={"operation": "video-edit"},
    ).raise_for_status().json()
    print(detail["model"]["generationProfiles"][0]["commonArguments"])
```

```json tab="MCP"
{
  "tool": "get_model",
  "arguments": {
    "id": "bfl/flux-3-video",
    "operation": "video-edit"
  }
}
```

```bash tab="CLI"
opengen catalog search --operation video-edit
opengen catalog get bfl/flux-3-video
opengen pricing --model bfl/flux-3-video --operation video-edit
```

## 2. Upload a private MP4/WebM or reuse a prior OpenGen video output

For local video clips (up to **100 MiB** MP4 or WebM), use the presigned single-PUT flow (`POST /v1/assets` -> storage `PUT` -> `POST /v1/assets/complete`). If the clip was generated by an earlier OpenGen job in the same workspace, skip re-uploading completely and copy it server-side with `source: "job_output"`:

```bash tab="cURL"
# Reuse a completed OpenGen video output as an independent ready input asset
curl --fail-with-body \
  -X POST "https://opengen.dev/v1/assets" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: reuse-vid-$(uuidgen | tr '[:upper:]' '[:lower:]')" \
  --data '{
    "source": "job_output",
    "sourceJobId": "550e8400-e29b-41d4-a716-446655440000",
    "outputIndex": 0
  }'
```

```ts tab="TypeScript"
import { randomUUID } from 'node:crypto';

const origin = process.env.OPENGEN_API_URL ?? 'https://opengen.dev';
const auth = {
  Authorization: `Bearer ${process.env.OPENGEN_API_KEY}`,
  'Content-Type': 'application/json',
};

const reused = await fetch(`${origin}/v1/assets`, {
  method: 'POST',
  headers: { ...auth, 'Idempotency-Key': `reuse-vid-${randomUUID()}` },
  body: JSON.stringify({
    source: 'job_output',
    sourceJobId: '550e8400-e29b-41d4-a716-446655440000',
    outputIndex: 0,
  }),
}).then((r) => r.json());
console.log(reused.assetKey, reused.state);
```

```python tab="Python"
import os
import uuid
import httpx

origin = os.environ.get("OPENGEN_API_URL", "https://opengen.dev")
auth = {"Authorization": f"Bearer {os.environ['OPENGEN_API_KEY']}"}

with httpx.Client(timeout=60.0) as client:
    reused = client.post(
        f"{origin}/v1/assets",
        headers={**auth, "Idempotency-Key": f"reuse-vid-{uuid.uuid4()}"},
        json={
            "source": "job_output",
            "sourceJobId": "550e8400-e29b-41d4-a716-446655440000",
            "outputIndex": 0,
        },
    ).raise_for_status().json()
    print(reused["assetKey"], reused["state"])
```

```json tab="MCP"
{
  "tool": "upload_asset",
  "arguments": {
    "source": "job_output",
    "sourceJobId": "550e8400-e29b-41d4-a716-446655440000",
    "outputIndex": 0,
    "idempotencyKey": "reuse-vid-001"
  }
}
```

```bash tab="CLI"
# For a local clip up to 100 MiB:
opengen upload /absolute/path/source-clip.mp4 --media-type video/mp4
```

## 3. Estimate route eligibility before submitting

Notice that `bfl/flux-3-video` on `video-edit` accepts only `prompt` and `sourceVideo` (plus optional `count`).

> [!IMPORTANT]
> Because `video-edit` pricing depends on the decoded duration and dimensions of `input.sourceVideo`, managed `video-edit` quotes on `bfl-undisclosed/bfl-flux-3-video` (and other `video-edit` routes in the current catalog) are **comparison-only** (`estimatedCostMicros: null`, `selectedRouteId: null`, reason `"Request price is not qualified; comparison only."`). To execute live `video-edit` jobs today, connect your own provider credential and submit with `"billing": "byok"` (your connected provider account is billed directly; omit `maxCostMicros`, since OpenGen cannot enforce a spend cap on direct BYOK charges).

```bash tab="cURL"
set -eu
umask 077
if [ -e video-edit-submission.key ]; then
  echo "Existing video-edit-submission.key found; recover read-only via GET /v1/generations/lookup before replacing video-edit-request.json." >&2
  exit 1
fi
rm -f video-edit-request.json
cat <<'JSON' > video-edit-request.json
{
  "modelId": "bfl/flux-3-video",
  "operation": "video-edit",
  "input": {
    "prompt": "Change the overcast sky to warm golden-hour sunlight and add gentle reflections on the wet pavement.",
    "sourceVideo": {
      "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_VIDEO_UUID.mp4"
    }
  },
  "routeId": "bfl-undisclosed/bfl-flux-3-video",
  "billing": "byok"
}
JSON
chmod 600 video-edit-request.json

# Dry-run estimate only (review selectedRouteId and workspaceEligibility before submitting)
curl --fail-with-body \
  -X POST "https://opengen.dev/v1/pricing/estimate" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  --data @video-edit-request.json
```

```json tab="MCP"
{
  "tool": "estimate_cost",
  "arguments": {
    "modelId": "bfl/flux-3-video",
    "operation": "video-edit",
    "input": {
      "prompt": "Change the overcast sky to warm golden-hour sunlight and add gentle reflections on the wet pavement.",
      "sourceVideo": {
        "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_VIDEO_UUID.mp4"
      }
    },
    "routeId": "bfl-undisclosed/bfl-flux-3-video",
    "billing": "byok"
  }
}
```

```bash tab="CLI"
opengen pricing estimate --input video-edit-request.json
```

### Submit once after reviewing the estimate

Run this step only after reviewing the estimate output above and confirming `selectedRouteId`, `workspaceEligibility`, and your BYOK billing payer.

```bash tab="cURL"
set -eu
umask 077
if [ -e video-edit-submission.key ]; then
  echo "Existing video-edit-submission.key found; recover read-only via GET /v1/generations/lookup before creating a new submission." >&2
  exit 1
fi
RAW_UUID="$(uuidgen)"
[ -n "$RAW_UUID" ] || { echo "uuidgen failed" >&2; exit 1; }
IDEMPOTENCY_KEY="vedit-$(printf '%s' "$RAW_UUID" | tr '[:upper:]' '[:lower:]')"
(set -C; printf '%s\n' "$IDEMPOTENCY_KEY" > video-edit-submission.key)

curl --fail-with-body \
  -X POST "https://opengen.dev/v1/generations" \
  -H "Authorization: Bearer $OPENGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  --data @video-edit-request.json > video-edit-receipt.json
```

```ts tab="TypeScript"
import { randomUUID } from 'node:crypto';
import { writeFile } from 'node:fs/promises';

const editVideoPayload = {
  modelId: 'bfl/flux-3-video',
  operation: 'video-edit',
  input: {
    prompt:
      'Change the overcast sky to warm golden-hour sunlight and add gentle reflections on the wet pavement.',
    sourceVideo: { assetKey: reused.assetKey },
  },
  routeId: 'bfl-undisclosed/bfl-flux-3-video',
  billing: 'byok',
} as const;

const estRes = await fetch(`${origin}/v1/pricing/estimate`, {
  method: 'POST',
  headers: auth,
  body: JSON.stringify(editVideoPayload),
});
if (!estRes.ok) throw new Error(`Estimate failed (${estRes.status}): ${await estRes.text()}`);
const estimate = await estRes.json();
console.log('Review estimate before submitting:', estimate);

const eligibility = estimate.workspaceEligibility;
const canSubmit = Boolean(
  estimate.selectedRouteId &&
  eligibility?.policyAllowed === true &&
  eligibility.hasActiveBillingHold === false &&
  eligibility.executableCandidateCount > 0 &&
  (eligibility.billingMode === 'byok' || eligibility.sufficientBalance === true) &&
  Array.isArray(eligibility.blockers) &&
  eligibility.blockers.length === 0,
);
if (canSubmit && process.env.CONFIRM_SUBMIT === '1') {
  const idempotencyKey = `vedit-${randomUUID()}`;
  await writeFile(
    'video-edit-submission.json',
    JSON.stringify({ idempotencyKey, payload: editVideoPayload }, null, 2),
    { mode: 0o600, flag: 'wx' },
  );
  const genRes = await fetch(`${origin}/v1/generations`, {
    method: 'POST',
    headers: { ...auth, 'Idempotency-Key': idempotencyKey },
    body: JSON.stringify(editVideoPayload),
  });
  if (!genRes.ok) throw new Error(`Generation failed (${genRes.status}): ${await genRes.text()}`);
  const job = await genRes.json();
  console.log(job.id, job.status);
}
```

```python tab="Python"
import json
import os
import uuid

edit_video_payload = {
    "modelId": "bfl/flux-3-video",
    "operation": "video-edit",
    "input": {
        "prompt": "Change the overcast sky to warm golden-hour sunlight and add gentle reflections on the wet pavement.",
        "sourceVideo": {"assetKey": reused["assetKey"]},
    },
    "routeId": "bfl-undisclosed/bfl-flux-3-video",
    "billing": "byok",
}

with httpx.Client(timeout=45.0) as client:
    estimate = client.post(
        f"{origin}/v1/pricing/estimate",
        headers=auth,
        json=edit_video_payload,
    ).raise_for_status().json()
    print("Review estimate before submitting:", estimate)

    eligibility = estimate.get("workspaceEligibility") or {}
    can_submit = (
        bool(estimate.get("selectedRouteId"))
        and eligibility.get("policyAllowed") is True
        and eligibility.get("hasActiveBillingHold") is False
        and eligibility.get("executableCandidateCount", 0) > 0
        and (eligibility.get("billingMode") == "byok" or eligibility.get("sufficientBalance") is True)
        and eligibility.get("blockers") == []
    )
    if can_submit and os.environ.get("CONFIRM_SUBMIT") == "1":
        idempotency_key = f"vedit-{uuid.uuid4()}"
        fd = os.open("video-edit-submission.json", os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
        with os.fdopen(fd, "w", encoding="utf-8") as handle:
            json.dump({"idempotencyKey": idempotency_key, "payload": edit_video_payload}, handle, indent=2)
        job = client.post(
            f"{origin}/v1/generations",
            headers={**auth, "Idempotency-Key": idempotency_key},
            json=edit_video_payload,
        ).raise_for_status().json()
        print(job["id"], job["status"])
```

```json tab="MCP"
{
  "tool": "generate",
  "arguments": {
    "idempotencyKey": "vedit-example-001",
    "modelId": "bfl/flux-3-video",
    "operation": "video-edit",
    "input": {
      "prompt": "Change the overcast sky to warm golden-hour sunlight and add gentle reflections on the wet pavement.",
      "sourceVideo": {
        "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_VIDEO_UUID.mp4"
      }
    },
    "routeId": "bfl-undisclosed/bfl-flux-3-video",
    "billing": "byok"
  }
}
```

```bash tab="CLI"
set -eu
umask 077
if [ -e video-edit-submission.key ]; then
  echo "Existing video-edit-submission.key found; run 'opengen job recover --idempotency-key \"\$(cat video-edit-submission.key)\"' before creating a new submission." >&2
  exit 1
fi
RAW_UUID="$(uuidgen)"
[ -n "$RAW_UUID" ] || { echo "uuidgen failed" >&2; exit 1; }
IDEMPOTENCY_KEY="vedit-$(printf '%s' "$RAW_UUID" | tr '[:upper:]' '[:lower:]')"
(set -C; printf '%s\n' "$IDEMPOTENCY_KEY" > video-edit-submission.key)
opengen generate --input video-edit-request.json --idempotency-key "$IDEMPOTENCY_KEY" > video-edit-receipt.json
```

### Reference-guided editing on Grok Imagine Video

If you want to specify target resolution (`480p` or `720p`) or supply reference images alongside `sourceVideo`, use [Grok Imagine Video](/xai/grok-imagine-video?variant=xai%2Fgrok-imagine-video) (`xai/grok-imagine-video`, omitting `duration`, with `"billing": "byok"` since managed `video-edit` quotes are comparison-only):

```json
{
  "modelId": "xai/grok-imagine-video",
  "operation": "video-edit",
  "input": {
    "prompt": "Swap the jacket in the clip to the emerald wool coat shown in the reference image.",
    "sourceVideo": {
      "assetKey": "inputs/YOUR_WORKSPACE/RETURNED_VIDEO_UUID.mp4"
    },
    "references": [
      {
        "type": "image",
        "asset": {
          "assetKey": "inputs/YOUR_WORKSPACE/COAT_REF_UUID.png"
        }
      }
    ],
    "resolution": "720p",
    "aspectRatio": "source"
  },
  "routeId": "xai-undisclosed/xai-grok-imagine-video",
  "billing": "byok"
}
```

## 4. Poll and verify delivered output

Poll `GET /v1/generations/{id}/status?waitMs=25000` (or MCP `job_get`) until `deliveryStatus: "available"`, then download privately via `GET /v1/generations/{id}`. Recover any interrupted submission read-only via `GET /v1/generations/lookup?idempotencyKey=$IDEMPOTENCY_KEY`.

## Next steps

- Need to add new footage to the end of a clip instead of editing existing frames? See [Video Extension](/docs/guides/video-extend).
- Learn how input pins protect tombstoned source videos during active jobs in [Owned Assets](/docs/assets).

## Supported Models

Live catalog variants supporting `video-edit` (single-source tariffs from `@media-router/catalog`; unknown prices stay `Unknown`, never `$0`).

| Model | Exact ID | Creator | Routes | Lowest published rate | Weights | Inspect schema |
| --- | --- | --- | --- | --- | --- | --- |
| [Wan 3.0](https://opengen.dev/alibaba/wan-3.0#variant-alibaba-wan-3.0) | `alibaba/wan-3.0` | Alibaba | 6 | $0.041256 / sec | Closed | `GET /v1/models/alibaba/wan-3.0?operation=video-edit` |
| [Wan 3.0 Prime](https://opengen.dev/alibaba/wan-3.0#variant-alibaba-wan-3.0-prime) | `alibaba/wan-3.0-prime` | Alibaba | 6 | $0.0636 / sec | Closed | `GET /v1/models/alibaba/wan-3.0-prime?operation=video-edit` |
| [Grok Imagine Video · Edit / Extend](https://opengen.dev/xai/grok-imagine-video#variant-xai-grok-imagine-video) | `xai/grok-imagine-video` | xAI | 4 | $0.05 / sec | Closed | `GET /v1/models/xai/grok-imagine-video?operation=video-edit` |
| [Kling 4.0](https://opengen.dev/kling/kling-4.0#variant-kling-kling-4.0) | `kling/kling-4.0` | Kling AI | 3 | $0.157 / sec | Closed | `GET /v1/models/kling/kling-4.0?operation=video-edit` |
| [Kling 4.0 Flash](https://opengen.dev/kling/kling-4.0#variant-kling-kling-4.0-flash) | `kling/kling-4.0-flash` | Kling AI | 3 | $0.094 / sec | Closed | `GET /v1/models/kling/kling-4.0-flash?operation=video-edit` |
| [FLUX 3 Video](https://opengen.dev/bfl/flux-3-video#variant-bfl-flux-3-video) | `bfl/flux-3-video` | Black Forest Labs | 2 | $0.03 / sec | Closed | `GET /v1/models/bfl/flux-3-video?operation=video-edit` |
| [Gemini Omni 1.1 Flash](https://opengen.dev/google/gemini-omni-1.1-flash#variant-google-gemini-omni-1.1-flash) | `google/gemini-omni-1.1-flash` | Google | 5 | $0.03 / sec | Closed | `GET /v1/models/google/gemini-omni-1.1-flash?operation=video-edit` |
| [Gemini Omni 1.2 Flash](https://opengen.dev/google/gemini-omni-1.2-flash#variant-google-gemini-omni-1.2-flash) | `google/gemini-omni-1.2-flash` | Google | 3 | $0.02 / sec | Closed | `GET /v1/models/google/gemini-omni-1.2-flash?operation=video-edit` |
| [Seedance 2.5](https://opengen.dev/bytedance/seedance-2.5#variant-bytedance-seedance-2.5) | `bytedance/seedance-2.5` | ByteDance | 1 | $0.20 / sec | Closed | `GET /v1/models/bytedance/seedance-2.5?operation=video-edit` |
| [Seedance 2.5 Flash](https://opengen.dev/bytedance/seedance-2.5#variant-bytedance-seedance-2.5-flash) | `bytedance/seedance-2.5-flash` | ByteDance | 1 | $0.13 / sec | Closed | `GET /v1/models/bytedance/seedance-2.5-flash?operation=video-edit` |
| [MiniMax H3](https://opengen.dev/minimax/h3#variant-minimax-h3) | `minimax/h3` | MiniMax | 1 | $0.08 / sec | Open weights | `GET /v1/models/minimax/h3?operation=video-edit` |
