xiaozhi-esp32-server/main/manager-api/API_ENDPOINTS.md
2025-08-29 19:45:39 +05:30

19 KiB

Cheeko Server Manager API Endpoints

Base Configuration

# Set base URL and token variables
BASE_URL="http://localhost:8002/xiaozhi"
TOKEN="your-auth-token-here"

# For authenticated requests, add header: -H "token: $TOKEN"

Authentication & User Management

Login Controller

# Get captcha
curl -X GET "$BASE_URL/user/captcha"

# Send SMS verification code
curl -X POST "$BASE_URL/user/smsVerification" \
  -H "Content-Type: application/json" \
  -d '{"mobile": "1234567890"}'

# User login
curl -X POST "$BASE_URL/user/login" \
  -H "Content-Type: application/json" \
  -d '{"mobile": "1234567890", "password": "password123", "captcha": "captcha_code", "uuid": "captcha_uuid"}'

# User registration (now returns token like login)
curl -X POST "$BASE_URL/user/register" \
  -H "Content-Type: application/json" \
  -d '{"mobile": "1234567890", "password": "password123", "verificationCode": "123456"}'

# Get user info
curl -X GET "$BASE_URL/user/info" \
  -H "token: $TOKEN"

# Change password
curl -X PUT "$BASE_URL/user/change-password" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"oldPassword": "old_password", "newPassword": "new_password"}'

# Retrieve password (forgot password)
curl -X PUT "$BASE_URL/user/retrieve-password" \
  -H "Content-Type: application/json" \
  -d '{"mobile": "1234567890", "newPassword": "new_password", "verificationCode": "123456"}'

# Get public configuration
curl -X GET "$BASE_URL/user/pub-config"

Agent Management

Agent Controller

# Get user's agent list
curl -X GET "$BASE_URL/agent/list" \
  -H "token: $TOKEN"

# Get all agents (admin only)
curl -X GET "$BASE_URL/agent/all" \
  -H "token: $TOKEN"

# Get agent by ID
curl -X GET "$BASE_URL/agent/{id}" \
  -H "token: $TOKEN"

# Create new agent
curl -X POST "$BASE_URL/agent" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Agent Name",
    "prompt": "Agent prompt",
    "llm": "LLM model",
    "tts": "TTS model",
    "asr": "ASR model",
    "vad": "VAD model"
  }'

# Update agent memory by device ID
curl -X PUT "$BASE_URL/agent/saveMemory/{macAddress}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"memory": "updated memory content"}'

# Update agent
curl -X PUT "$BASE_URL/agent/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Agent Name",
    "prompt": "Updated prompt"
  }'

# Delete agent
curl -X DELETE "$BASE_URL/agent/{id}" \
  -H "token: $TOKEN"

# Get agent templates
curl -X GET "$BASE_URL/agent/template" \
  -H "token: $TOKEN"

# Update agent template
curl -X PUT "$BASE_URL/agent/template/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "agentName": "Updated Template Name",
    "systemPrompt": "Updated system prompt"
  }'

# Create agent template
curl -X POST "$BASE_URL/agent/template" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "agentName": "New Template",
    "systemPrompt": "System prompt for new template",
    "asrModelId": "ASR_FunASR",
    "vadModelId": "VAD_SileroVAD",
    "llmModelId": "LLM_ChatGLMLLM",
    "ttsModelId": "TTS_EdgeTTS"
  }'

# Get agent sessions
curl -X GET "$BASE_URL/agent/{id}/sessions" \
  -H "token: $TOKEN"

# Get agent chat history
curl -X GET "$BASE_URL/agent/{id}/chat-history/{sessionId}" \
  -H "token: $TOKEN"

# Get recent 50 chat messages for user
curl -X GET "$BASE_URL/agent/{id}/chat-history/user" \
  -H "token: $TOKEN"

# Get audio content by audio ID
curl -X GET "$BASE_URL/agent/{id}/chat-history/audio?audioId={audioId}" \
  -H "token: $TOKEN"

# Get audio download ID
curl -X POST "$BASE_URL/agent/audio/{audioId}" \
  -H "token: $TOKEN"

# Play audio
curl -X GET "$BASE_URL/agent/play/{uuid}" \
  -H "token: $TOKEN"

Agent Chat History Controller

# Upload chat history file
curl -X POST "$BASE_URL/agent/chat-history/report" \
  -H "token: $TOKEN" \
  -F "file=@/path/to/chat_history.json" \
  -F "deviceId=device123"

Agent MCP Access Point Controller

# Get agent MCP access address
curl -X GET "$BASE_URL/agent/mcp/address/{agentId}" \
  -H "token: $TOKEN"

# Get agent MCP tools list
curl -X GET "$BASE_URL/agent/mcp/tools/{agentId}" \
  -H "token: $TOKEN"

Agent Voice Print Controller

