Skip to main content
POST
/
api
/
functions
/
create
Create Function
curl --request POST \
  --url https://api.example.com/api/functions/create \
  --header 'Content-Type: application/json' \
  --data '
{
  "id": "<string>",
  "name": "<string>",
  "content": "<string>",
  "meta": {
    "description": "<string>",
    "manifest": {}
  }
}
'
{
  "id": "<string>",
  "user_id": "<string>",
  "type": "<string>",
  "name": "<string>",
  "meta": {},
  "is_active": true,
  "is_global": true,
  "updated_at": 123,
  "created_at": 123,
  "detail": "<string>"
}

Create New Function

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": {}
    }
  }'
Creates a new function. The function ID must be unique and contain only alphanumeric characters and underscores.

Request Body

id
string
required
Unique identifier for the function. Must be alphanumeric with underscores only (will be converted to lowercase).
name
string
required
Display name for the function
content
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
meta
object
required
Metadata for the function

Response

id
string
The function identifier
user_id
string
ID of the user who created the function
type
string
Function type (automatically detected from the function code)
name
string
Function name
meta
object
Function metadata with parsed manifest
is_active
boolean
Whether the function is active (default: false)
is_global
boolean
Whether the function is globally available (default: false)
updated_at
integer
Unix timestamp of creation
created_at
integer
Unix timestamp of creation

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:
"""
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

detail
string
Error message
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.