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

# Character Replace API Reference - Magic Hour Docs

> **What this API does**

Create the same Character Replace you can make in the browser, but programmatically, so you can automate it, run it at scale, or connect it to your own app or workflow.
    
**Good for**
- Automation and batch processing  
- Adding character replace into apps, pipelines, or tools  

**How it works (3 steps)**
1) Upload your inputs (video, image, or audio) with [Generate Upload URLs](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls) and copy the `file_path`.  
2) Send a request to create a character replace job with the basic fields.  
3) Check the job status until it's `complete`, then download the result from `downloads`.

**Key options**
- Inputs: usually a file, sometimes a YouTube link, depending on project type  
- Resolution: free users are limited to 576px; higher plans unlock HD and larger sizes  
- Extra fields: e.g. `face_swap_mode`, `start_seconds`/`end_seconds`, or a text prompt  

**Cost**  
Credits are only charged for the frames that actually render. You'll see an estimate when the job is queued, and the final total after it's done.

For detailed examples, see the [product page](https://magichour.ai/products/character-replace).



## OpenAPI

````yaml post /v1/character-replace
openapi: 3.0.2
info:
  title: Magic Hour API
  version: beta
  description: >

    Magic Hour provides an API (beta) that can be integrated into your own
    application to generate videos and images using AI. 


    Webhook documentation can be found
    [here](https://magichour.ai/docs/webhook).


    If you have any questions, please reach out to us via
    [discord](https://discord.gg/JX5rgsZaJp).


    # Authentication


    Every request requires an API key.


    To get started, first generate your API key
    [here](https://magichour.ai/settings/developer).


    Then, add the `Authorization` header to the request.


    | Key | Value |

    |-|-|

    | Authorization | Bearer mhk_live_apikey |


    > **Warning**: any API call that renders a video will utilize credits in
    your account.
  termsOfService: https://magichour.ai/terms-of-service
servers:
  - url: https://api.magichour.ai
security: []
tags:
  - name: Files
    description: API related to uploading assets used for video generation
  - name: Image Projects
    description: API related to image projects
  - name: Video Projects
    description: API related to video projects
  - name: Audio Projects
    description: API related to audio projects
paths:
  /v1/character-replace:
    post:
      tags:
        - Video Projects
      summary: Character Replace
      description: >-
        **What this API does**


        Create the same Character Replace you can make in the browser, but
        programmatically, so you can automate it, run it at scale, or connect it
        to your own app or workflow.
            
        **Good for**

        - Automation and batch processing  

        - Adding character replace into apps, pipelines, or tools  


        **How it works (3 steps)**

        1) Upload your inputs (video, image, or audio) with [Generate Upload
        URLs](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls)
        and copy the `file_path`.  

        2) Send a request to create a character replace job with the basic
        fields.  

        3) Check the job status until it's `complete`, then download the result
        from `downloads`.


        **Key options**

        - Inputs: usually a file, sometimes a YouTube link, depending on project
        type  

        - Resolution: free users are limited to 576px; higher plans unlock HD
        and larger sizes  

        - Extra fields: e.g. `face_swap_mode`, `start_seconds`/`end_seconds`, or
        a text prompt  


        **Cost**  

        Credits are only charged for the frames that actually render. You'll see
        an estimate when the job is queued, and the final total after it's done.


        For detailed examples, see the [product
        page](https://magichour.ai/products/character-replace).
      operationId: characterReplace.createVideo
      parameters: []
      requestBody:
        required: true
        description: Body
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Give your video a custom name for easy identification.
                  example: My Character Replace video
                  default: Character Replace - dateTime
                start_seconds:
                  default: 0
                  type: number
                  minimum: 0
                  description: Start time of your clip (seconds). Must be ≥ 0.
                  format: float
                  example: 0
                end_seconds:
                  type: number
                  minimum: 0.1
                  description: >-
                    End time of your clip (seconds). Must be greater than
                    start_seconds.
                  format: float
                  example: 15
                resolution:
                  type: string
                  enum:
                    - 480p
                    - 720p
                  description: >-
                    Output video resolution. Defaults to 480p, the lowest
                    resolution available on your plan.
                  example: 720p
                assets:
                  type: object
                  properties:
                    video_file_path:
                      type: string
                      minLength: 1
                      description: >
                        Source video containing the subject to replace or
                        animate. This value is either

                        - a direct URL to the video file

                        - `file_path` field from the response of the [upload
                        urls
                        API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls).


                        See the [file upload
                        guide](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file)
                        for details.
                      example: api-assets/id/1234.mp4
                    image_file_path:
                      type: string
                      minLength: 1
                      description: >
                        Reference character image used as the replacement or
                        animation target. This value is either

                        - a direct URL to the video file

                        - `file_path` field from the response of the [upload
                        urls
                        API](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls).


                        See the [file upload
                        guide](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls#input-file)
                        for details.
                      example: api-assets/id/5678.png
                  required:
                    - video_file_path
                    - image_file_path
                  description: Source video and reference character image for the job.
                style:
                  type: object
                  properties:
                    mode:
                      type: string
                      enum:
                        - replace
                        - animate
                      description: >-
                        Processing mode. `replace` swaps the detected subject
                        with your reference character. `animate` transfers
                        motion from the video onto your character image.
                      example: replace
                    selection_mode:
                      type: string
                      enum:
                        - auto
                        - point
                      description: >-
                        How to locate the subject in the source video. `auto`
                        detects a person automatically. `point` uses your
                        `points` to mark the subject. Defaults to `auto`.
                      example: auto
                    points:
                      type: array
                      items:
                        type: object
                        properties:
                          position_x:
                            type: integer
                            minimum: 0
                            description: >-
                              Horizontal pixel coordinate in the source video
                              frame at `time_seconds`, measured from the left
                              edge.
                            example: 320
                          position_y:
                            type: integer
                            minimum: 0
                            description: >-
                              Vertical pixel coordinate in the source video
                              frame at `time_seconds`, measured from the top
                              edge.
                            example: 180
                          time_seconds:
                            type: number
                            minimum: 0
                            description: >-
                              Timestamp on the source video timeline in seconds.
                              Uses the same clock as `start_seconds` and
                              `end_seconds`.
                            format: float
                            example: 2.5
                        required:
                          - position_x
                          - position_y
                          - time_seconds
                      description: >-
                        On-frame markers for manual subject selection. Required
                        when `selection_mode` is `point`. Ignored when
                        `selection_mode` is `auto` or omitted.
                  description: >-
                    Optional style controls for replace vs animate mode and
                    subject selection.
              required:
                - end_seconds
                - assets
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: cuid-example
                    description: >-
                      Unique ID of the video. Use it with the [Get video Project
                      API](https://docs.magichour.ai/api-reference/video-projects/get-video-details)
                      to fetch status and downloads.
                  credits_charged:
                    type: integer
                    description: >-
                      The amount of credits deducted from your account to
                      generate the video. If the status is not 'complete', this
                      value is an estimate and may be adjusted upon completion
                      based on the actual FPS of the output video. 


                      If video generation fails, credits will be refunded, and
                      this field will be updated to include the refund.
                    example: 450
                required:
                  - id
                  - estimated_frame_cost
                  - credits_charged
                description: Success
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
                description: The request is invalid
                example:
                  message: Missing request body
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Unauthorized
                required:
                  - message
                description: The request is not properly authenticated
                example:
                  message: Unauthorized
        '402':
          description: Payment Required
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
                description: The request requires payment
                example:
                  message: Payment required
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    enum:
                      - Not Found
                required:
                  - message
                description: Requested resource is not found
                example:
                  message: Not Found
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Unable to create video
                required:
                  - message
                description: Unprocessable Entity
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Bearer authentication header of the form `Bearer <api_key>`, where
        `<api_key>` is your API key. To get your API key, go to [Developer
        Hub](https://magichour.ai/developer?tab=api-keys) and click "Create new
        API Key".

````