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

# Creates a Document or Text Source

> Creates a Document or Text Source that can be added to Knowledge Bases as a Knowledge Base Source or used as context for an Explanation. Upload a file that can be used across various endpoints. Individual document files can be up to 100 MB, text Sources can be up to 1000000 characters long, and the size of all Sources uploaded by one `Organization` can be up to 100 GB Document `Sources` are submitted as multipart/form-data and Text `Sources` as application/json.



## OpenAPI

````yaml /api-reference/openapi.yaml post /sources
openapi: 3.0.3
info:
  title: Totoy API
  description: >-
    Explain documents in simple, plain or detailed language and create Knowledge
    Bases from your documents in 19 languages.
  termsOfService: https://www.totoy.ai
  contact:
    name: Totoy Support
    email: support@totoy.ai
  license:
    name: MIT
    url: https://raw.githubusercontent.com/totoy-ai/totoy-openapi/main/LICENSE
  version: 1.1.5
servers:
  - url: https://api.totoy.ai/v1
security:
  - ApiKeyAuth: []
tags:
  - name: Explanation
    description: >-
      Given a document in any language, an output language and one of three
      language levels, the assistant will return an `Explanation` for this
      document.
  - name: Knowledge Bases
    description: >-
      Create `Knowledge Bases` from document or text `Sources` and chat with an
      assistant about them in 19 languages.
  - name: Sources
    description: >-
      `Sources` are used to upload documents (.pdf, .jpg or .png) or plain texts
      that can be used with features like `Explanation` or `Knowledge Bases.`
  - name: Projects
    description: '`Projects` are used to group `Knowledge Bases` and `Explanations`.'
  - name: Organization
    description: Get information about your `Organization`.
paths:
  /sources:
    post:
      tags:
        - Sources
      summary: Creates a Document or Text Source
      description: >-
        Creates a Document or Text Source that can be added to Knowledge Bases
        as a Knowledge Base Source or used as context for an Explanation. Upload
        a file that can be used across various endpoints. Individual document
        files can be up to 100 MB, text Sources can be up to 1000000 characters
        long, and the size of all Sources uploaded by one `Organization` can be
        up to 100 GB Document `Sources` are submitted as multipart/form-data and
        Text `Sources` as application/json.
      operationId: createSource
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CreateDocumentSourceRequest'
            examples:
              create-document-source-request-example:
                $ref: '#/components/examples/create-document-source-request-example'
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTextSourceRequest'
            examples:
              create-text-source-request-example:
                $ref: '#/components/examples/create-text-source-request-example'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Source'
              examples:
                document-source-example-1:
                  $ref: '#/components/examples/document-source-example-1'
                text-source-example-1:
                  $ref: '#/components/examples/text-source-example-1'
        4XX:
          $ref: '#/components/responses/general4XXResponse'
        5XX:
          $ref: '#/components/responses/general5XXResponse'
