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

# Create Function

> Create a new function in the system

## Create New Function

<CodeGroup>
  ```bash POST /api/functions/create theme={null}
  curl -X POST "https://your-instance.com/api/functions/create" \
    -H "Authorization: Bearer YOUR_ADMIN_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "id": "my_custom_function",
      "name": "My Custom Function",
      "content": "def main():\n    pass",
      "meta": {
        "description": "A custom function",
        "manifest": {}
      }
    }'
  ```
</CodeGroup>

Creates a new function. The function ID must be unique and contain only alphanumeric characters and underscores.

## Request Body

<ParamField body="id" type="string" required>
  Unique identifier for the function. Must be alphanumeric with underscores only (will be converted to lowercase).
</ParamField>

<ParamField body="name" type="string" required>
  Display name for the function
</ParamField>

<ParamField body="content" type="string" required>
  Python source code for the function. The system will:

  * Replace imports with internal versions
  * Load and validate the function module
  * Extract function type (e.g., "filter", "action")
  * Parse frontmatter manifest
</ParamField>

<ParamField body="meta" type="object" required>
  Metadata for the function

  <Expandable title="meta properties">
    <ParamField body="description" type="string">
      Description of what the function does
    </ParamField>

    <ParamField body="manifest" type="object">
      Additional manifest data (will be populated from function frontmatter)
    </ParamField>
  </Expandable>
</ParamField>

## Response

<ResponseField name="id" type="string">
  The function identifier
</ResponseField>

<ResponseField name="user_id" type="string">
  ID of the user who created the function
</ResponseField>

<ResponseField name="type" type="string">
  Function type (automatically detected from the function code)
</ResponseField>

<ResponseField name="name" type="string">
  Function name
</ResponseField>

<ResponseField name="meta" type="object">
  Function metadata with parsed manifest
</ResponseField>

<ResponseField name="is_active" type="boolean">
  Whether the function is active (default: false)
</ResponseField>

<ResponseField name="is_global" type="boolean">
  Whether the function is globally available (default: false)
</ResponseField>

<ResponseField name="updated_at" type="integer">
  Unix timestamp of creation
</ResponseField>

<ResponseField name="created_at" type="integer">
  Unix timestamp of creation
</ResponseField>

## Function Types

The system automatically detects the function type from your code:

* **filter**: Functions that process/filter content
* **action**: Functions that perform actions
* Other types may be supported depending on your configuration

## Python Function Pattern

Functions should follow this pattern:

```python theme={null}
"""
title: My Function
author: Your Name
version: 1.0.0
"""

class Valves(BaseModel):
    # Optional: Define configuration parameters
    pass

class UserValves(BaseModel):
    # Optional: Define user-specific parameters
    pass

def main():
    # Your function logic
    pass
```

The frontmatter (between `"""`) is parsed as the manifest.

## Special Behaviors

### Filter Functions with Toggle

If your function is detected as a "filter" type and has a `toggle` attribute, the system automatically sets `meta.toggle` to `true`.

### Import Replacement

The system automatically replaces imports to use internal module versions for security and compatibility.

## Error Responses

<ResponseField name="detail" type="string">
  Error message
</ResponseField>

**400 Bad Request**

* Invalid function ID format (non-alphanumeric/underscore characters)
* Function ID already exists
* Invalid Python code
* Failed to load function module

**401 Unauthorized**

* Missing or invalid admin authentication

## Authentication

Requires admin privileges.
