Skip to main content

REST API

Complete reference for all Saiki REST API endpoints. All endpoints are prefixed with /api/.

Base URL

http://localhost:3001/api

Message Endpoints

Send Message (Synchronous)

Send a message to the agent and receive the complete response.

POST /api/message-sync

Request Body

FieldTypeRequiredDescription
messagestringThe message to send to the agent
imageDataobjectOptional image data for multimodal input
imageData.base64stringBase64 encoded image string
imageData.mimeTypestringImage MIME type (e.g., "image/png")

Example Request

curl -X POST http://localhost:3001/api/message-sync \
-H "Content-Type: application/json" \
-d '{
"message": "What files are in the current directory?",
"imageData": {
"base64": "iVBORw0KGgoAAAANSUhEUgAAAAUA...",
"mimeType": "image/png"
}
}'

Example Response

{
"success": true,
"response": "I can see several files in the current directory:\n\n1. package.json - Node.js project configuration\n2. README.md - Project documentation\n3. src/ - Source code directory\n4. docs/ - Documentation files\n\nWould you like me to examine any specific file in more detail?",
"timestamp": "2024-01-15T10:30:00.000Z"
}

Status Codes

CodeDescription
200Success - Message processed
400Bad Request - Invalid message format
429Rate Limit - Too many requests
500Server Error - Processing failed

Send Message (Asynchronous)

Send a message to the agent asynchronously. Use WebSocket to receive the response.

POST /api/message

Request Body

FieldTypeRequiredDescription
messagestringThe message to send to the agent

Example Request

curl -X POST http://localhost:3001/api/message \
-H "Content-Type: application/json" \
-d '{"message": "Analyze the project structure"}'

Example Response

{
"status": "processing",
"timestamp": "2024-01-15T10:30:00.000Z"
}
WebSocket Required

The actual response will be sent via WebSocket events. See WebSocket API for details.

Reset Conversation

Clear the agent's conversation history for a fresh start.

POST /api/reset

Request Body

No request body required (can be empty or {}).

Example Request

curl -X POST http://localhost:3001/api/reset \
-H "Content-Type: application/json"

Example Response

{
"status": "reset initiated",
"timestamp": "2024-01-15T10:30:00.000Z"
}

MCP Server Management

List MCP Servers

Get all connected and attempted MCP servers with their status.

GET /api/mcp/servers

Example Request

curl http://localhost:3001/api/mcp/servers

Example Response

{
"servers": [
{
"id": "filesystem",
"name": "filesystem",
"status": "connected",
"type": "stdio",
"description": "File system operations"
},
{
"id": "puppeteer",
"name": "puppeteer",
"status": "error",
"type": "stdio",
"error": "Failed to start server process"
}
],
"timestamp": "2024-01-15T10:30:00.000Z"
}

Server Status Values

StatusDescription
connectedServer is running and connected
connectingServer is starting up
errorServer failed to start or crashed
disconnectedServer was disconnected

Connect New MCP Server

Dynamically connect a new MCP server to the agent at runtime.

POST /api/connect-server

Request Body

FieldTypeRequiredDescription
namestringUnique name for the server
configobjectServer configuration
config.typestringServer type (usually "stdio")
config.commandstringCommand to start the server
config.argsarrayCommand arguments
config.envobjectEnvironment variables

Example Request

curl -X POST http://localhost:3001/api/connect-server \
-H "Content-Type: application/json" \
-d '{
"name": "database",
"config": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@truffle-ai/database-server"],
"env": {
"DB_URL": "postgresql://localhost:5432/mydb"
}
}
}'

Example Response