components:
  schemas:
    CreateDocumentSourceRequest:
      title: CreateDocumentSourceRequest
      type: object
      additionalProperties: false
      properties:
        document_file:
          description: >-
            A document file (not file name) to be uploaded to `Sources`.
            Supported file types are .pdf, .jpg, and .png.
          type: string
          format: binary
          maxLength: 100000000
          example: <binary_file>
        title:
          description: Title of the document.
          type: string
          maxLength: 512
          example: Totoy Company Overview
        backlink:
          description: >-
            A url to the document source that can be used by clients to link
            back to the original document.
          type: string
          example: https://www.totoy.ai/totoy-company-overview.pdf
          maxLength: 512
        valid_from:
          description: >-
            From what time the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_from` is set, the `Source` is valid from
            the time it is added to `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2024-01-01T00:00:00Z'
        valid_until:
          description: >-
            Until when the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_until` is set, the `Source` is valid
            until it is removed from `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        project_id:
          description: >-
            The unique identifier of the project this `Source` should be
            assigned to. `Sources` can only be used by resources with the same
            `project_id`. If no `project_id` is set, the `Source` will be
            assigned to the default project.
          maxLength: 28
          pattern: ^pj_[a-zA-Z0-9]{25}$
          type: string
          nullable: true
          example: pj_avX7imfLaPcQnv5ckvGlOEBA9
        custom_metadata:
          $ref: '#/components/schemas/CustomMetadata'
      required:
        - document_file
    CreateTextSourceRequest:
      title: CreateTextSourceRequest
      type: object
      additionalProperties: false
      properties:
        text_content:
          description: Plain-text string to be uploaded to `Sources`.
          type: string
          maxLength: 1000000
          example: Totoy GmbH was founded on November 8, 2023.
        title:
          description: Title of the text `Source`.
          type: string
          maxLength: 512
          nullable: true
          example: Foundation Date
        backlink:
          description: >-
            A url to the text `Source` that can be used by clients to link back
            to the original text.
          type: string
          maxLength: 512
          example: https://www.totoy.ai/general-info
        valid_from:
          description: >-
            From what time the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_from` is set, the `Source` is valid from
            the time it is added to `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2024-01-01T00:00:00Z'
        valid_until:
          description: >-
            Until when the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_until` is set, the `Source` is valid
            until it is removed from `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        project_id:
          description: >-
            The unique identifier of the project this `Source` should be
            assigned to. `Sources` can only be used by resources with the same
            `project_id`. If no `project_id` is set, the `Source` will be
            assigned to the default project.
          maxLength: 28
          pattern: ^pj_[a-zA-Z0-9]{25}$
          type: string
          nullable: true
          example: pj_avX7imfLaPcQnv5ckvGlOEBA9
        custom_metadata:
          $ref: '#/components/schemas/CustomMetadata'
      required:
        - text_content
    Source:
      title: Source
      type: object
      description: >-
        The `Source` object represents a document source (.pdf, .jpg, .png) or
        text source (plain-text) that has been uploaded to Totoy.
      properties:
        source_id:
          description: Unique identifier for the `Source`.
          maxLength: 29
          pattern: ^src_[a-zA-Z0-9]{25}$
          type: string
          example: src_oXiYDg8QOc9JsOk86idRXiywD
        source_type:
          description: Type for this source (document or text).
          type: string
          enum:
            - document
            - text
          example: document
        bytes:
          description: Size of the document file or text, in bytes.
          type: integer
          format: int32
          example: 1234567
        created_at:
          description: Date-time for when the `Source` was created, in ISO 8601 format.
          type: string
          format: date-time
          example: '2024-03-01T00:00:00Z'
        updated_at:
          description: >-
            Date-time for when the `Source` was last modified, in ISO 8601
            format.
          type: string
          format: date-time
          example: '2024-03-01T00:00:00Z'
        title:
          description: Title of the document or text.
          type: string
          maxLength: 512
          example: Totoy Company Overview
        document_file_name:
          description: The file name of a `Source` document.
          type: string
          maxLength: 255
          nullable: true
          example: totoy-company-overview.pdf
        backlink:
          description: >-
            An external url to the `Source` that can be used by clients to link
            back to the original document or text (i.e. a web page containing
            that text).
          type: string
          maxLength: 512
          example: https://www.totoy.ai/totoy-company-overview.pdf
        valid_from:
          description: >-
            From what time the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_from` is set, the `Source` is valid from
            the time it is added to `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2024-01-01T00:00:00Z'
        valid_until:
          description: >-
            Until when the `Source` can be used by a `Knowledge Base` or an
            `Explanation`. If no `valid_until` is set, the `Source` is valid
            until it is removed from `Sources`.
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        project_id:
          description: >-
            The unique identifier of the project this `Source` is assigned to.
            `Sources` can only be used by resources with the same `project_id`.
          maxLength: 28
          pattern: ^pj_[a-zA-Z0-9]{25}$
          type: string
          example: pj_avX7imfLaPcQnv5ckvGlOEBA9
        custom_metadata:
          $ref: '#/components/schemas/CustomMetadata'
        knowledge_base_ids:
          description: List of `Knowledge Base` identifiers where this `Source` is used.
          type: array
          items:
            type: string
            maxLength: 29
            pattern: ^kb_[a-zA-Z0-9]{25}$
            example: kb_feMfJbeqbAEj4u8K5HqmKpUbY
          nullable: true
          example:
            - kb_feMfJbeqbAEj4u8K5HqmKpUbY
            - kb_7eMfJbeqbAEj4u8K5HqmKpUbY
          maxItems: 1500
        status:
          description: >-
            The parsing status of the Document Source. The status `completed`
            indicates that the source is ready for use. The status parameter is
            only available for Document Sources.
          type: string
          enum:
            - in_progress
            - completed
            - failed
          example: in_progress
        pages:
          description: >-
            The number of pages of the Document Source. The pages parameter is
            only available for Document Sources.
          type: integer
          example: 27
      required:
        - source_id
        - source_type
        - bytes
        - created_at
        - updated_at
        - project_id
    CustomMetadata:
      title: CustomMetadata
      description: >-
        Custom optional metadata for a `Source` provided by a client. Up to 10
        key-value pairs.
      type: object
      additionalProperties: true
      maxProperties: 10
      example:
        internal_tag: general_documents
    Problem:
      title: Problem
      description: A Response Body for HTTP Problem Details in RFC 9457 format.
      type: object
      additionalProperties: false
      properties:
        type:
          description: A URI reference that identifies the problem type.
          type: string
          maxLength: 512
          example: https://docs.totoy.ai/probs/out-of-credit
        title:
          description: A short, human-readable summary of the problem type.
          type: string
          maxLength: 512
          example: You do not have enough credit.
        status:
          description: >-
            The HTTP status code generated by the origin server for this
            occurrence of the problem.
          type: integer
          format: int32
          example: 403
        detail:
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
          type: string
          maxLength: 4096
          example: You do not have enough credit to perform this operation.
        instance:
          description: >-
            A URI reference that identifies the specific occurrence of the
            problem.
          type: string
          maxLength: 512
          example: /projects/pj_avX7imfLaPcQnv5ckvGlOEBA9
  examples:
    create-document-source-request-example:
      summary: Create Document Source Request Example
      description: An example for creating a document source.
      value:
        document_file: <binary_string>
        title: Totoy Company Overview
        backlink: https://www.totoy.ai/totoy-company-overview.pdf
        valid_from: '2024-01-01T00:00:00Z'
        valid_until: '2026-12-31T23:59:59Z'
        custom_metadata:
          internal_tag: general_documents
    create-text-source-request-example:
      summary: Create Text Source Request Example
      description: An example for creating a text source.
      value:
        text_content: Totoy GmbH was founded on November 8, 2023.
        title: Foundation Date
        backlink: https://www.totoy.ai/general-info
        valid_from: '2024-01-01T00:00:00Z'
        valid_until: '2026-12-31T23:59:59Z'
        custom_metadata:
          internal_tag: text_snippets
    document-source-example-1:
      summary: Document Source Example 1
      description: An example for a document `Source`.
      value:
        source_id: src_oXiYDg8QOc9JsOk86idRXiywD
        source_type: document
        bytes: 1234567
        created_at: '2024-03-01T00:00:00Z'
        updated_at: '2024-03-01T00:00:00Z'
        title: Totoy Company Overview
        document_file_name: totoy-company-overview.pdf
        backlink: https://www.totoy.ai/totoy-company-overview.pdf
        valid_from: '2024-01-01T00:00:00Z'
        valid_until: '2026-12-31T23:59:59Z'
        project_id: pj_avX7imfLaPcQnv5ckvGlOEBA9
        custom_metadata:
          internal_tag: general_documents
        knowledge_base_ids:
          - kb_feMfJbeqbAEj4u8K5HqmKpUbY
          - kb_2eMfJbeqbAEj4u8K5HqmKpUbY
        status: completed
        pages: 27
    text-source-example-1:
      summary: Text Source Example 1
      description: An example for a text `Source`.
      value:
        source_id: src_qoY7rSGkiWtn4NP8kPXc7xzrq
        source_type: text
        bytes: 44
        created_at: '2024-04-01T00:00:00Z'
        updated_at: '2024-04-01T00:00:00Z'
        title: Foundation Date
        backlink: https://www.totoy.ai/general-info
        valid_from: '2024-01-01T00:00:00Z'
        valid_until: '2026-12-31T23:59:59Z'
        project_id: pj_avX7imfLaPcQnv5ckvGlOEBA9
        custom_metadata:
          internal_tag: text_snippets
        knowledge_base_ids:
          - kb_feMfJbeqbAEj4u8K5HqmKpUbY
          - kb_2eMfJbeqbAEj4u8K5HqmKpUbY
  responses:
    general4XXResponse:
      description: Client Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
    general5XXResponse:
      description: Server Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer

````