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

# Add a collection source

> Attaches a new source to a collection.



## OpenAPI

````yaml /openapi/source/external/collections/collections.json post /ai/collections/{uuid}/sources
openapi: 3.1.0
info:
  version: 1.0.0
  title: Telnyx API
  x-latency-category: interactive
  x-endpoint-cost: light
  description: >-
    Create and manage AI Collections — logical, searchable groupings of your
    Telnyx product data (voice, meeting bot, and message sources).


    A collection defines *what* data is searchable and *how* it is retrieved.
    You create a collection, attach one or more sources to it, tune its
    retrieval settings, and then run vector or hybrid search scoped to that
    collection. Every collection is automatically scoped to your organization —
    identity is derived from your Telnyx API key and cannot be overridden.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
    description: Telnyx API v2
security:
  - bearerAuth: []
tags:
  - name: AI Collections
    description: >-
      Create and manage logical collections of your Telnyx data, tune retrieval
      settings, manage sources, and run collection-scoped semantic search.
paths:
  /ai/collections/{uuid}/sources:
    post:
      tags:
        - AI Collections
      summary: Add a collection source
      description: Attaches a new source to a collection.
      operationId: AddCollectionSource
      parameters:
        - $ref: '#/components/parameters/Uuid'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SourceRequest'
      responses:
        '201':
          description: The created source.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SourceEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '422':
          description: >-
            Invalid source configuration -- `bucket` without a `bucket_id`
            (`invalid_source_configuration`) or an unknown `source_type`
            (`invalid_source_type`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              example:
                errors:
                  - code: invalid_source_configuration
                    title: Invalid source configuration
                    detail: >-
                      The bucket_id field is required when source_type is
                      bucket.
                    meta:
                      pointer: /bucket_id
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Telnyx from 'telnyx';


            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });


            const SourceEnvelope = await
            client.ai.collections.sources.create('uuid', {
              source_type: 'voice',
            });


            console.log(SourceEnvelope.data);
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            source_envelope = client.ai.collections.sources.create(
                uuid="uuid",
                source_type="voice",
            )
            print(source_envelope.data)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tsource, err := client.AI.Collections.Sources.New(\n\t\tcontext.TODO(),\n\t\t\"uuid\",\n\t\ttelnyx.AICollectionSourceNewParams{\n\t\t\tSourceType: \"source_type\",\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", source.Data)\n}\n"
        - lang: Java
          source: >-
            package com.telnyx.sdk.example;


            import com.telnyx.sdk.client.TelnyxClient;

            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            import
            com.telnyx.sdk.models.ai.collections.sources.SourceCreateParams;


            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    SourceCreateParams params = SourceCreateParams.builder()
                        .sourceType(SourceCreateParams.SourceType.VOICE)
                        .build();
                    var response = client.ai().collections().sources().create("uuid", params);
                }
            }
        - lang: Ruby
          source: >-
            require "telnyx"


            telnyx = Telnyx::Client.new(api_key: "My API Key")


            source_envelope = telnyx.ai.collections.sources.create("uuid",
            source_type: :voice)


            puts(source_envelope)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $source_envelope = $client->ai->collections->sources->create(
                'uuid',
                source_type: 'voice',
              );

              var_dump($source_envelope);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx ai:collections:sources create \
              --api-key 'My API Key' \
              --uuid 6a09ccbd-8f9b-4c3a-9b0e-2f1d3c4b5a6e \
              --source-type voice
components:
  parameters:
    Uuid:
      name: uuid
      in: path
      required: true
      description: The collection's unique identifier.
      schema:
        type: string
        format: uuid
        example: 6a09ccbd-8f9b-4c3a-9b0e-2f1d3c4b5a6e
  schemas:
    SourceRequest:
      type: object
      required:
        - source_type
      properties:
        source_type:
          $ref: '#/components/schemas/SourceType'
        bucket_id:
          type: string
          description: >-
            The Telnyx Storage bucket name. Required when `source_type` is
            `bucket`; ignored otherwise.
          example: policy-docs
      allOf:
        - if:
            properties:
              source_type:
                const: bucket
            required:
              - source_type
          then:
            properties:
              bucket_id:
                type: string
            required:
              - bucket_id
    SourceEnvelope:
      type: object
      description: Envelope containing a single collection source.
      properties:
        data:
          $ref: '#/components/schemas/Source'
    Errors:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/Error'
    SourceType:
      type: string
      description: >-
        The type of Telnyx data attached as a source. `bucket` requires an
        additional `bucket_id`. Only `voice` is searchable today; `meeting_bot`,
        `message`, and `bucket` attach but are not yet searchable (Coming soon).
      enum:
        - voice
        - meeting_bot
        - message
        - bucket
      example: voice
    Source:
      type: object
      properties:
        id:
          type: string
          example: source_8vkvtcksnawvbnxq48yv2l06wx
        record_type:
          type: string
          description: Identifies the record type. Always `ai_collection_source`.
          example: ai_collection_source
        collection_id:
          type: string
          format: uuid
          example: 6a09ccbd-8f9b-4c3a-9b0e-2f1d3c4b5a6e
        source_type:
          $ref: '#/components/schemas/SourceType'
        bucket_id:
          type: string
          description: The Telnyx Storage bucket name. Present only for `bucket` sources.
          example: policy-docs
        status:
          type: string
          example: ready
    Error:
      type: object
      properties:
        code:
          type: string
        title:
          type: string
        detail:
          type: string
        meta:
          type: object
          additionalProperties: true
          properties:
            pointer:
              type: string
              description: >-
                JSON Pointer to the request field that caused the error. Present
                on field-level validation and conflict errors.
              example: /slug
  responses:
    BadRequest:
      description: The request was malformed or failed validation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
          example:
            errors:
              - code: '10015'
                title: Bad Request
                detail: The request failed because it was not well-formed.
                meta:
                  url: https://developers.telnyx.com/docs/overview/errors/10015
    Unauthorized:
      description: Missing or invalid authentication.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
          example:
            errors:
              - code: '10009'
                title: Authentication failed
                detail: >-
                  The required authentication headers were either invalid or not
                  included in the request.
                meta:
                  url: https://developers.telnyx.com/docs/overview/errors/10009
    NotFound:
      description: The requested resource does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
          example:
            errors:
              - code: collection_not_found
                title: Collection not found
                detail: >-
                  No collection with uuid 'b3b1c8a2-9f4e-4d2a-9c1e-2f7a6d5b4c3a'
                  exists for this account.
    Conflict:
      description: >-
        The request conflicts with existing state (e.g. duplicate slug or
        duplicate source).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Errors'
          example:
            errors:
              - code: collection_slug_taken
                title: Collection slug already in use
                detail: >-
                  A collection with slug 'support-transcripts' already exists
                  for this account.
                meta:
                  pointer: /slug
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Telnyx API key. Collections and results are automatically scoped to the
        authenticated user's organization.

````