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

# Update Custom Function

> Update an existing custom function

Update an existing custom function. You can update the name, description, source code, and limits. If source code changes, the function is re-analyzed automatically.

## Path Parameters

<ParamField path="function_id" type="string" required>
  Unique identifier of the custom function
</ParamField>

## Request Body

All fields are optional. Only provided fields will be updated.

<ParamField body="name" type="string">
  Updated display name
</ParamField>

<ParamField body="description" type="string">
  Updated description
</ParamField>

<ParamField body="source_code" type="string">
  Updated Python source code (triggers re-analysis)
</ParamField>

<ParamField body="limits" type="object">
  Updated execution limits
</ParamField>

## Response

Returns the updated `CustomFunctionItem`.

## Example Request

```bash theme={"dark"}
curl -X PATCH -H "x-api-key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{"description": "Updated description", "source_code": "def xpander_run_action(city: str) -> str:\n    return f\"Weather in {city}: Sunny\""}' \
  "https://api.xpander.ai/v1/custom_functions/<function-id>"
```

## Notes

* Changing `source_code` triggers automatic re-analysis — status resets to `analysing`
* Non-code fields (name, description, limits) can be updated without triggering re-analysis


## OpenAPI

````yaml PATCH /v1/custom_functions/{function_id}
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/custom_functions/{function_id}:
    patch:
      tags:
        - API v1
        - Custom Functions
        - Custom Functions CRUD
      summary: Update Custom Function
      description: >-
        Update an existing custom function. You can update name, description,
        source_code, and limits. If source_code changes, the function is
        re-analyzed automatically.
      operationId: Update_custom_function_v1_custom_functions__function_id__patch
      parameters:
        - name: function_id
          in: path
          required: true
          schema:
            type: string
            title: Function Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCustomFunctionRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    UpdateCustomFunctionRequest:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
          description: Updated function name.
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: Updated function description.
        source_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Source Code
          description: Updated Python source code. If changed, triggers re-analysis.
        limits:
          anyOf:
            - $ref: '#/components/schemas/CustomFunctionLimitsModel'
            - type: 'null'
          description: Updated resource limits.
      type: object
      title: UpdateCustomFunctionRequest
      description: >-
        Request model for updating an existing custom function.


        All fields are optional. If source_code changes, the function will be

        re-analyzed automatically (status transitions to 'analysing' then
        'ready').
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    CustomFunctionLimitsModel:
      properties:
        max_run_time:
          anyOf:
            - type: integer
            - type: 'null'
          title: Max Run Time
          description: >-
            Maximum execution time in seconds. The function will be terminated
            if it exceeds this limit. Default: 15 seconds.
          default: 15
      type: object
      title: CustomFunctionLimitsModel
      description: Resource limits for custom function execution.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````