Tools (Functions) API
Tools are individual functions that perform specific operations. You can search for available tools and execute them directly via the API.
Base URL
All Tools API requests go through the marketplace proxy:
/api/agent/functions
For self-hosted installations, prepend your instance URL: http://kaman.ai/api/agent/functions
Search Tools
Search for available tools by name or description.
Endpoint
GET /api/agent/functions
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| q | string | Yes | Search query (searches name and description) |
Example
bash
curl -X GET "http://kaman.ai/api/agent/functions?q=email" \
-H "Authorization: Bearer kam_your_api_key"
Response
json
[
{
"id": 42,
"name": "Send Email",
"description": "Sends an email to specified recipients",
"inputFields": [
{
"name": "to",
"type": "string",
"required": true,
"description": "Recipient email address"
},
{
"name": "subject",
"type": "string",
"required": true,
"description": "Email subject line"
},
{
"name": "body",
"type": "string",
"required": true,
"description": "Email body content"
}
],
"outputFields": [
{
"name": "messageId",
"type": "string",
"description": "ID of the sent email"
},
{
"name": "success",
"type": "boolean",
"description": "Whether the email was sent successfully"
}
]
}
]
Execute a Tool
Execute a tool by its ID or name with the provided arguments.
Endpoint
POST /api/agent/functions/{id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
| id | string | Function ID (numeric) or function name |
Request Body
The request body should contain the arguments required by the tool's input fields.
Example (by ID)
bash
curl -X POST "http://kaman.ai/api/agent/functions/42" \
-H "Authorization: Bearer kam_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"to": "user@example.com",
"subject": "Hello from Kaman",
"body": "This is a test email sent via the Kaman API."
}'
Example (by Name)
bash
curl -X POST "http://kaman.ai/api/agent/functions/Send%20Email" \
-H "Authorization: Bearer kam_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"to": "user@example.com",
"subject": "Hello from Kaman",
"body": "This is a test email sent via the Kaman API."
}'
Response (Success)
json
{
"result": {
"messageId": "msg_abc123",
"success": true
}
}
Response (Error)
json
{
"error": "Invalid email address format"
}
Code Examples
TypeScript
typescript
const API_KEY = process.env.KAMAN_API_KEY;
const BASE_URL = 'http://kaman.ai';
// Search for tools
async function searchTools(query: string) {
const response = await fetch(
`${BASE_URL}/api/agent/functions?q=${encodeURIComponent(query)}`,
{
headers: {
'Authorization': `Bearer ${API_KEY}`
}
}
);
return response.json();
}
// Execute a tool by ID
async function executeTool(toolId: number | string, args: Record<string, any>) {
const response = await fetch(
`${BASE_URL}/api/agent/functions/${toolId}`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(args)
}
);
return response.json();
}
// Example usage
const emailTools = await searchTools('email');
const result = await executeTool(42, {
to: 'user@example.com',
subject: 'Hello',
body: 'Test email'
});
Python
python
import requests
import os
from typing import Optional, Dict, Any, List
class KamanTools:
def __init__(self, base_url: str):
self.base_url = f'{base_url}/api/agent/functions'
self.headers = {
'Authorization': f'Bearer {os.getenv("KAMAN_API_KEY")}',
'Content-Type': 'application/json'
}
def search(self, query: str) -> List[Dict]:
"""Search for tools by name or description."""
response = requests.get(
self.base_url,
params={'q': query},
headers=self.headers
)
return response.json()
def execute(self, tool_id: str | int, args: Dict[str, Any]) -> Dict[str, Any]:
"""Execute a tool with the provided arguments."""
response = requests.post(
f'{self.base_url}/{tool_id}',
json=args,
headers=self.headers
)
return response.json()
# Example usage
client = KamanTools('http://kaman.ai')
# Search for email-related tools
tools = client.search('email')
for tool in tools:
print(f"{tool['name']}: {tool['description']}")
# Execute a tool
result = client.execute(42, {
'to': 'user@example.com',
'subject': 'Hello',
'body': 'Test email'
})
print(result)
cURL
bash
#!/bin/bash
API_KEY="${KAMAN_API_KEY}"
BASE_URL="http://kaman.ai/api/agent/functions"
# Search for tools
curl -s "$BASE_URL?q=email" \
-H "Authorization: Bearer $API_KEY"
# Execute a tool by ID
curl -s -X POST "$BASE_URL/42" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "user@example.com",
"subject": "Hello",
"body": "Test email"
}'
Understanding Tool Definitions
Each tool has defined input and output fields:
Input Fields
| Property | Type | Description |
|---|---|---|
| name | string | Field name (used as the argument key) |
| type | string | Data type (string, number, boolean, array, object) |
| required | boolean | Whether this field is required |
| description | string | Description of the field |
Output Fields
| Property | Type | Description |
|---|---|---|
| name | string | Field name in the result |
| type | string | Data type of the output |
| description | string | Description of the output |
Error Handling
| Status | Error | Description |
|---|---|---|
| 400 | Validation error | Missing or invalid input arguments |
| 401 | Unauthorized | Invalid or missing authentication |
| 404 | Tool not found | Invalid tool ID or name |
| 500 | Execution error | Error during tool execution |
Error Response
json
{
"error": "Missing required field: to"
}
Best Practices
- Check Tool Requirements: Use the search endpoint to inspect required input fields before execution
- Validate Inputs: Ensure all required fields are provided with correct types
- Handle Errors: Implement proper error handling for failed executions
- Use IDs When Possible: Using tool IDs is faster than names since names require lookup
Next Steps
- Workflows API - Chain multiple tools into workflows
- Authentication - Learn about API authentication
- KDL API - Query your data lake