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

> Updates an existing custom variable by its ID. Use this endpoint to modify a variable's source, default value, or other properties.  **Partial updates:** Only the provided fields are updated; omitted

# Update Custom Variable

For the complete error reference, see [Error Guide](/rest-api/ai-agents-apis/error-codes).


## OpenAPI

````yaml patch /ai-agents/agent-builder/agents/variables/custom/{variableId}
openapi: 3.0.0
info:
  title: AI Agents APIs
  description: API reference for CometChat AI Agents service
  version: '1.0'
servers:
  - url: https://{appId}.api-{region}.cometchat.io/v3
    variables:
      appId:
        default: appId
        description: (Required) App ID
      region:
        enum:
          - us
          - eu
          - in
        default: us
        description: Select Region
security: []
tags:
  - name: ai-agent
    description: ''
paths:
  /ai-agents/agent-builder/agents/variables/custom/{variableId}:
    patch:
      tags:
        - Agent Builder
      summary: Update Custom Variable
      description: >-
        Updates an existing custom variable by its ID. Use this endpoint to
        modify a variable's source, default value, or other properties.


        **Partial updates:** Only the provided fields are updated; omitted
        fields remain unchanged.


        **Restrictions:** The variable name cannot be changed after creation.
      operationId: AgentBuilderController_updateCustomVariable
      parameters:
        - name: variableId
          required: true
          in: path
          description: Variable ID to update
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCustomVariableDto'
      responses:
        '200':
          description: Custom variable updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  _id:
                    type: string
                    example: 507f1f77bcf86cd799439011
                  appId:
                    type: string
                    example: my-app-id
                  name:
                    type: string
                    example: user.plan
                  description:
                    type: string
                    example: The user subscription plan
                  sourceType:
                    type: string
                    enum:
                      - message_metadata
                      - user_metadata
                      - constant
                    example: user_metadata
                  sourcePath:
                    type: string
                    example: metadata.plan
                  constantValue:
                    type: string
                    example: premium
                  defaultValue:
                    type: string
                    example: free
                  category:
                    type: string
                    enum:
                      - custom
                    example: custom
                  createdAt:
                    type: number
                    example: 1700000000000
                  updatedAt:
                    type: number
                    example: 1700000000000
              example:
                _id: 507f1f77bcf86cd799439011
                appId: my-app-id
                name: user.plan
                description: Updated description
                sourceType: user_metadata
                sourcePath: metadata.plan
                constantValue: ''
                defaultValue: premium
                category: custom
                createdAt: 1700000000000
                updatedAt: 1700000100000
      security:
        - apiKey: []
components:
  schemas:
    UpdateCustomVariableDto:
      type: object
      properties:
        description:
          type: string
          description: Human-readable description of the variable
          maxLength: 200
          example: The preferred language of the user
        sourceType:
          type: string
          description: Source from which the variable value is resolved
          enum:
            - message_metadata
            - user_metadata
            - constant
          example: user_metadata
        sourcePath:
          type: string
          description: Dot-notation path to extract the value from the source metadata
          maxLength: 100
          example: language
        constantValue:
          type: string
          description: Fixed value used when sourceType is constant
          maxLength: 500
          example: en
        defaultValue:
          type: string
          description: Fallback value used when the source path does not resolve
          maxLength: 200
          example: en
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key (i.e. Rest API Key from the Dashboard).
      name: apikey
      in: header

````