> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Attach UDF to service

> **Disclaimer:** This beta endpoint is evolving; the API contract may change. <br /><br /> Attaches one UDF version to a service, replacing the current version when necessary. When version is omitted, the latest ready version is attached.

<span data-endpoint-badge="Beta"><Badge color="blue">Beta</Badge></span>

**Disclaimer:** This beta endpoint is evolving; the API contract may change. <br /><br /> Attaches one UDF version to a service, replacing the current version when necessary. When version is omitted, the latest ready version is attached.


## OpenAPI

````yaml _specs/cloud-openapi.json PUT /v1/organizations/{organizationId}/udfs/{functionName}/attachments/{serviceId}
openapi: 3.1.2
info:
  title: OpenAPI spec for ClickHouse Cloud
  version: '1.0'
  contact:
    name: ClickHouse Support
    url: >-
      https://clickhouse.com/docs/en/cloud/manage/openapi?referrer=openapi-1037333
    email: support@clickhouse.com
servers:
  - url: https://api.clickhouse.cloud
security:
  - basicAuth: []
tags:
  - name: Organization
  - name: User management
  - name: Billing
  - name: Role Management
  - name: Service
  - name: Backup
  - name: OpenAPI
  - name: Prometheus
  - name: ClickPipes
  - name: ClickStack
  - name: Postgres
  - name: UDF
paths:
  /v1/organizations/{organizationId}/udfs/{functionName}/attachments/{serviceId}:
    put:
      tags:
        - UDF
      summary: Attach UDF to service
      description: >-
        **Disclaimer:** This beta endpoint is evolving; the API contract may
        change. <br /><br /> Attaches one UDF version to a service, replacing
        the current version when necessary. When version is omitted, the latest
        ready version is attached.
      operationId: udfAttach
      parameters:
        - in: path
          name: organizationId
          schema:
            description: ID of the requested organization.
            type: string
            format: uuid
            pattern: >-
              ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
          required: true
          description: ID of the requested organization.
        - in: path
          name: functionName
          schema:
            description: Name of the UDF.
            type: string
            pattern: ^[A-Za-z][A-Za-z0-9_]*$
          required: true
          description: Name of the UDF.
        - in: path
          name: serviceId
          schema:
            description: ID of the requested service.
            type: string
            format: uuid
            pattern: >-
              ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
          required: true
          description: ID of the requested service.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                version:
                  description: >-
                    Version to attach. When omitted, the latest ready version is
                    attached.
                  example: 1
                  type: integer
                  exclusiveMinimum: 0
      responses:
        '200':
          description: Current attachment state.
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    description: HTTP status code.
                    example: 200
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                  result:
                    $ref: '#/components/schemas/UdfAttachment'
                required:
                  - status
                  - requestId
                  - result
                additionalProperties: false
        '400':
          description: The service does not support UDFs.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Human-readable error message.
                    type: string
                  status:
                    description: HTTP status code.
                    example: 400
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - status
                  - requestId
                additionalProperties: false
        '404':
          description: UDF, version, or service not found.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Human-readable error message.
                    type: string
                  status:
                    description: HTTP status code.
                    example: 404
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - status
                  - requestId
                additionalProperties: false
        '409':
          description: >-
            The requested version is not ready or another attachment transition
            is in progress.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Human-readable error message.
                    type: string
                  status:
                    description: HTTP status code.
                    example: 409
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - status
                  - requestId
                additionalProperties: false
        '422':
          description: Service UDF attachment limit exceeded.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Human-readable error message.
                    type: string
                  status:
                    description: HTTP status code.
                    example: 422
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - status
                  - requestId
                additionalProperties: false
        '424':
          description: The service must be running before the UDF can be attached.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Human-readable error message.
                    type: string
                  code:
                    description: Reason the attachment could not be started.
                    type: string
                    enum:
                      - SERVICE_IDLE
                      - SERVICE_NOT_RUNNING
                      - SERVICE_STOPPED
                  serviceState:
                    description: Current state of the service.
                    type: string
                    enum:
                      - starting
                      - stopping
                      - terminating
                      - softdeleting
                      - awaking
                      - partially_running
                      - provisioning
                      - running
                      - stopped
                      - terminated
                      - softdeleted
                      - degraded
                      - failed
                      - idle
                  canWake:
                    description: >-
                      Whether the service can be woken before retrying the
                      attachment.
                    type: boolean
                  status:
                    description: HTTP status code.
                    example: 424
                    type: integer
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - code
                  - serviceState
                  - canWake
                  - status
                  - requestId
                additionalProperties: false
        '500':
          description: >-
            An internal server error has occurred. If this issue persists,
            please contact ClickHouse Cloud support for assistance.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    description: Error message.
                    type: string
                  status:
                    type: integer
                    description: HTTP status code.
                    example: 500
                  requestId:
                    description: Unique id assigned to every request. UUIDv4
                    type: string
                    format: uuid
                    pattern: >-
                      ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
                required:
                  - error
                  - status
                  - requestId
                additionalProperties: {}
components:
  schemas:
    UdfAttachment:
      type: object
      properties:
        functionName:
          description: Name of the UDF.
          type: string
        serviceId:
          description: ID of the attached service.
          type: string
          format: uuid
          pattern: >-
            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$
        status:
          description: Current attachment lifecycle state.
          type: string
          enum:
            - deployed
            - deprovisioning
            - error
            - provisioning
            - standby
        version:
          description: Attached UDF version.
          example: 1
          type: integer
          exclusiveMinimum: 0
      required:
        - functionName
        - serviceId
        - status
        - version
      additionalProperties: false
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: >-
        Use key ID and key secret obtained in ClickHouse Cloud console:
        https://clickhouse.com/docs/cloud/manage/openapi

````