# Create voice print
curl -X POST "$BASE_URL/agent/voice-print" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "agentId": 1,
    "name": "Voice Print Name",
    "voiceData": "base64_encoded_voice_data"
  }'

# Update voice print
curl -X PUT "$BASE_URL/agent/voice-print" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "name": "Updated Voice Print",
    "voiceData": "updated_base64_voice_data"
  }'

# Delete voice print
curl -X DELETE "$BASE_URL/agent/voice-print/{id}" \
  -H "token: $TOKEN"

# Get voice prints for agent
curl -X GET "$BASE_URL/agent/voice-print/list/{agentId}" \
  -H "token: $TOKEN"

Device Management

Device Controller

# Bind device to agent
curl -X POST "$BASE_URL/device/bind/{agentId}/{deviceCode}" \
  -H "token: $TOKEN"

# Register device
curl -X POST "$BASE_URL/device/register" \
  -H "Content-Type: application/json" \
  -d '{
    "deviceId": "device123",
    "type": "ESP32",
    "firmwareVersion": "1.0.0"
  }'

# Get user's bound devices
curl -X GET "$BASE_URL/device/bind/{agentId}" \
  -H "token: $TOKEN"

# Unbind device
curl -X POST "$BASE_URL/device/unbind" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"deviceId": "device123", "agentId": 1}'

# Update device info
curl -X PUT "$BASE_URL/device/update/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "New Device Name", "description": "Updated description"}'

# Manually add device
curl -X POST "$BASE_URL/device/manual-add" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "deviceId": "manual_device_123",
    "name": "Manual Device",
    "type": "ESP32"
  }'

OTA Controller

# Check OTA version and activation status
curl -X POST "$BASE_URL/ota/" \
  -H "Content-Type: application/json" \
  -d '{
    "deviceId": "device123",
    "currentVersion": "1.0.0",
    "type": "ESP32"
  }'

# Quick check device activation status
curl -X POST "$BASE_URL/ota/activate" \
  -H "Content-Type: application/json" \
  -d '{"deviceId": "device123"}'

# Get OTA status info
curl -X GET "$BASE_URL/ota/"

OTA Management Controller

# Get OTA firmware list (paginated)
curl -X GET "$BASE_URL/otaMag?page=1&limit=10" \
  -H "token: $TOKEN"

# Get OTA firmware by ID
curl -X GET "$BASE_URL/otaMag/{id}" \
  -H "token: $TOKEN"

# Save new OTA firmware info
curl -X POST "$BASE_URL/otaMag" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "2.0.0",
    "type": "ESP32",
    "description": "New firmware version",
    "url": "http://example.com/firmware.bin"
  }'

# Delete OTA firmware
curl -X DELETE "$BASE_URL/otaMag/{id}" \
  -H "token: $TOKEN"

# Update OTA firmware info
curl -X PUT "$BASE_URL/otaMag/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "2.0.1",
    "description": "Updated firmware"
  }'

# Get firmware download URL
curl -X GET "$BASE_URL/otaMag/getDownloadUrl/{id}" \
  -H "token: $TOKEN"

# Download firmware file
curl -X GET "$BASE_URL/otaMag/download/{uuid}" \
  -o firmware.bin

# Upload firmware file
curl -X POST "$BASE_URL/otaMag/upload" \
  -H "token: $TOKEN" \
  -F "file=@/path/to/firmware.bin" \
  -F "version=2.0.0" \
  -F "type=ESP32"

Model Management

Model Controller

# Get all model names
curl -X GET "$BASE_URL/models/names" \
  -H "token: $TOKEN"

# Get LLM model codes
curl -X GET "$BASE_URL/models/llm/names" \
  -H "token: $TOKEN"

# Get model providers for type
curl -X GET "$BASE_URL/models/{modelType}/provideTypes" \
  -H "token: $TOKEN"

# Get model configuration list
curl -X GET "$BASE_URL/models/list" \
  -H "token: $TOKEN"

# Add model configuration
curl -X POST "$BASE_URL/models/{modelType}/{provideCode}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Model Name",
    "apiKey": "api_key_here",
    "config": {"temperature": 0.7}
  }'

# Edit model configuration
curl -X PUT "$BASE_URL/models/{modelType}/{provideCode}/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Model",
    "config": {"temperature": 0.8}
  }'

# Delete model configuration
curl -X DELETE "$BASE_URL/models/{id}" \
  -H "token: $TOKEN"

# Get model configuration
curl -X GET "$BASE_URL/models/{id}" \
  -H "token: $TOKEN"

# Enable/disable model
curl -X PUT "$BASE_URL/models/enable/{id}/{status}" \
  -H "token: $TOKEN"

# Set default model
curl -X PUT "$BASE_URL/models/default/{id}" \
  -H "token: $TOKEN"

