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

# Upload a file source

> Upload a document to the agent's knowledge base. Send the request as
`multipart/form-data`.

The request returns as soon as the upload is accepted, before the file
is searchable. Poll `GET .../sources/{sourceId}` to track processing;
the status is `failed` if the file cannot be processed.

This request is not idempotent: sending it twice creates two sources.
If you receive a 504, list the agent's sources to check whether the
upload went through before retrying.



## OpenAPI

````yaml POST /v1/agents/{agentId}/knowledge-base/sources/files
openapi: 3.1.0
info:
  title: PolyAI Agents API
  version: 1.0.11
  description: Manage PolyAI agents, telephony, deployments, and real-time configs.
servers:
  - url: https://api.us.poly.ai
    description: US region
  - url: https://api.eu.poly.ai
    description: EU region
  - url: https://api.uk.poly.ai
    description: UK region
  - url: https://api.studio.poly.ai
    description: Studio region
security:
  - polyApiKey: []
paths:
  /v1/agents/{agentId}/knowledge-base/sources/files:
    parameters:
      - name: agentId
        in: path
        required: true
        schema:
          type: string
    post:
      tags:
        - Source Hub
      summary: Upload a file source
      description: |-
        Upload a document to the agent's knowledge base. Send the request as
        `multipart/form-data`.

        The request returns as soon as the upload is accepted, before the file
        is searchable. Poll `GET .../sources/{sourceId}` to track processing;
        the status is `failed` if the file cannot be processed.

        This request is not idempotent: sending it twice creates two sources.
        If you receive a 504, list the agent's sources to check whether the
        upload went through before retrying.
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CreateFileSourceBody'
      responses:
        '201':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateFileSourceResponse'
        '400':
          description: Validation error
        '401':
          description: Unauthorized – missing or invalid API key
        '403':
          description: Forbidden – insufficient permissions
components:
  schemas:
    CreateFileSourceBody:
      description: >-
        A file to add to the agent's knowledge base, sent as
        multipart/form-data.
      type: object
      properties:
        targetEnvSandbox:
          description: Whether the source is used in sandbox
          type:
            - boolean
            - 'null'
        targetEnvPrerelease:
          description: Whether the source is used in pre-release
          type:
            - boolean
            - 'null'
        targetEnvLive:
          description: Whether the source is used in live
          type:
            - boolean
            - 'null'
        variantIds:
          description: >-
            Variants the source applies to. An empty list or null applies it to
            all variants
          type:
            - array
            - 'null'
          items:
            type: string
        file:
          description: >-
            The document to upload, up to 64 MiB. Supported formats: PDF, Word,
            Excel, PowerPoint, OpenDocument text (ODT), RTF, EPUB, HTML, XML,
            JSON, Markdown, CSV, plain text, and email (EML, MSG)
          type: string
          format: binary
        name:
          description: Display name of the source. Defaults to the file name
          minLength: 1
          type:
            - string
            - 'null'
      required:
        - file
    CreateFileSourceResponse:
      description: The created file source. The file is stored and queued for processing.
      type: object
      properties:
        source:
          description: The saved source
          allOf:
            - $ref: '#/components/schemas/SourceSettingsResponse'
      required:
        - source
    SourceSettingsResponse:
      description: |-
        A knowledge base source as saved, without its document count or sync
        state. Sources are shared across all branches of the agent.
      type: object
      properties:
        targetEnvSandbox:
          description: Whether the source is used in sandbox
          type:
            - boolean
            - 'null'
        targetEnvPrerelease:
          description: Whether the source is used in pre-release
          type:
            - boolean
            - 'null'
        targetEnvLive:
          description: Whether the source is used in live
          type:
            - boolean
            - 'null'
        variantIds:
          description: >-
            Variants the source applies to. An empty list or null applies it to
            all variants
          type:
            - array
            - 'null'
          items:
            type: string
        id:
          description: Unique source identifier
          type: string
        accountId:
          description: Account this source belongs to
          type: string
        projectId:
          description: Agent (project) this source belongs to
          type:
            - string
            - 'null'
        name:
          description: Display name of the source
          type: string
        createdAt:
          description: When the source was created
          type: string
        updatedAt:
          description: When the source was last updated
          type:
            - string
            - 'null'
        createdBy:
          description: Email of the user who created the source
          type: string
        updatedBy:
          description: Email of the user who last updated the source
          type:
            - string
            - 'null'
        sourceType:
          description: Source type (file, website)
          type: string
        sourceUrl:
          description: URL a website source is crawled from
          type:
            - string
            - 'null'
        syncInterval:
          description: Seconds between scheduled syncs; null when not scheduled
          type:
            - integer
            - 'null'
        webScrapeConfig:
          description: How a website source is crawled
          anyOf:
            - $ref: '#/components/schemas/WebScrapeConfigResponse'
            - type: 'null'
      required:
        - id
        - accountId
        - name
        - createdAt
        - createdBy
        - sourceType
    WebScrapeConfigResponse:
      description: >-
        Crawl settings for a website source. Unset settings use the crawler
        defaults.
      type: object
      properties:
        pageLimit:
          description: Maximum number of pages the crawl visits
          type:
            - integer
            - 'null'
  securitySchemes:
    polyApiKey:
      type: apiKey
      in: header
      name: X-API-KEY

````