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

# Attach function

> Attaches a function to a collection.



## OpenAPI

````yaml https://api.trychroma.com/openapi.json post /api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/functions/attach
openapi: 3.1.0
info:
  title: chroma-frontend
  description: ''
  license:
    name: ''
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/tenants/{tenant}/databases/{database}/collections/{collection_id}/functions/attach:
    post:
      tags:
        - Function
      summary: Attach function
      description: Attaches a function to a collection.
      operationId: attach_function
      parameters:
        - name: tenant
          in: path
          description: Tenant UUID
          required: true
          schema:
            type: string
          example: 1e30d217-3d78-4f8c-b244-79381dc6a254
        - name: database
          in: path
          description: Database name
          required: true
          schema:
            type: string
        - name: collection_id
          in: path
          description: Collection UUID
          required: true
          schema:
            type: string
          example: 1e30d217-3d78-4f8c-b244-79381dc6a254
      requestBody:
        description: Function attachment request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AttachFunctionRequest'
            example:
              function_id: 1e30d217-3d78-4f8c-b244-79381dc6a254
              name: my_function
              output_collection: output_collection_name
              params: {}
        required: true
      responses:
        '200':
          description: ' Function attached successfully'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AttachFunctionResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    AttachFunctionRequest:
      type: object
      required:
        - name
        - function_id
        - output_collection
      properties:
        function_id:
          type: string
        name:
          type: string
        output_collection:
          type: string
        params: {}
    AttachFunctionResponse:
      type: object
      required:
        - attached_function
        - created
      properties:
        attached_function:
          $ref: '#/components/schemas/AttachedFunctionInfo'
        created:
          type: boolean
          description: >-
            True if newly created, false if already existed (idempotent
            request).
    ErrorResponse:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: string
        message:
          type: string
    AttachedFunctionInfo:
      type: object
      required:
        - id
        - name
        - function_name
      properties:
        function_name:
          type: string
          description: Name of the function (e.g., "record_counter", "statistics").
        id:
          type: string
          description: Unique identifier for the attached function.
        name:
          type: string
          description: Human-readable name for the attached function instance.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-chroma-token

````