# Edit Captions

> Robots API reference, generated from the OpenAPI spec.

HTML version: https://www.mux.com/docs/api-reference/robots/edit-captions. Full OpenAPI spec: https://www.mux.com/api-spec.json

## Create an 'edit-captions' job

`POST https://api.mux.com/robots/v1/jobs/edit-captions`

Creates a new job that edits an existing Mux text track using static replacements, speaker-label replacements, and optional profanity censoring. Provide at least one of `replacements`, `speaker_replacements`, or `auto_censor_profanity`.

Operation ID: `create-edit-captions-job`. HTML version: https://www.mux.com/docs/api-reference/robots/edit-captions/create-edit-captions-job

### Request body

- `passthrough` (string): Arbitrary string stored with the job and returned in responses. Useful for correlating jobs with your own systems.
- `parameters` (object, required)
  - `asset_id` (string, required, minLength: 1): The Mux asset ID whose existing text track should be edited.
  - `track_id` (string, required, minLength: 1): Mux text track ID of the source captions. Must identify a ready subtitle track, or the single ready legacy text transcript without subtitle metadata on an audio-only asset. A missing or unready source is rejected.
  - `auto_censor_profanity` (object): Optional LLM-driven profanity detection and censorship rules applied to the selected caption track.
    - `detection_method` (string, default: "llm"): How profanity is detected. Currently only `llm` is supported, which uses an LLM to identify profanity in cue text. Possible values: `"llm"`.
    - `mode` (string, default: "blank"): Replacement strategy for detected profanity: blank inserts bracketed underscores, remove drops the match, and mask replaces characters with question marks. Defaults to "blank". Possible values: `"blank"`, `"remove"`, `"mask"`.
    - `always_censor` (array of string): Additional words or short phrases that should always be censored even if the model does not detect them. Each item: minLength: 1.
    - `never_censor` (array of string): Words or short phrases that should never be censored even if the model flags them. Each item: minLength: 1.
  - `replacements` (array of object): Optional static word or phrase replacements applied directly to cue text.
    - `find` (string, required, minLength: 1): Exact word or phrase to replace in cue text.
    - `replace` (string, required): Replacement text to insert when a match is found. Use an empty string to delete the match.
    - `case_sensitive` (boolean, default: false): When true, `find` is matched only with exact case. Defaults to false (case-insensitive matching), so "gonna" also matches "Gonna" and "GONNA".
  - `speaker_replacements` (array of object): Optional replacements for bracketed speaker labels at the start of caption cues. Values omit the surrounding square brackets, and matching spoken text is not changed.
    - `find` (string, required, minLength: 1): Existing speaker label without the surrounding square brackets. Must match the label in the track exactly, including case.
    - `replace` (string, required, minLength: 1): New speaker label without the surrounding square brackets.
  - `upload_to_mux` (boolean, default: true): Whether to upload the edited VTT back to the Mux asset as a text track. Defaults to true.
  - `replace_existing_tracks` (string, default: "replace"): What to do with the source track. Defaults to `replace`: the source is deleted and the edited track takes its place under the same name, language and closed-captions setting; no other track is touched, and the source is restored if the edited track can't be added. `fail` deletes nothing and adds the edited track alongside the source, so it requires a `track_name` different from the source's. Either way the request is rejected if a track other than the source already has the edited track's name. `replace` requires `upload_to_mux` to be true. Possible values: `"replace"`, `"fail"`.
  - `track_name` (string, minLength: 1): Name for the edited Mux text track. Defaults to the source track's name. Required and must differ from the source's name when `replace_existing_tracks` is `fail`. Mux requires text track names to be unique on an asset.

Example request body:

```json
{
  "parameters": {
    "asset_id": "mux_asset_123abc",
    "track_id": "text_track_456def",
    "replacements": [
      {
        "find": "Mucks",
        "replace": "Mux",
        "case_sensitive": true
      },
      {
        "find": "gonna",
        "replace": "going to"
      }
    ],
    "speaker_replacements": [
      {
        "find": "speaker_0",
        "replace": "Alice"
      }
    ],
    "upload_to_mux": true,
    "replace_existing_tracks": "replace"
  }
}
```

### Response `202`

Job queued