# Get model voices
curl -X GET "$BASE_URL/models/{modelId}/voices" \
  -H "token: $TOKEN"

Model Provider Controller

# Get model providers (paginated)
curl -X GET "$BASE_URL/models/provider?page=1&limit=10" \
  -H "token: $TOKEN"

# Add model provider
curl -X POST "$BASE_URL/models/provider" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Provider Name",
    "code": "provider_code",
    "type": "LLM"
  }'

# Edit model provider
curl -X PUT "$BASE_URL/models/provider" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "name": "Updated Provider"
  }'

# Delete model provider
curl -X POST "$BASE_URL/models/provider/delete" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": [1, 2, 3]}'

# Get plugin names
curl -X GET "$BASE_URL/models/provider/plugin/names" \
  -H "token: $TOKEN"

Configuration

Config Controller

# Get server configuration
curl -X POST "$BASE_URL/config/server-base" \
  -H "Content-Type: application/json" \
  -d '{"deviceId": "device123"}'

# Get agent models
curl -X POST "$BASE_URL/config/agent-models" \
  -H "Content-Type: application/json" \
  -d '{"agentId": 1}'

TTS Voice/Timbre Management

Timbre Controller

# Get timbre list (paginated)
curl -X GET "$BASE_URL/ttsVoice?page=1&limit=10" \
  -H "token: $TOKEN"

# Save new timbre
curl -X POST "$BASE_URL/ttsVoice" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Voice Name",
    "voiceId": "voice_123",
    "provider": "elevenlabs"
  }'

# Update timbre
curl -X PUT "$BASE_URL/ttsVoice/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Voice Name"
  }'

# Delete timbre
curl -X POST "$BASE_URL/ttsVoice/delete" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": [1, 2, 3]}'

Admin Functions

Admin Controller

# Get users (paginated)
curl -X GET "$BASE_URL/admin/users?page=1&limit=10" \
  -H "token: $TOKEN"

# Reset user password
curl -X PUT "$BASE_URL/admin/users/{id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"password": "new_password"}'

# Delete user
curl -X DELETE "$BASE_URL/admin/users/{id}" \
  -H "token: $TOKEN"

# Batch change user status
curl -X PUT "$BASE_URL/admin/users/changeStatus/{status}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"userIds": [1, 2, 3]}'

# Get all devices (paginated)
curl -X GET "$BASE_URL/admin/device/all?page=1&limit=10" \
  -H "token: $TOKEN"

Server Side Management Controller

# Get WebSocket server list
curl -X GET "$BASE_URL/admin/server/server-list" \
  -H "token: $TOKEN"

# Notify Python server to update config
curl -X POST "$BASE_URL/admin/server/emit-action" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "UPDATE_CONFIG",
    "payload": {"config": "value"}
  }'

System Dictionary Data Controller

# Get dictionary data (paginated)
curl -X GET "$BASE_URL/admin/dict/data/page?page=1&limit=10" \
  -H "token: $TOKEN"

# Get dictionary data by ID
curl -X GET "$BASE_URL/admin/dict/data/{id}" \
  -H "token: $TOKEN"

# Save dictionary data
curl -X POST "$BASE_URL/admin/dict/data/save" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "dictType": "status",
    "dictLabel": "Active",
    "dictValue": "1"
  }'

# Update dictionary data
curl -X PUT "$BASE_URL/admin/dict/data/update" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "dictLabel": "Updated Label"
  }'

# Delete dictionary data
curl -X POST "$BASE_URL/admin/dict/data/delete" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": [1, 2, 3]}'

# Get dictionary data by type
curl -X GET "$BASE_URL/admin/dict/data/type/{dictType}" \
  -H "token: $TOKEN"

System Dictionary Type Controller

# Get dictionary types (paginated)
curl -X GET "$BASE_URL/admin/dict/type/page?page=1&limit=10" \
  -H "token: $TOKEN"

# Get dictionary type by ID
curl -X GET "$BASE_URL/admin/dict/type/{id}" \
  -H "token: $TOKEN"

# Save dictionary type
curl -X POST "$BASE_URL/admin/dict/type/save" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "dictType": "new_type",
    "dictName": "New Type Name"
  }'

# Update dictionary type
curl -X PUT "$BASE_URL/admin/dict/type/update" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "dictName": "Updated Type Name"
  }'

# Delete dictionary type
curl -X POST "$BASE_URL/admin/dict/type/delete" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": [1, 2, 3]}'

System Parameters Controller

# Get system parameters (paginated)
curl -X GET "$BASE_URL/admin/params/page?page=1&limit=10" \
  -H "token: $TOKEN"

# Get parameter by ID
curl -X GET "$BASE_URL/admin/params/{id}" \
  -H "token: $TOKEN"

# Save parameter
curl -X POST "$BASE_URL/admin/params" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "paramCode": "param_code",
    "paramValue": "param_value"
  }'

