docs/api/KiroCloud REST API Referenz

KiroCloud REST API Referenz

KiroCloud REST API & SDK Dokumentation

Herzlich willkommen zur offiziellen KiroCloud REST API-Referenz für Entwickler und Bot-Betreiber. Diese Dokumentation bietet alle notwendigen Spezifikationen, Endpunkte und SDK-Beispiele, um KiroCloud in eigene Anwendungen, Überwachungs-Tools oder CI/CD-Pipelines zu integrieren.

!IMPORTANT Alle Anfragen an authentifizierte Endpunkte erfordern einen gültigen API-Schlüssel, der im HTTP-Header mitgesendet werden muss. Teile deinen API-Schlüssel niemals öffentlich (z. B. in GitHub-Repositories oder Client-seitigem Frontend-Code).


1. Authentifizierung

Um Anfragen an die API zu senden, übergibst du deinen API-Schlüssel im Authorization-Header als Bearer Token.

Header-Format

Authorization: Bearer kiro_sec_DEIN_API_SCHLUESSEL
Content-Type: application/json
Accept: application/json

API-Schlüssel können direkt im KiroCloud Dashboard unter den Entwickler-Einstellungen erstellt und mit spezifischen Berechtigungen (Scopes) versehen werden.


2. Fertige SDK-Wrapper für deine Projekte

Damit du nicht jeden HTTP-Request manuell implementieren musst, findest du hier produktionsreife Client-Klassen für Node.js / TypeScript, Python und Bash.

2.1 Node.js / TypeScript (Native Fetch API)

Optimiert für moderne Node.js-Umgebungen (ab v18) und Edge-Runtimes:

// kiroClient.ts
export interface BotStatusResponse {
  success: boolean;
  data: {
    id: string;
    name: string;
    status: 'online' | 'offline' | 'starting' | 'error';
    runtimeExpiresAt: string;
    uptimeSeconds: number;
  };
}

export class KiroClient {
  private baseUrl: string;
  private apiKey: string;

  constructor(apiKey: string, baseUrl = 'https://api.kirocloud.de/api/v1') {
    this.apiKey = apiKey;
    this.baseUrl = baseUrl;
  }

  private async request<T>(method: string, endpoint: string, body?: unknown): Promise<T> {
    const headers: Record<string, string> = {
      'Authorization': `Bearer ${this.apiKey}`,
      'Content-Type': 'application/json',
      'Accept': 'application/json',
    };

    const response = await fetch(`${this.baseUrl}${endpoint}`, {
      method,
      headers,
      body: body ? JSON.stringify(body) : undefined,
    });

    if (!response.ok) {
      const errorData = await response.json().catch(() => ({}));
      throw new Error(`KiroCloud API Error [${response.status}]: ${errorData.message || response.statusText}`);
    }

    return response.json() as Promise<T>;
  }

  // --- Public Status & Platform Health ---

  async getPlatformStatus() {
    return this.request<{ success: boolean; data: Record<string, unknown> }>('GET', '/public/status');
  }

  async getPlatformStats() {
    return this.request<{ success: boolean; data: { activeBots: number; activeServers: number; uptime: number } }>('GET', '/public/stats');
  }

  // --- Bot Management (Scope: bots:read, bots:write) ---

  async listBots() {
    return this.request<{ success: boolean; data: Array<{ id: string; name: string; status: string }> }>('GET', '/bots');
  }

  async getBot(botId: string) {
    return this.request<BotStatusResponse>('GET', `/bots/${botId}`);
  }

  async startBot(botId: string) {
    return this.request<{ success: boolean; message: string }>('POST', `/bots/${botId}/start`);
  }

  async stopBot(botId: string) {
    return this.request<{ success: boolean; message: string }>('POST', `/bots/${botId}/stop`);
  }

  async restartBot(botId: string) {
    return this.request<{ success: boolean; message: string }>('POST', `/bots/${botId}/restart`);
  }

  async sendEmbed(botId: string, payload: { channelId: string; embed: Record<string, unknown> }) {
    return this.request<{ success: boolean; messageId: string }>('POST', `/bots/${botId}/send-embed`, payload);
  }

  // --- Support Tickets (Scope: tickets:read, tickets:write) ---

  async listTickets() {
    return this.request<{ success: boolean; data: Array<{ id: string; subject: string; status: string }> }>('GET', '/tickets');
  }

  async createTicket(payload: { subject: string; message: string; priority?: 'low' | 'normal' | 'high' }) {
    return this.request<{ success: boolean; ticketId: string }>('POST', '/tickets', payload);
  }
}

2.2 Python (Requests)

Für Python-basierte Bots, Automatisierungen oder CLI-Werkzeuge (pip install requests):

# kiro_client.py
import requests
from typing import Optional, Dict, Any, List

