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

# Upsert Chapter

> Create or update a chapter within a video.
If the chapter exists, it will be updated; otherwise, a new one will be created.



## OpenAPI

````yaml https://raw.githubusercontent.com/vidinfra/open-api-docs/refs/heads/main/openapi.json put /libraries/{libraryId}/videos/{videoId}/chapters
openapi: 3.0.1
info:
  title: Default module
  description: ''
  version: 1.0.0
servers:
  - url: https://api.tenbyte.io/v1/vidinfra
    description: Production server
security:
  - bearer: []
tags:
  - name: Library
  - name: Folder
  - name: Video
  - name: Subtitle
  - name: Video Thumbnails
  - name: Transcoding Profiles
  - name: Player Themes
  - name: Video Chapter
  - name: Webhook Endpoints
  - name: Webhook Deliveries
  - name: Security
  - name: Video Multipart Upload
  - name: Webhook
  - name: Migration Jobs
paths:
  /libraries/{libraryId}/videos/{videoId}/chapters:
    put:
      tags:
        - Video Chapter
      summary: Upsert Chapter
      description: >-
        Create or update a chapter within a video.

        If the chapter exists, it will be updated; otherwise, a new one will be
        created.
      parameters:
        - name: libraryId
          in: path
          description: Unique identifier of the library.
          required: true
          example: 314221a1-3cbf-4d3c-846e-f6c22bc43064
          schema:
            type: string
        - name: videoId
          in: path
          description: Unique identifier of the targeted video resource.
          required: true
          example: a7f590b4-3fd7-42a4-82bb-a7cfa6aa9d04
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                chapters:
                  type: array
                  description: >-
                    List of chapters to create or update within the video. Each
                    chapter defines a time range and title.
                  items:
                    type: object
                    properties:
                      title:
                        type: string
                        description: >-
                          The title or label of the chapter, displayed in the
                          video player timeline.
                      start_time:
                        type: integer
                        description: The starting time of the chapter in seconds.
                      end_time:
                        type: integer
                        description: The ending time of the chapter in seconds.
                      order_index:
                        type: integer
                        description: Optional ordering position of the chapter in the list.
                    required:
                      - title
                      - start_time
                      - end_time
                    description: >-
                      Defines a single video chapter, including title, duration
                      range, and display order.
              required:
                - chapters
            example:
              chapters:
                - title: Introduction
                  start_time: 1
                  end_time: 30
                  order_index: 0
                - title: What is CDN?
                  start_time: 30
                  end_time: 60
                  order_index: 1
                - title: Next Steps
                  start_time: 60
                  end_time: 70
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        video_id:
                          type: string
                        title:
                          type: string
                        start_time:
                          type: integer
                        end_time:
                          type: integer
                        order_index:
                          type: integer
                      required:
                        - id
                        - video_id
                        - title
                        - start_time
                        - end_time
                        - order_index
                  message:
                    type: string
                  success:
                    type: boolean
                required:
                  - data
                  - message
                  - success
              example:
                data:
                  - id: 03061150-2c72-40e4-9ac5-e5cd16083292
                    video_id: 7f7a8d67-d552-4436-bc0e-1fdc62b9210a
                    title: Introduction
                    start_time: 1
                    end_time: 30
                    order_index: 0
                  - id: 3fc10b86-56c6-414c-ae5e-2ae40ecb15da
                    video_id: 7f7a8d67-d552-4436-bc0e-1fdc62b9210a
                    title: What is Vidinfra CDN?
                    start_time: 30
                    end_time: 60
                    order_index: 1
                  - id: e8835784-3410-435b-b075-c8834112c6dd
                    video_id: 7f7a8d67-d552-4436-bc0e-1fdc62b9210a
                    title: Next Steps
                    start_time: 60
                    end_time: 70
                    order_index: 2
                message: Video Chapters Updated Successfully
                success: true
          headers: {}
        '400':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  success:
                    type: boolean
                required:
                  - message
                  - success
              example:
                message: Invalid Request
                success: false
          headers: {}
        '401':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  success:
                    type: boolean
                required:
                  - code
                  - message
                  - success
              example:
                code: auth_type_not_found
                message: >-
                  Could not determine authentication type from request. Please
                  provide a valid Authorization header or X-API-Key header.
                success: false
          headers: {}
        '404':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  success:
                    type: boolean
                required:
                  - message
                  - success
              example:
                message: Resource not found
                success: false
          headers: {}
        '422':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  errors:
                    type: array
                    items:
                      type: object
                      properties:
                        field:
                          type: string
                        code:
                          type: string
                        message:
                          type: string
                  success:
                    type: boolean
                required:
                  - message
                  - errors
                  - success
              example:
                message: Invalid Request
                errors:
                  - field: field_name
                    code: validation_required
                    message: This field is required
                success: false
          headers: {}
        '500':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  success:
                    type: boolean
                required:
                  - message
                  - success
              example:
                message: Internal server error
                success: false
          headers: {}
      deprecated: false
      security:
        - bearer: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer

````