{
"status": "connected",
"name": "database",
"server": {
"id": "database",
"name": "database",
"status": "connected",
"type": "stdio"
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Tool Management

List Server Tools

Get all tools available from a specific MCP server.

GET /api/mcp/servers/{serverId}/tools

Path Parameters

ParameterTypeRequiredDescription
serverIdstringThe ID/name of the MCP server

Example Request

curl http://localhost:3001/api/mcp/servers/filesystem/tools

Example Response

{
"tools": [
{
"id": "readFile",
"name": "readFile",
"description": "Read the contents of a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file to read"
}
},
"required": ["path"]
}
},
{
"id": "writeFile",
"name": "writeFile",
"description": "Write content to a file",
"inputSchema": {
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Path to the file to write"
},
"content": {
"type": "string",
"description": "Content to write to the file"
}
},
"required": ["path", "content"]
}
}
],
"timestamp": "2024-01-15T10:30:00.000Z"
}

Execute Tool

Directly execute a specific tool on a connected MCP server.

POST /api/mcp/servers/{serverId}/tools/{toolName}/execute

Path Parameters

ParameterTypeRequiredDescription
serverIdstringThe ID/name of the MCP server
toolNamestringThe name of the tool to execute

Request Body

The request body should match the tool's inputSchema. See the tool list endpoint for schema details.

Example Request

curl -X POST http://localhost:3001/api/mcp/servers/filesystem/tools/readFile/execute \
-H "Content-Type: application/json" \
-d '{"path": "./README.md"}'

Example Response

{
"success": true,
"data": {
"content": "# My Project\n\nThis is a sample README file...",
"encoding": "utf-8",
"size": 1234
},
"execution": {
"toolName": "readFile",
"serverId": "filesystem",
"duration": 45
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Configuration

Export Configuration

Get the current agent configuration in YAML format. Sensitive information is omitted.

GET /api/config.yaml

Example Request

curl http://localhost:3001/api/config.yaml

Example Response

mcpServers:
filesystem:
type: stdio
command: npx
args:
- "-y"
- "@modelcontextprotocol/server-filesystem"
- "."

llm:
provider: openai
model: gpt-4.1-mini
apiKey: "***REDACTED***"
systemPrompt: |
You are Saiki, a helpful AI assistant with access to tools.
Use these tools when appropriate to answer user queries.

version: "0.2.5"

Health Check

API Health

Check if the Saiki API is running and healthy.

GET /api/health

Example Request

curl http://localhost:3001/api/health

Example Response

{
"status": "healthy",
"version": "0.2.5",
"uptime": 3600,
"agent": {
"status": "ready",
"connectedServers": 2
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Error Responses

All endpoints return errors in a consistent format:

Error Response Format

{
"success": false,
"error": {
"code": "ERROR_CODE",
"message": "Human readable error message",
"details": {
"field": "Additional error context",
"suggestion": "How to fix this error"
}
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Common Error Codes

CodeStatusDescription
INVALID_REQUEST400Request format is invalid
MISSING_FIELD400Required field is missing
UNAUTHORIZED401Authentication required
RATE_LIMIT_EXCEEDED429Too many requests
SERVER_NOT_FOUND404MCP server not found
TOOL_NOT_FOUND404Tool not found on server
TOOL_EXECUTION_FAILED500Tool execution failed
AGENT_ERROR500Agent processing error
INTERNAL_ERROR500Unexpected server error

Example Error Responses

Missing Required Field

{
"success": false,
"error": {
"code": "MISSING_FIELD",
"message": "Missing required field: message",
"details": {
"field": "message",
"suggestion": "Include a 'message' field in your request body"
}
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Tool Execution Failed

{
"success": false,
"error": {
"code": "TOOL_EXECUTION_FAILED",
"message": "Failed to execute tool: readFile",
"details": {
"toolName": "readFile",
"serverId": "filesystem",
"reason": "File not found: ./nonexistent.txt"
}
},
"timestamp": "2024-01-15T10:30:00.000Z"
}

Rate Limiting

API responses include rate limiting headers:

HTTP/1.1 200 OK
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1640995200
Content-Type: application/json

See Authentication for detailed rate limiting information.

Next Steps