class KiroClient:
    def __init__(self, api_key: str, base_url: str = "https://api.kirocloud.de/api/v1"):
        self.api_key = api_key
        self.base_url = base_url
        self.headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
            "Accept": "application/json",
        }

    def _request(self, method: str, endpoint: str, data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
        url = f"{self.base_url}{endpoint}"
        resp = requests.request(method, url, headers=self.headers, json=data, timeout=10)
        if not resp.ok:
            raise Exception(f"KiroCloud API Error [{resp.status_code}]: {resp.text}")
        return resp.json()

    # --- System Status ---
    def get_status(self) -> Dict[str, Any]:
        return self._request("GET", "/public/status")

    def get_stats(self) -> Dict[str, Any]:
        return self._request("GET", "/public/stats")

    # --- Bots ---
    def list_bots(self) -> List[Dict[str, Any]]:
        return self._request("GET", "/bots").get("data", [])

    def get_bot(self, bot_id: str) -> Dict[str, Any]:
        return self._request("GET", f"/bots/{bot_id}")

    def restart_bot(self, bot_id: str) -> Dict[str, Any]:
        return self._request("POST", f"/bots/{bot_id}/restart")

    def send_embed(self, bot_id: str, channel_id: str, embed_data: Dict[str, Any]) -> Dict[str, Any]:
        return self._request("POST", f"/bots/{bot_id}/send-embed", {
            "channelId": channel_id,
            "embed": embed_data,
        })

2.3 Shell / cURL (CI/CD Automatisierung)

Für Deployment-Skripte oder automatisierte Neustarts nach GitHub Actions Builds:

#!/bin/bash
set -euo pipefail

API_KEY="kiro_sec_YOUR_API_KEY_HERE"
BASE_URL="https://api.kirocloud.de/api/v1"
BOT_ID="00000000-0000-0000-0000-000000000000"

echo "Checking platform health..."
curl -s -f -X GET "$BASE_URL/public/status" \
  -H "Accept: application/json" | jq .

echo "Restarting bot instance after deployment..."
curl -s -f -X POST "$BASE_URL/bots/$BOT_ID/restart" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" | jq .

3. Endpunkt-Spezifikation

3.1 Plattform-Status & Metriken (Öffentlich)

GET /api/v1/public/status

Liefert den aktuellen Betriebszustand aller KiroCloud-Komponenten (Discord Gateway Proxies, Rechenknoten, Datenbank).

  • Authentifizierung: Keine erforderlich
  • Antwort: 200 OK
{
  "success": true,
  "data": {
    "overall": "operational",
    "services": {
      "database": "operational",
      "botEngine": "operational",
      "minecraftNodes": "operational"
    },
    "timestamp": "2026-10-09T00:00:00.000Z"
  }
}

GET /api/v1/public/stats

Aggregierte Echtzeit-Statistiken über die Gesamtlaufzeit und aktive Instanzen.

  • Authentifizierung: Keine erforderlich

3.2 Bot-Steuerung & Instanz-Lifecycle

GET /api/v1/bots

Gibt alle Bots zurück, die dem authentifizierten Benutzer-Account zugeordnet sind.

  • Scope: bots:read
  • Antwort: Array von Bot-Metadaten (Name, Status, Laufzeitverfallsdatum).

GET /api/v1/bots/:id

Ruft detaillierte Laufzeitdaten und Systemmetriken einer spezifischen Bot-Instanz ab.

  • Scope: bots:read

POST /api/v1/bots/:id/start

Startet die isolierte Bot-Laufzeitumgebung in einer sicheren cgroups-Sandbox.

  • Scope: bots:write
  • Rückgabe: 200 OK bei erfolgreicher Initialisierung.

POST /api/v1/bots/:id/stop

Fährt den laufenden Node.js-Prozess des Bots kontrolliert über SIGTERM herunter.

  • Scope: bots:write

POST /api/v1/bots/:id/restart

Führt einen kontrollierten Neustart der Instanz aus. Ideal nach dem Aktualisieren von Bot-Modulen oder Umgebungsvariablen.

  • Scope: bots:write

POST /api/v1/bots/:id/send-embed

Sendet ein gestaltetes Discord-Embed über den authentifizierten Bot in einen Zielkanal.

  • Scope: bots:write
  • Payload:
{
  "channelId": "123456789012345678",
  "embed": {
    "title": "Wartungsarbeiten abgeschlossen",
    "description": "Alle Systeme laufen wieder mit voller Leistung.",
    "color": 3447003
  }
}

3.3 Support-Ticket API

GET /api/v1/tickets

Listet alle eigenen Support-Tickets inklusive aktuellem Bearbeitungsstatus auf.

  • Scope: tickets:read

POST /api/v1/tickets

Eröffnet ein neues Support-Ticket im KiroCloud Helpdesk.

  • Scope: tickets:write
  • Payload:
{
  "subject": "Frage zur Bot-Skalierung",
  "message": "Wie kann ich die Shard-Anzahl für meinen Bot dynamisch anpassen?",
  "priority": "normal"
}

4. HTTP-Statuscodes & Fehlerbehandlung

Die KiroCloud-API antwortet bei Fehlern stets mit standardisierten RFC-7807-konformen JSON-Objekten:

StatuscodeFehler-CodeUrsache & Empfohlene Maßnahme
401 UnauthorizedUNAUTHORIZEDDer API-Schlüssel fehlt, ist ungültig oder abgelaufen. Prüfe den Authorization: Bearer-Header.
403 ForbiddenFORBIDDEN_SCOPEDem Schlüssel fehlt die erforderliche Berechtigung (z. B. bots:write für Neustarts).
404 Not FoundNOT_FOUNDDie angefragte Ressource (Bot-ID oder Ticket) existiert nicht oder gehört einem anderen Account.
429 Too Many RequestsRATE_LIMITEDAnfragelimit erreicht. Implementiere einen exponentiellen Backoff (Retry-After-Header beachten).
500 Internal ErrorINTERNAL_ERRORVorübergehender Serverfehler. Bitte an den Support wenden oder nach 5 Sekunden erneut versuchen.
Luca Lichtenwald
Artikel verfasst vonGründer & Lead Cloud Architect

Luca Lichtenwald

Spezialisiert auf hochverfügbare Discord-Bot-Infrastrukturen, V8-Memory-Tuning und kryptografische Zero-Trust-Architekturen.

Cookie-Einstellungen

Wir verwenden Cookies, um deine Erfahrung zu verbessern und unsere Dienste optimal anzubieten. Du kannst deine Einstellungen jederzeit anpassen.

main/11f725c