- `data` (object, required)
  - `id` (string, required): Unique job identifier.
  - `passthrough` (string): Arbitrary string supplied at creation, returned as-is.
  - `units_consumed` (integer, required, minimum: 0): Number of Mux AI units consumed by this job.
  - `directive` (object): The directive run that dispatched this job. Absent for jobs created via direct API POST.
    - `id` (string, required): ID of the directive that dispatched this job.
    - `run_id` (string, required): ID of the specific directive run that dispatched this job.
  - `created_at` (integer, required, minimum: 0): Unix timestamp (seconds) when the job was created.
  - `updated_at` (integer, required, minimum: 0): Unix timestamp (seconds) of the job's last state transition (e.g. when it started processing or reached a terminal state).
  - `workflow` (string, required) Possible values: `"edit-captions"`.
  - `parameters` (object, required)
    - `asset_id` (string, required, minLength: 1): The Mux asset ID whose existing text track should be edited.
    - `track_id` (string, required, minLength: 1): Mux text track ID of the source captions. Must identify a ready subtitle track, or the single ready legacy text transcript without subtitle metadata on an audio-only asset. A missing or unready source is rejected.
    - `auto_censor_profanity` (object): Optional LLM-driven profanity detection and censorship rules applied to the selected caption track.
      - `detection_method` (string, default: "llm"): How profanity is detected. Currently only `llm` is supported, which uses an LLM to identify profanity in cue text. Possible values: `"llm"`.
      - `mode` (string, default: "blank"): Replacement strategy for detected profanity: blank inserts bracketed underscores, remove drops the match, and mask replaces characters with question marks. Defaults to "blank". Possible values: `"blank"`, `"remove"`, `"mask"`.
      - `always_censor` (array of string): Additional words or short phrases that should always be censored even if the model does not detect them. Each item: minLength: 1.
      - `never_censor` (array of string): Words or short phrases that should never be censored even if the model flags them. Each item: minLength: 1.
    - `replacements` (array of object): Optional static word or phrase replacements applied directly to cue text.
      - `find` (string, required, minLength: 1): Exact word or phrase to replace in cue text.
      - `replace` (string, required): Replacement text to insert when a match is found. Use an empty string to delete the match.
      - `case_sensitive` (boolean, default: false): When true, `find` is matched only with exact case. Defaults to false (case-insensitive matching), so "gonna" also matches "Gonna" and "GONNA".
    - `speaker_replacements` (array of object): Optional replacements for bracketed speaker labels at the start of caption cues. Values omit the surrounding square brackets, and matching spoken text is not changed.
      - `find` (string, required, minLength: 1): Existing speaker label without the surrounding square brackets. Must match the label in the track exactly, including case.
      - `replace` (string, required, minLength: 1): New speaker label without the surrounding square brackets.
    - `upload_to_mux` (boolean, default: true): Whether to upload the edited VTT back to the Mux asset as a text track. Defaults to true.
    - `replace_existing_tracks` (string, default: "replace"): What to do with the source track. Defaults to `replace`: the source is deleted and the edited track takes its place under the same name, language and closed-captions setting; no other track is touched, and the source is restored if the edited track can't be added. `fail` deletes nothing and adds the edited track alongside the source, so it requires a `track_name` different from the source's. Either way the request is rejected if a track other than the source already has the edited track's name. `replace` requires `upload_to_mux` to be true. Possible values: `"replace"`, `"fail"`.
    - `track_name` (string, minLength: 1): Name for the edited Mux text track. Defaults to the source track's name. Required and must differ from the source's name when `replace_existing_tracks` is `fail`. Mux requires text track names to be unique on an asset.
  - `status` (string, required): Current job status. Possible values: `"pending"`, `"processing"`, `"completed"`, `"errored"`, `"cancelled"`.
  - `errors` (array of object): Error details. Present when status is 'errored'.
    - `type` (string, required): Stable public error category identifier. New types may be added, so handle unknown values.
    - `code` (string): Identifies the specific condition that failed, when it has a public code. Absent for other failures. New codes may be added, so handle unknown values.
    - `message` (string, required): Human-readable public error message.
    - `retryable` (boolean): Whether retrying this job may resolve the error.
  - `resources` (object): Related Mux resources linked to this job.
    - `assets` (array of object, required): Mux assets associated with this job.
      - `id` (string, required): Mux asset ID.
      - `meta` (object): Mux asset metadata, if available.
        - `title` (string): Asset title from Mux metadata.
        - `creator_id` (string): Creator identifier from Mux metadata.
        - `external_id` (string): External identifier from Mux metadata.
      - `passthrough` (string): Passthrough string from the Mux asset.
      - `_links` (object, required): Hypermedia links for the asset.
        - `self` (object, required)
          - `href` (string, required): URL to the Mux asset resource.
  - `outputs` (object): Workflow results. Present when status is 'completed'.
    - `total_replacement_count` (integer, required, minimum: 0): Total count of cue text replacements applied across all edit operations.
    - `temporary_vtt_url` (string, minLength: 1): Temporary pre-signed URL for downloading the edited VTT file. Expires 7 days after the job completes.
    - `track_id` (string, minLength: 1): Mux text track ID of the newly created edited captions, distinct from the source parameters.track_id. Present when upload_to_mux is true and the upload succeeds.
    - `replaced_track_ids` (array of string): IDs of tracks deleted during replacement. Omitted when no deletions were recorded; historical jobs may lack this information. Each item: minLength: 1.

### Errors

- `400`: Malformed JSON request body.
- `401`: Missing or invalid Mux credentials
- `403`: The access token lacks robots:write (insufficient_scope), or Robots access is inactive or suspended. A free-plan workflow or unit limit can also prevent creation. For insufficient_scope, use credentials with the required permission. If using an API access token, create a replacement token with that permission. Enabling Robots for an organization does not grant token permissions.
- `409`: Resource conflict. See the error type and messages for details.
- `422`: Asset not found or errored, missing public or signed playback access, missing or ineligible caption source, invalid edit parameters, or a conflicting edited track name.
- `500`: Server error

Every error response has this body:

- `error` (object, required)
  - `type` (string, required): Machine-readable error type. New types may be added, so handle unknown values.
  - `code` (string): Identifies the specific condition that failed, when it has a public code. Absent for other errors. New codes may be added, so handle unknown values.
  - `messages` (array of string, required): Individual error messages describing what went wrong.