# Update parameter
curl -X PUT "$BASE_URL/admin/params" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 1,
    "paramValue": "updated_value"
  }'

# Delete parameter
curl -X POST "$BASE_URL/admin/params/delete" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ids": [1, 2, 3]}'

Mobile Parent Profile Management

Mobile Parent Profile Controller

# Get parent profile
curl -X GET "$BASE_URL/api/mobile/profile" \
  -H "token: $TOKEN"

# Create parent profile
curl -X POST "$BASE_URL/api/mobile/profile/create" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fullName": "John Doe",
    "email": "john@example.com",
    "phoneNumber": "+1234567890",
    "preferredLanguage": "en",
    "timezone": "UTC",
    "notificationPreferences": "{\"push\":true,\"email\":true,\"daily_summary\":true}",
    "onboardingCompleted": false
  }'

# Update parent profile
curl -X PUT "$BASE_URL/api/mobile/profile/update" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fullName": "John Smith",
    "phoneNumber": "+1234567891"
  }'

# Accept terms and privacy policy
curl -X POST "$BASE_URL/api/mobile/profile/accept-terms" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "termsAccepted": true,
    "privacyAccepted": true
  }'

# Complete onboarding
curl -X POST "$BASE_URL/api/mobile/profile/complete-onboarding" \
  -H "token: $TOKEN"

# Delete parent profile
curl -X DELETE "$BASE_URL/api/mobile/profile" \
  -H "token: $TOKEN"

Notes

  1. Replace {id}, {agentId}, {deviceCode}, etc. with actual values
  2. Most endpoints require authentication via the token header
  3. The base URL assumes the application is running on http://localhost:8002/xiaozhi
  4. Adjust the JSON payloads according to your specific requirements
  5. For file uploads, replace /path/to/file with actual file paths
  6. Pagination parameters typically include page and limit query parameters
  7. Admin endpoints require admin privileges
  8. Mobile parent profile endpoints are designed for the Flutter mobile app integration

Content Library Management

Content Library Controller

# Get paginated content list with filters
curl -X GET "$BASE_URL/content/library?page=1&limit=20&contentType=music&category=English" \
  -H "token: $TOKEN"

# Search content across titles and alternatives
curl -X GET "$BASE_URL/content/library/search?query=baby%20shark&contentType=music&page=1&limit=20" \
  -H "token: $TOKEN"

# Get available categories by content type
curl -X GET "$BASE_URL/content/library/categories?contentType=music" \
  -H "token: $TOKEN"

# Get available story categories
curl -X GET "$BASE_URL/content/library/categories?contentType=story" \
  -H "token: $TOKEN"

# Get content by ID
curl -X GET "$BASE_URL/content/library/{content_id}" \
  -H "token: $TOKEN"

# Get content statistics
curl -X GET "$BASE_URL/content/library/statistics" \
  -H "token: $TOKEN"

# Add new content (admin only)
curl -X POST "$BASE_URL/content/library" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "New Song Title",
    "romanized": "New Song Title",
    "filename": "new_song.mp3",
    "contentType": "music",
    "category": "English",
    "alternatives": ["new song", "song title"],
    "awsS3Url": "https://s3.amazonaws.com/bucket/new_song.mp3",
    "durationSeconds": 180,
    "fileSizeBytes": 3145728
  }'

# Update existing content
curl -X PUT "$BASE_URL/content/library/{content_id}" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Updated Title",
    "category": "Hindi"
  }'

# Delete content (soft delete - sets inactive)
curl -X DELETE "$BASE_URL/content/library/{content_id}" \
  -H "token: $TOKEN"

# Batch insert content (for migration)
curl -X POST "$BASE_URL/content/library/batch" \
  -H "token: $TOKEN" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "title": "Song 1",
      "filename": "song1.mp3",
      "contentType": "music",
      "category": "English"
    },
    {
      "title": "Story 1",
      "filename": "story1.mp3",
      "contentType": "story",
      "category": "Adventure"
    }
  ]'

# Sync content from metadata files
curl -X POST "$BASE_URL/content/library/sync" \
  -H "token: $TOKEN"

Testing Authentication Flow

# 1. Get captcha
CAPTCHA_RESPONSE=$(curl -s -X GET "$BASE_URL/user/captcha")
echo $CAPTCHA_RESPONSE

# 2. Login (extract token from response)
LOGIN_RESPONSE=$(curl -s -X POST "$BASE_URL/user/login" \
  -H "Content-Type: application/json" \
  -d '{"mobile": "your_mobile", "password": "your_password"}')
TOKEN=$(echo $LOGIN_RESPONSE | jq -r '.data.token')
echo "Token: $TOKEN"

# 3. Use token for authenticated requests
curl -X GET "$BASE_URL/user/info" \
  -H "token: $TOKEN"