Overview
Tools extend the capabilities of AI agents by providing custom functions they can invoke. The Tools API allows you to programmatically manage custom tools for your chatflows.
All tool endpoints require JWT authentication. See Authentication for details.
Retrieve all tools in your workspace.
curl -X GET http://localhost:3000/api/v1/tools \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Query Parameters
Page number for pagination
Response
[
{
"id" : "tool-uuid" ,
"name" : "Weather Tool" ,
"description" : "Get current weather for a city" ,
"color" : "#3B82F6" ,
"iconSrc" : "https://example.com/weather-icon.png" ,
"schema" : "{ \" type \" : \" object \" , \" properties \" :{ \" city \" :{ \" type \" : \" string \" }}}" ,
"func" : "async function getWeather(city) { ... }" ,
"workspaceId" : "workspace-id" ,
"createdDate" : "2024-03-15T10:30:00.000Z" ,
"updatedDate" : "2024-03-15T10:30:00.000Z"
}
]
Unique identifier for the tool
Description of what the tool does (shown to the AI)
Hex color code for the tool’s visual representation
URL to an icon image for the tool
JSON schema defining the tool’s input parameters
JavaScript function code that executes when the tool is called
ID of the workspace this tool belongs to
Retrieve a specific tool by its ID.
curl -X GET http://localhost:3000/api/v1/tools/TOOL_ID \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Path Parameters
The unique identifier of the tool
Response
Returns a single tool object with the same structure as shown in the list response.
Create a new custom tool.
curl -X POST http://localhost:3000/api/v1/tools \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Calculator",
"description": "Perform mathematical calculations",
"color": "#10B981",
"schema": "{\"type\":\"object\",\"properties\":{\"expression\":{\"type\":\"string\",\"description\":\"Mathematical expression to evaluate\"}}}",
"func": "async function calculate(expression) { return eval(expression); }"
}'
Request Body
Description of what the tool does. This is shown to the AI agent to help it decide when to use the tool.
Hex color code for visual representation (e.g., #3B82F6)
URL to an icon image for the tool
JSON schema (as a string) defining the tool’s input parameters {
"type" : "object" ,
"properties" : {
"city" : {
"type" : "string" ,
"description" : "City name"
},
"units" : {
"type" : "string" ,
"enum" : [ "celsius" , "fahrenheit" ],
"description" : "Temperature units"
}
},
"required" : [ "city" ]
}
JavaScript function code that executes when the tool is called async function getWeather ( city , units = 'celsius' ) {
const apiKey = 'YOUR_API_KEY' ;
const response = await fetch (
`https://api.weather.com/v1/current?city= ${ city } &units= ${ units } &key= ${ apiKey } `
);
const data = await response . json ();
return `The current temperature in ${ city } is ${ data . temp } ° ${ units === 'celsius' ? 'C' : 'F' } ` ;
}
Response
{
"id" : "tool-uuid" ,
"name" : "Calculator" ,
"description" : "Perform mathematical calculations" ,
"color" : "#10B981" ,
"schema" : "{...}" ,
"func" : "async function calculate(expression) { ... }" ,
"workspaceId" : "workspace-id" ,
"createdDate" : "2024-03-15T10:30:00.000Z" ,
"updatedDate" : "2024-03-15T10:30:00.000Z"
}
Update an existing tool.
curl -X PUT http://localhost:3000/api/v1/tools/TOOL_ID \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"description": "Updated description",
"color": "#F59E0B"
}'
Path Parameters
The unique identifier of the tool to update
Request Body
Include only the fields you want to update. All fields from the create endpoint are supported.
Response
Returns the updated tool object.
Delete a tool permanently.
curl -X DELETE http://localhost:3000/api/v1/tools/TOOL_ID \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Path Parameters
The unique identifier of the tool to delete
Response
{
"message" : "Tool deleted successfully"
}
Deleting a tool will break any chatflows currently using it. Ensure no active flows depend on the tool before deletion.
When creating tool functions, follow these best practices:
Always define tools as async functions, even if they don’t perform asynchronous operations: async function myTool ( param ) {
// Your code here
return result ;
}
Wrap your code in try-catch blocks and return user-friendly error messages: async function weatherTool ( city ) {
try {
const response = await fetch ( `https://api.weather.com/v1/ ${ city } ` );
if ( ! response . ok ) {
return `Error: Unable to fetch weather for ${ city } ` ;
}
const data = await response . json ();
return `Temperature: ${ data . temp } °C` ;
} catch ( error ) {
return `Error: ${ error . message } ` ;
}
}
Return Descriptive Results
Return results in a format that’s easy for the AI to understand and present to users: // Good - descriptive result
return `The stock price of ${ symbol } is $ ${ price } ( ${ change > 0 ? '+' : '' }${ change } %)` ;
// Bad - just raw data
return { price: 150.25 , change: 2.3 };
Validate Input Parameters
Simple Parameter
Multiple Parameters
Complex Schema
{
"type" : "object" ,
"properties" : {
"query" : {
"type" : "string" ,
"description" : "Search query"
}
},
"required" : [ "query" ]
}
Weather Tool
Database Query Tool
// Tool configuration
{
"name" : "Get Weather" ,
"description" : "Get current weather information for any city" ,
"color" : "#3B82F6" ,
"schema" : JSON . stringify ({
"type" : "object" ,
"properties" : {
"city" : {
"type" : "string" ,
"description" : "City name"
},
"units" : {
"type" : "string" ,
"enum" : [ "celsius" , "fahrenheit" ],
"default" : "celsius"
}
},
"required" : [ "city" ]
}),
"func" : `async function getWeather(city, units = 'celsius') {
try {
const apiKey = process.env.WEATHER_API_KEY;
const response = await fetch(
\` https://api.openweathermap.org/data/2.5/weather?q= \$ {city}&units= \$ {units === 'celsius' ? 'metric' : 'imperial'}&appid= \$ {apiKey} \`
);
if (!response.ok) {
return \` Unable to find weather data for \$ {city} \` ;
}
const data = await response.json();
const temp = Math.round(data.main.temp);
const condition = data.weather[0].description;
return \` The weather in \$ {city} is \$ {condition} with a temperature of \$ {temp}° \$ {units === 'celsius' ? 'C' : 'F'} \` ;
} catch (error) {
return \` Error fetching weather: \$ {error.message} \` ;
}
}`
}
Code Examples
// Create a tool
const newTool = await fetch ( 'http://localhost:3000/api/v1/tools' , {
method: 'POST' ,
headers: {
'Authorization' : 'Bearer YOUR_JWT_TOKEN' ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ({
name: 'Calculator' ,
description: 'Perform mathematical calculations' ,
color: '#10B981' ,
schema: JSON . stringify ({
type: 'object' ,
properties: {
expression: {
type: 'string' ,
description: 'Math expression to evaluate'
}
},
required: [ 'expression' ]
}),
func: `async function calculate(expression) {
try {
const result = eval(expression);
return \` Result: \$ {result} \` ;
} catch (error) {
return 'Invalid expression';
}
}`
})
}). then ( res => res . json ());
// List all tools
const tools = await fetch ( 'http://localhost:3000/api/v1/tools' , {
headers: {
'Authorization' : 'Bearer YOUR_JWT_TOKEN'
}
}). then ( res => res . json ());
// Update a tool
const updated = await fetch ( `http://localhost:3000/api/v1/tools/ ${ toolId } ` , {
method: 'PUT' ,
headers: {
'Authorization' : 'Bearer YOUR_JWT_TOKEN' ,
'Content-Type' : 'application/json'
},
body: JSON . stringify ({
description: 'Updated calculator tool description'
})
}). then ( res => res . json ());