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": {}
}
}
'import requests
url = "https://api.example.com/api/functions/create"
payload = {
"id": "<string>",
"name": "<string>",
"content": "<string>",
"meta": {
"description": "<string>",
"manifest": {}
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: '<string>',
name: '<string>',
content: '<string>',
meta: {description: '<string>', manifest: {}}
})
};
fetch('https://api.example.com/api/functions/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/functions/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'name' => '<string>',
'content' => '<string>',
'meta' => [
'description' => '<string>',
'manifest' => [
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/functions/create"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/functions/create")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/functions/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"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": {}
}
}
'import requests
url = "https://api.example.com/api/functions/create"
payload = {
"id": "<string>",
"name": "<string>",
"content": "<string>",
"meta": {
"description": "<string>",
"manifest": {}
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
id: '<string>',
name: '<string>',
content: '<string>',
meta: {description: '<string>', manifest: {}}
})
};
fetch('https://api.example.com/api/functions/create', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/functions/create",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'name' => '<string>',
'content' => '<string>',
'meta' => [
'description' => '<string>',
'manifest' => [
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/functions/create"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/functions/create")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/functions/create")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"name\": \"<string>\",\n \"content\": \"<string>\",\n \"meta\": {\n \"description\": \"<string>\",\n \"manifest\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"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
string
required
Unique identifier for the function. Must be alphanumeric with underscores only (will be converted to lowercase).
string
required
Display name for the function
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
object
required
Response
string
The function identifier
string
ID of the user who created the function
string
Function type (automatically detected from the function code)
string
Function name
object
Function metadata with parsed manifest
boolean
Whether the function is active (default: false)
boolean
Whether the function is globally available (default: false)
integer
Unix timestamp of creation
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
""") 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
string
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