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

# Add Knowledge Base Item Chunk

> Adds one chunk you wrote. It is not searchable until you index the item (`POST /v1/voice-agents/knowledge-base/{id}/index`). An item can have at most 5,000 chunks.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/voice-agents/knowledge-base/{id}/chunks
openapi: 3.0.1
info:
  title: Hamsa API
  description: >-
    The Hamsa API: voice agents and their calls, phone numbers, batch calls and
    knowledge bases; speech to text, text to speech, voices and AI content.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tryhamsa.com
security: []
paths:
  /v1/voice-agents/knowledge-base/{id}/chunks:
    post:
      summary: Add a chunk to a knowledge base item
      description: >-
        Adds one chunk you wrote. It is not searchable until you index the item
        (`POST /v1/voice-agents/knowledge-base/{id}/index`). An item can have at
        most 5,000 chunks.
      parameters:
        - in: path
          name: id
          required: true
          description: ID of the knowledge base item.
          schema:
            type: string
            format: uuid
            example: d949f13f-40d2-4e48-ac86-b66633070603
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - text
              properties:
                text:
                  type: string
                  minLength: 1
                  maxLength: 6000
                  description: >-
                    Chunk text, at most 6,000 characters. Empty or blank text is
                    refused (`ChunkTextCannotBeEmpty`).
                  example: Refunds are issued within 5 business days.
                afterChunkId:
                  type: string
                  format: uuid
                  nullable: true
                  description: >-
                    Put the new chunk after this chunk. `null`: at the top.
                    Omitted: at the end.
                  example: 0f1a5c0e-2d9b-4f8a-9d3e-6b2c1a7e8f90
            examples:
              after:
                summary: After a chunk
                value:
                  text: Refunds are issued within 5 business days.
                  afterChunkId: 0f1a5c0e-2d9b-4f8a-9d3e-6b2c1a7e8f90
              top:
                summary: At the top
                value:
                  text: This document covers our refund policy.
                  afterChunkId: null
              end:
                summary: At the end
                value:
                  text: Contact support@example.com for help with refunds.
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Chunks saved successfully!
                  messageKey:
                    type: string
                    example: ChunksSavedSuccessfully
                  data:
                    $ref: '#/components/schemas/KnowledgeBaseChunk'
        '400':
          description: >-
            Invalid body, or the item already has 5,000 chunks
            (`ChunksMaxPerItemExceeded`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: 'Unauthorized: missing or invalid API key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: >-
            Your API key or role does not have the `knowledge_base:update`
            permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '404':
          description: >-
            Knowledge base item not found, or `afterChunkId` is not one of its
            chunks (`KnowledgeBaseItemChunkNotFound`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '422':
          description: >-
            The item is still processing (`KnowledgeBaseItemIsProcessing`): wait
            for it to finish before changing its chunks.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '500':
          description: Server Side Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    KnowledgeBaseChunk:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Chunk ID.
          example: 0f1a5c0e-2d9b-4f8a-9d3e-6b2c1a7e8f90
        knowledgeBaseItemId:
          type: string
          format: uuid
          description: The knowledge base item the chunk belongs to.
          example: d949f13f-40d2-4e48-ac86-b66633070603
        position:
          type: integer
          description: Order of the chunk in the item, starting at 1.
          example: 3
        text:
          type: string
          description: Chunk text (at most 6,000 characters).
          example: Enterprise plans include a dedicated support line, available 24/7.
        charCount:
          type: integer
          description: Number of characters in `text`.
          example: 66
        wordCount:
          type: integer
          description: Number of words in `text`.
          example: 10
        origin:
          type: string
          enum:
            - AUTO
            - USER
          description: '`AUTO`: made by the chunker. `USER`: added by you.'
          example: AUTO
        flagged:
          type: boolean
          description: >-
            `true` when the chunker flagged the chunk for review (see
            `metadata.flags`). Editing the text clears it.
          example: false
        metadata:
          $ref: '#/components/schemas/KnowledgeBaseChunkMetadata'
        isIndexed:
          type: boolean
          description: >-
            `true` when the indexed copy matches the current text. `false` for
            new or edited chunks until you index the item.
          example: true
        indexedAt:
          type: string
          format: date-time
          nullable: true
          description: When the chunk was last indexed. `null` if never.
          example: '2026-10-08T10:05:50.000Z'
        createdAt:
          type: string
          format: date-time
          example: '2026-10-08T10:05:50.000Z'
        updatedAt:
          type: string
          format: date-time
          example: '2026-10-08T10:05:50.000Z'
    ErrorSchema:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Service error code: the HTTP status with a service prefix (for
            example `8404`). Missing when the service has no code for that
            status.
          example: 8404
        message:
          type: string
          description: >-
            What went wrong. Some services (calls and recordings) put the error
            key here, for example `CallNotFoundOrUnavailable`, and send no
            `messageKey`.
          example: Policy not found!
        messageKey:
          type: string
          description: >-
            Stable key for the error, safe to match on in code. Not returned by
            every service.
          example: PolicyNotFound
        params:
          type: object
          additionalProperties: true
          description: >-
            Details for some errors (for example `reason`). Not returned by
            every service.
          example:
            reason: NO_DRAFT
    KnowledgeBaseChunkMetadata:
      type: object
      nullable: true
      description: Details from the chunker. `null` for chunks you added yourself.
      properties:
        headerPath:
          type: string
          description: The headings the chunk sits under, outermost first.
          example: Pricing > Enterprise
        page:
          type: integer
          description: Page number (files with pages).
          example: 4
        kind:
          type: string
          enum:
            - prose
            - list
            - code
            - table
            - qa
          description: What the chunk contains.
          example: prose
        tokenCount:
          type: integer
          description: Size of the chunk text in tokens.
          example: 212
        qualityScore:
          type: number
          description: Chunker quality score, 0 to 1.
          example: 0.71
        strategy:
          type: string
          enum:
            - SEMANTIC
            - BY_PARAGRAPH
            - QA_PAIRS
            - BY_PAGE
            - FIXED
            - LLM_GUIDED
          description: >-
            The chunking method actually used (it can differ from the one you
            asked for after a fallback).
          example: SEMANTIC
        context:
          type: string
          description: The sentence added in front of the chunk when `addContext` is on.
          example: >-
            This section lists the support options included in the Enterprise
            plan.
        title:
          type: string
          description: Chunk title chosen by the AI model (`LLM_GUIDED` only).
          example: Enterprise support
        flags:
          type: array
          items:
            type: string
            enum:
              - low_quality
              - too_short
              - oversized
          description: Why the chunk is flagged for review.
          example:
            - too_short
        overlapApplied:
          type: boolean
          example: true
          description: >-
            Only when `overlapTokens` is above 0: whether the start of this
            chunk repeats the end of the chunk before it.
        overlapTokenCount:
          type: integer
          example: 38
          description: 'Only when `overlapApplied` is `true`: how many tokens were repeated.'
        overlapSkipReason:
          type: string
          enum:
            - first_chunk
            - table
            - qa_pair
            - after_table
            - after_qa_pair
            - qa_pairs_strategy
            - last_word_over_overlap
          example: first_chunk
          description: >-
            Only when `overlapApplied` is `false`: why. `first_chunk`: the first
            chunk of the item; `table`: the chunk is a table; `qa_pair`: the
            chunk is a question and its answer; `after_table`: the chunk before
            it is a table; `after_qa_pair`: the chunk before it is a question
            and its answer; `qa_pairs_strategy`: the item uses `QA_PAIRS`;
            `last_word_over_overlap`: the last word of the chunk before it is
            longer than `overlapTokens`.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Pass the API key in the Authorization header, You need to put Token
        keyword before the API key. e.g. 'Authorization: Token <api-key>'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.