API Reference
Overview
The RACE Management Console provides a comprehensive REST API for managing industrial data monitoring, rule configuration, and AI-powered analysis. All API endpoints return JSON responses and follow RESTful conventions.
Base URL
http://localhost:5000
Authentication
Most API endpoints require authentication through Flask sessions. AI provider endpoints may require additional API keys configured in the system.
Response Format
All API responses follow this standard format:
{
"success": true|false,
"data": {...},
"error": "Error message (if success=false)",
"message": "Success message (optional)"
}
Configuration API
Get API Configuration
GET /api/configuration
Response:
{
"success": true,
"data": {
"id": 1,
"client_id": "client_id",
"region": "us",
"tenant_id": "tenant_id",
"namespace_id": "namespace_id",
"is_active": true
}
}
Update API Configuration
POST /api/configuration
Request Body:
{
"client_id": "your_client_id",
"client_secret": "your_client_secret",
"region": "us",
"tenant_id": "your_tenant_id",
"namespace_id": "your_namespace_id"
}
Test API Connection
POST /api/test-connection
Response:
{
"success": true,
"data": {
"connection_status": "success",
"tenant_info": {...},
"namespace_info": {...}
}
}
Asset Discovery API
Discover Assets
POST /api/discover-assets
Response:
{
"success": true,
"data": {
"assets_discovered": 15,
"streams_discovered": 47,
"assets": [...]
}
}
Get Monitored Assets
GET /api/monitored-assets
Response:
{
"success": true,
"data": [
{
"id": 1,
"asset_id": "Wonderbrew.Roaster022",
"display_name": "Roaster022",
"is_active": true,
"streams": [...]
}
]
}
Rule Management API
Get Packages
GET /api/packages
Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "Manufacturing Operations",
"description": "Core manufacturing rules",
"templates": [...]
}
]
}
Create Package
POST /api/packages
Request Body:
{
"name": "New Package",
"description": "Package description"
}
Get Rule Templates
GET /api/packages/{package_id}/templates
Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "Asset Utilization",
"category": "utilization",
"color": "#00c7fc",
"rules": [...],
"instances": [...]
}
]
}
Create Rule Template
POST /api/packages/{package_id}/templates
Request Body:
{
"name": "Equipment Health",
"category": "health",
"color": "#ff6b35",
"description": "Equipment health monitoring"
}
Get Template Instances
GET /api/template-instances/{template_id}
Response:
{
"success": true,
"data": [
{
"id": 1,
"instance_name": "IST ROA 022 Asset Utilization",
"is_deployed": true,
"plant_node_floc_id": "ENT-MIL-ARE1-LIN02-ROA022",
"placeholders": [...]
}
]
}
Deploy Template Instance
POST /api/template-instances
Request Body:
{
"template_id": 1,
"instance_name": "New Instance",
"plant_node_floc_id": "PLANT-NODE-001",
"placeholders": [
{
"placeholder_name": "EQUIPMENT",
"stream_name": "Wonderbrew.Roaster022"
}
]
}
Event Management API
Get Active Events
GET /api/rule-events/active
Response:
{
"success": true,
"data": [
{
"id": 916,
"event_name": "BL-A00378.OnHold",
"event_description": "Holding On",
"severity": "warning",
"is_active": true,
"start_time": "2025-08-10T09:34:17.023182",
"enrichment": {
"ProductionID": "PR-A008100913"
},
"template_instance": "IST ROA 022 Asset Utilization"
}
]
}
Get Event History
GET /api/rule-events/history?limit=50&offset=0
Query Parameters:
- limit: Number of events to return (default: 50)
- offset: Number of events to skip (default: 0)
- severity: Filter by severity (info, warning, error, critical)
- category: Filter by category (utilization, health, production, etc.)
Get Event Wall Data
GET /api/event-wall-data?hours=1&layout=template
Query Parameters:
- hours: Time range in hours (default: 1)
- layout: Layout mode (template, category, timeline)
AI Provider API
Get AI Providers
GET /api/ai-providers
Response:
{
"success": true,
"data": [
{
"id": 1,
"display_name": "OpenAI GPT-4",
"provider_type": "openai",
"model_name": "gpt-4",
"usage_mode": "assistant",
"is_active": true,
"supports_function_calling": true,
"function_calling_enabled": true
}
]
}
Create AI Provider
POST /api/ai-providers
Request Body:
{
"display_name": "Claude Sonnet",
"provider_type": "anthropic",
"model_name": "claude-3-sonnet-20240229",
"api_key": "your_api_key",
"usage_mode": "assistant",
"system_instructions": "You are an industrial AI assistant...",
"assistant_type_id": 1
}
Update AI Provider
PUT /api/ai-providers/{provider_id}
Test AI Provider
POST /api/ai-providers/{provider_id}/test
Request Body:
{
"test_message": "Hello, can you help me analyze equipment data?"
}
Get Combined Instructions
GET /api/ai-providers/{provider_id}/instructions
Response:
{
"success": true,
"data": {
"assistant_type_instructions": "Base investigation instructions...",
"provider_specific_instructions": "Provider-specific customizations...",
"combined_instructions": "Full combined instructions..."
}
}
AI Conversation API
Start Conversation
POST /api/ai-providers/{provider_id}/conversation
Request Body:
{
"message": "Analyze current equipment status",
"context_type": "events",
"time_filter": "24h",
"include_context": true
}
Response:
{
"success": true,
"data": {
"response": "Based on the current events...",
"session_id": "session_uuid",
"function_calls": [...],
"api_usage": {
"prompt_tokens": 1500,
"completion_tokens": 800,
"total_tokens": 2300
}
}
}
Get Conversation Logs
GET /api/conversation-logs/{provider_id}
Response:
{
"success": true,
"data": {
"logs": [
{
"timestamp": "2025-08-10T13:16:04",
"type": "user",
"content": "Analyze equipment status",
"session_id": "session_uuid"
}
]
}
}
Get Function Call Logs
GET /api/function-call-logs/{provider_id}
Get API Usage Stats
GET /api/api-usage-logs/{provider_id}
Get Raw Logs
GET /api/raw-logs/{provider_id}
Response:
{
"success": true,
"data": {
"logs": "[2025-08-10 13:16:04] INFO: Session started - UUID: session_uuid\n[2025-08-10 13:16:04] USER: Analyze equipment status...\n[2025-08-10 13:16:05] FUNCTION: get_context_data (150ms) - SUCCESS\n[2025-08-10 13:16:06] API: chat_completion (1200ms) (tokens: 2300) - SUCCESS\n[2025-08-10 13:16:06] ASSISTANT: Response generated (800 chars)"
}
}
Clear Conversation Logs
DELETE /api/conversation-logs/{provider_id}
Context Data API
Get Context Data
GET /api/context-data?context_type=events&time_filter=24h&max_items=50
Query Parameters:
- context_type: Data type (events, rules, assets, streams, plant_model)
- time_filter: Time range (1h, 24h, 7d, 30d)
- max_items: Maximum items to return
Response:
{
"success": true,
"data": {
"context_type": "events",
"data": {
"events": {
"active": 4,
"details": [...]
}
}
}
}
Plant Model API
Get Plant Model
GET /api/plant-model
Response:
{
"success": true,
"data": [
{
"id": "ENT-MIL",
"name": "Milan Enterprise",
"type": "enterprise",
"children": [...]
}
]
}
Create Plant Node
POST /api/plant-model
Request Body:
{
"floc_id": "ENT-MIL-ARE1-LIN03",
"name": "Production Line 03",
"node_type": "production_line",
"parent_id": "ENT-MIL-ARE1"
}
Assistant Types API
Get Assistant Types
GET /api/assistant-types
Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "Investigation",
"description": "AI assistant for technical investigation",
"base_instructions": "You are an expert industrial engineer...",
"is_active": true
}
]
}
Create Assistant Type
POST /api/assistant-types
Request Body:
{
"name": "Analysis Expert",
"description": "Specialized in data analysis",
"base_instructions": "You are a data analysis expert...",
"admin_password": "ipteam76"
}
Error Codes
HTTP Status Codes
200: Success400: Bad Request - Invalid request data401: Unauthorized - Authentication required403: Forbidden - Insufficient permissions404: Not Found - Resource not found500: Internal Server Error - Server-side error
Application Error Codes
API_CONFIG_MISSING: API configuration not foundINVALID_CREDENTIALS: Invalid API credentialsCONNECTION_FAILED: External API connection failedTEMPLATE_NOT_FOUND: Rule template not foundINSTANCE_DEPLOYMENT_FAILED: Template instance deployment failedAI_PROVIDER_ERROR: AI provider communication errorFUNCTION_CALL_FAILED: Function calling execution failed
Rate Limiting
API endpoints are subject to rate limiting: - Default: 100 requests per minute per IP - AI Endpoints: 20 requests per minute per provider - Heavy Operations: 10 requests per minute (asset discovery, bulk operations)
Pagination
List endpoints support pagination:
GET /api/endpoint?limit=20&offset=40
Response:
{
"success": true,
"data": [...],
"pagination": {
"limit": 20,
"offset": 40,
"total": 150,
"has_next": true,
"has_prev": true
}
}
WebSocket Events (Future)
Real-time updates will be available through WebSocket connections:
- event_created: New rule event generated
- event_updated: Event status changed
- stream_updated: Stream value changed
- ai_response: AI conversation response received