Skip to main content

Introduction

The Management API provides programmatic control over switchAILocal’s configuration, monitoring, and intelligent systems. Use it to automate operations, build management dashboards, or integrate with DevOps tools.

Base URL

http://localhost:18080/v0/management
All management endpoints use the /v0/management prefix.

Authentication

Management endpoints require a secret key for authentication:
curl http://localhost:18080/v0/management/config \
  -H "X-Management-Key: your-secret-key"

Initialize Secret

On first run, initialize your management secret:
curl -X POST http://localhost:18080/v0/management/initialize \
  -H "Content-Type: application/json" \
  -d '{
    "password": "your-secure-password"
  }'
See Authentication for details.

Endpoint Categories

Configuration

Manage server configuration and settings
  • Get/update config.yaml
  • Manage API keys
  • Configure providers

Monitoring

Track usage and performance
  • Usage statistics
  • Provider health
  • Request logs

Intelligent Systems

Access advanced AI capabilities
  • Memory statistics
  • Steering rules
  • Hook status
  • Analytics

Provider Management

Control AI providers
  • Test connectivity
  • Discover models
  • Manage credentials

Quick Examples

Get Server Configuration

curl http://localhost:18080/v0/management/config \
  -H "X-Management-Key: your-secret-key"

Update Configuration

curl -X PUT http://localhost:18080/v0/management/config.yaml \
  -H "X-Management-Key: your-secret-key" \
  -H "Content-Type: application/yaml" \
  --data-binary @config.yaml

Get Usage Statistics

curl http://localhost:18080/v0/management/usage \
  -H "X-Management-Key: your-secret-key"

Test Provider

curl -X POST http://localhost:18080/v0/management/providers/test \
  -H "X-Management-Key: your-secret-key" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "geminicli",
    "model": "gemini-2.5-pro"
  }'

Setup Workflow

New installations can use the setup flow:

1. Check Setup Status

curl http://localhost:18080/v0/management/setup-status
Response:
{
  "initialized": false,
  "skipped": false,
  "allow_remote": false
}

2. Initialize or Skip

# Option A: Initialize with secret
curl -X POST http://localhost:18080/v0/management/initialize \
  -H "Content-Type: application/json" \
  -d '{"password": "secure-password"}'

# Option B: Skip setup (localhost-only access)
curl -X POST http://localhost:18080/v0/management/skip

3. Access Management Endpoints

After initialization, use the secret key:
curl http://localhost:18080/v0/management/config \
  -H "X-Management-Key: your-secret-key"

Localhost Bypass

When accessing from localhost and remote management is disabled:
config.yaml
remote_management:
  allow_remote: false  # Default
Management endpoints allow unauthenticated access from localhost for better UX.
Only enable allow_remote: true when you need external access. Always use strong secret keys for remote access.

Remote Access

To enable remote management:
config.yaml
remote_management:
  allow_remote: true
  secret_key: "<bcrypt-hashed-password>"  # Set via initialize endpoint
Or use environment variable:
export MANAGEMENT_PASSWORD="your-password"
./switchAILocal

Security Features

Rate Limiting

Failed authentication attempts trigger temporary IP bans:
  • Max failures: 5 attempts
  • Ban duration: 30 minutes
  • Scope: Per remote IP

CORS Disabled

Management endpoints disable CORS to prevent browser-based attacks.

Localhost Restriction

Optionally restrict management to localhost only:
config.yaml
ampcode:
  restrict_management_to_localhost: true

Response Format

All management endpoints return JSON:

Success Response

{
  "success": true,
  "data": { ... }
}

Error Response

{
  "error": "Invalid management key"
}

Common Headers

HeaderRequiredDescription
X-Management-KeyYesManagement secret key
Content-TypeVariesapplication/json or application/yaml
AuthorizationNoAlternative to X-Management-Key: Bearer <key>

Version Information

All responses include version headers:
X-CPA-VERSION: 1.0.0
X-CPA-COMMIT: abc123def
X-CPA-BUILD-DATE: 2026-03-09T10:00:00Z

