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>"
}Functions & Tools
Create Function
Create a new function in the system
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": {}
}
}'
Request Body
Unique identifier for the function. Must be alphanumeric with underscores only (will be converted to lowercase).
Display name for the function
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
Response
The function identifier
ID of the user who created the function
Function type (automatically detected from the function code)
Function name
Function metadata with parsed manifest
Whether the function is active (default: false)
Whether the function is globally available (default: false)
Unix timestamp of creation
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
""") is parsed as the manifest.
Special Behaviors
Filter Functions with Toggle
If your function is detected as a “filter” type and has atoggle 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
Error message
- Invalid function ID format (non-alphanumeric/underscore characters)
- Function ID already exists
- Invalid Python code
- Failed to load function module
- Missing or invalid admin authentication
Authentication
Requires admin privileges.⌘I