> ## 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.

# Execute Custom Function

> Execute a custom function with the provided parameters

Execute a custom function directly with the provided parameters. The function must be in `ready` status. Parameters are passed as key-value pairs matching the function's `input_schema`.

## Path Parameters

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

## Request Body

Pass parameters as key-value pairs matching the function's `input_schema`. The exact fields depend on the function definition.

## Response

Returns the function execution result.

## Example Request

```bash theme={"dark"}
curl -X POST "https://api.xpander.ai/v1/custom_functions/<function-id>/execute" \
  -H "Content-Type: application/json" \
  -H "x-api-key: <your-api-key>" \
  -d '{"city": "San Francisco"}'
```

## Notes

* The function must be in `ready` status — functions in `analysing` or `error` status cannot be executed
* Parameters must match the function's `input_schema` (see [Get Custom Function](/api-reference/v1/custom_functions/get-custom-function))
* Useful for testing functions before attaching them to agents


## OpenAPI

````yaml POST /v1/custom_functions/{function_id}/execute
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}/execute:
    post:
      tags:
        - API v1
        - Custom Functions
        - Custom Functions
      summary: Execute Custom Function
      description: >-
        Execute a custom function with the provided parameters. The function
        must be in 'ready' status. Parameters are passed as key-value pairs in
        the request body matching the function's input_schema.
      operationId: Execute_custom_function_v1_custom_functions__function_id__execute_post
      parameters:
        - name: function_id
          in: path
          required: true
          schema:
            type: string
            title: Function Id
      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:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    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

````