Available Endpoints

Configuration Management

EndpointMethodDescription
/configGETGet JSON configuration
/config.yamlGETGet YAML configuration
/config.yamlPUTUpdate configuration
/debugGET/PUTGet/set debug mode
/logging-to-fileGET/PUTGet/set file logging
/usage-statistics-enabledGET/PUTGet/set usage tracking
/proxy-urlGET/PUT/DELETEManage proxy settings

Provider Management

EndpointMethodDescription
/providers/testPOSTTest provider connectivity
/providers/discover-modelsPOSTDiscover available models
/gemini-api-keyGET/PUT/PATCH/DELETEManage Gemini keys
/claude-api-keyGET/PUT/PATCH/DELETEManage Claude keys
/switchai-api-keyGET/PUT/PATCH/DELETEManage switchAI keys
/codex-api-keyGET/PUT/PATCH/DELETEManage Codex keys

Monitoring

EndpointMethodDescription
/usageGETUsage statistics
/metricsGETSuperbrain metrics
/logsGETServer logs
/request-error-logsGETError logs
/request-log-by-id/:idGETSpecific request log

Intelligent Systems

EndpointMethodDescription
/memory/statsGETMemory system statistics
/heartbeat/statusGETProvider health status
/steering/rulesGETLoaded steering rules
/steering/reloadPOSTReload steering rules
/hooks/statusGETHook execution status
/hooks/reloadPOSTReload hooks
/analyticsGETComputed analytics

Advanced

EndpointMethodDescription
/cache/metricsGETCache statistics
/cache/clearPOSTClear semantic cache
/state-box/statusGETState directory info
/latest-versionGETCheck for updates

Python Client Example

import requests

class ManagementClient:
    def __init__(self, base_url="http://localhost:18080", secret_key=None):
        self.base_url = base_url
        self.headers = {}
        if secret_key:
            self.headers["X-Management-Key"] = secret_key
    
    def get_config(self):
        response = requests.get(
            f"{self.base_url}/v0/management/config",
            headers=self.headers
        )
        response.raise_for_status()
        return response.json()
    
    def get_usage(self):
        response = requests.get(
            f"{self.base_url}/v0/management/usage",
            headers=self.headers
        )
        response.raise_for_status()
        return response.json()
    
    def test_provider(self, provider, model):
        response = requests.post(
            f"{self.base_url}/v0/management/providers/test",
            headers=self.headers,
            json={"provider": provider, "model": model}
        )
        response.raise_for_status()
        return response.json()

# Usage
client = ManagementClient(secret_key="your-secret-key")
config = client.get_config()
print(f"Debug mode: {config['debug']}")

usage = client.get_usage()
print(f"Total requests: {usage['total_requests']}")

JavaScript Client Example

class ManagementClient {
  constructor(baseURL = 'http://localhost:18080', secretKey = null) {
    this.baseURL = baseURL;
    this.headers = secretKey ? { 'X-Management-Key': secretKey } : {};
  }

  async getConfig() {
    const response = await fetch(
      `${this.baseURL}/v0/management/config`,
      { headers: this.headers }
    );
    if (!response.ok) throw new Error('Failed to get config');
    return response.json();
  }

  async getUsage() {
    const response = await fetch(
      `${this.baseURL}/v0/management/usage`,
      { headers: this.headers }
    );
    if (!response.ok) throw new Error('Failed to get usage');
    return response.json();
  }

  async testProvider(provider, model) {
    const response = await fetch(
      `${this.baseURL}/v0/management/providers/test`,
      {
        method: 'POST',
        headers: { ...this.headers, 'Content-Type': 'application/json' },
        body: JSON.stringify({ provider, model })
      }
    );
    if (!response.ok) throw new Error('Failed to test provider');
    return response.json();
  }
}

// Usage
const client = new ManagementClient(
  'http://localhost:18080',
  'your-secret-key'
);

const config = await client.getConfig();
console.log(`Debug mode: ${config.debug}`);

const usage = await client.getUsage();
console.log(`Total requests: ${usage.total_requests}`);

Next Steps