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

# Add sources to a knowledge base

> Attaches existing sources to a knowledge base by their IDs. The sources are queued for chunking and embedding into this knowledge base. Create the sources first with [Create sources](#tag/sources/post/knowledge-base/sources). Requires a token with write access.



## OpenAPI

````yaml /openapi-knowledge-base.json post /knowledge-base/datasets/{dataset_id}/sources
openapi: 3.0.3
info:
  title: AnyReach Knowledge Base API
  version: 1.0.0
  description: Manage knowledge bases, their sources, and run retrieval queries.
servers:
  - url: https://api.anyreach.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Knowledge bases
    description: >-
      A knowledge base (a `dataset` in the API) is a collection of embedded
      content an agent can retrieve from.
  - name: Knowledge base sources
    description: Attach and detach sources to a knowledge base.
  - name: Sources
    description: >-
      A source is a file or URL whose content is ingested, chunked, and
      embedded.
paths:
  /knowledge-base/datasets/{dataset_id}/sources:
    post:
      tags:
        - Knowledge base sources
      summary: Add sources to a knowledge base
      description: >-
        Attaches existing sources to a knowledge base by their IDs. The sources
        are queued for chunking and embedding into this knowledge base. Create
        the sources first with [Create
        sources](#tag/sources/post/knowledge-base/sources). Requires a token
        with write access.
      operationId: addKnowledgeBaseSources
      parameters:
        - name: dataset_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: The knowledge base ID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddSourcesRequest'
            example:
              source_ids:
                - 3f8a...
                - 9c2b...
      responses:
        '200':
          description: Sources attached and queued.
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  schemas:
    AddSourcesRequest:
      type: object
      required:
        - source_ids
      properties:
        source_ids:
          type: array
          items:
            type: string
            format: uuid
          description: IDs of existing sources to attach.
    Error:
      type: object
      properties:
        detail:
          type: string
          example: Dataset not found
  responses:
    Forbidden:
      description: The token's role doesn't grant access to this action.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The resource does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Personal access token. See Authentication.

````