API-DOKUMENTATION

Einführung

Willkommen zur Dokumentation der NOSGPU-API. Diese Dokumentation bietet Entwicklern einen umfassenden Leitfaden zur Integration unserer Plattform. Über unsere API können Entwickler NOSGPU-Funktionen nahtlos in ihre Anwendungen integrieren.

Erste Schritte

Um unsere API zu nutzen, solltest du dich mit den Endpunkten und Authentifizierungsmechanismen vertraut machen. Hier findest du die wichtigsten Informationen für den Einstieg:

  • Basis-URL der Sandbox-API: https://api.nosgpu.ch/sandbox/v1
  • Basis-URL der Produktions-API: https://api.nosgpu.ch/v1

Die Beispiele verwenden die Produktions-API. Ersetze für die Sandbox die Produktions-Basis-URL durch die Sandbox-Basis-URL.

Authentifizierung

Für den Zugriff auf die NOSGPU-API ist eine Authentifizierung per API-Schlüssel erforderlich. So erhältst du deinen API-Schlüssel:

  1. Melde dich an und öffne den API-Bereich. Du findest ihn hier:/dashboard/api.
  2. Klicke auf „Neuer API-Schlüssel“.
  3. Gib einen Namen für deinen API-Schlüssel ein und bestätige.
  4. Wir empfehlen dringend, deinen API-Schlüssel durch eine IP-Zulassungsliste zu schützen. Dadurch wird die Nutzung auf die angegebenen IP-Adressen beschränkt und die Sicherheit erhöht.
  5. Nach Erhalt kannst du den API-Schlüssel bei jeder API-Anfrage als Bearer-Token im Authorization-Header der HTTPS-Anfrage hinzufügen.

API-Anfragen müssen von Server zu Server erfolgen. Die Nutzung der API im Frontend kann deinen API-Schlüssel öffentlich offenlegen.

SSH-Schlüssel: Einrichtung auf der Website

Öffentliche SSH-Schlüssel können nur über die Website hinzugefügt werden, nicht über die öffentliche API. Registriere deinen Schlüssel, bevor du eine Instanz über die API erstellst.

  1. Melde dich mit dem Konto an, dem dein API-Schlüssel gehört, und öffne Dashboard / Konto / SSH-Schlüssel.
  2. Klicke auf „NEUEN SCHLÜSSEL HINZUFÜGEN“, gib einen Namen ein und füge den Inhalt deines öffentlichen SSH-Schlüssels (.pub-Datei) in „Öffentlicher Schlüssel“ ein. Verwende ausschließlich den öffentlichen Schlüssel, niemals deinen privaten Schlüssel.
  3. Klicke auf „SCHLÜSSEL HINZUFÜGEN“. Kopiere nach dem Speichern die Zahl in der Spalte „ID“ der SSH-Schlüsselliste.
  4. Verwende diese Zahl als ssh_key_id in der Anfrage zur Instanzerstellung. Die API erwartet die ID des gespeicherten Schlüssels, nicht seinen Namen oder den Text des öffentlichen Schlüssels.

Kontoguthaben

Aktuelles Wallet-Guthaben und Währung abrufen.


const API_KEY = 'YOUR_BEARER_API_KEY';
const URL = 'https://api.nosgpu.ch/v1/account/balance';

fetch(URL, {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    }
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Balance:', data.balance);
    console.log('Currency:', data.currency);
})
.catch((error) => {
    console.error('Error fetching balance:', error.message);
});

Anfrage

Methode:

GET

API-URL: https://api.nosgpu.ch/v1/account/balance

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: optional – application/json

Antwort

Statuscode: 200

Erfolgreiche Antwort

            
{
  // current user balance
  "balance": number,

  "currency": {
    // currency code
    "code": 'USD'|'EUR'|'GBP'|'CHF',
    // currency symbol
    "symbol": '$'|'€'|'£'|'CHF'|null
  }
}

          
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Instanzkatalog

Diese API liefert alle mietbaren Instanzpakete nach Kategorie, einschließlich Verfügbarkeit, Hardwareressourcen, Betriebssystemen, Vorlagen und Preisen.


const API_KEY = 'YOUR_BEARER_API_KEY';
const URL = 'https://api.nosgpu.ch/v1/catalog/packages';

fetch(URL, {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    }
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Categories:', data.categories);
    console.log('Currency:', data.currency);
})
.catch((error) => {
    console.error('Error fetching catalog packages:', error.message);
});

Anfrage

Methode:

GET

API-URL: https://api.nosgpu.ch/v1/catalog/packages

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: optional – application/json

Antwort

Statuscode: 200

Erfolgreiche Antwort

            
{
  "categories": {
    "vm_gpu_dedicated": {
      "packages": [
        {
          // package id
          "id": number,
          "availability": {
            // 1 if package is available, 0 otherwise
            "available": 0|1,
            // availability reason if not available
            "reason": string|null
          },
          "cpu": {
            // cpu brand
            "brand": string|null,
            // cpu model name
            "name": string|null,
            // number of cpu cores
            "cores": number|null
          },
          "ram": {
            // ram quantity
            "quantity": string|null,
            // ram unit
            "unit": 'GB'
          },
          "disk": {
            // disk type
            "type": string|null,
            // disk quantity
            "quantity": number|null,
            // disk unit
            "unit": 'GB'
          },
          "gpu": {
            // gpu brand
            "brand": string|null,
            // gpu model name
            "name": string|null,
            // gpu vram quantity
            "vram_quantity": string|null,
            // gpu vram unit
            "vram_unit": 'GB',
            // dedicated gpu quantity for dedicated packages
            "quantity"?: number,
            // shared gpu slice quantity for shared packages
            "slice_quantity"?: number,
            // total slice quantity available on source gpu
            "slice_quantity_of"?: number|null,
            // source gpu total vram quantity for shared packages
            "vram_quantity_of"?: string|null
          },
          "os": [
            {
              // operating system brand
              "brand": string,
              // operating system version
              "version": string,
              "templates": [
                {
                  // image id used when creating an instance
                  "image_id": number,
                  // template name
                  "name": string
                }
              ]
            }
          ],
          // package tag
          "tag": string,
          "price": {
            // billing unit
            "unit": 'h'|'m',
            // billing amount
            "amount": number
          }
        }
      ]
    },
    "vm_gpu_shared": {
      "packages": array
    },
    "bare_metal": {
      "packages": array
    },
    "cold_storage": {
      "packages": array
    },
    "ai_storage": {
      "packages": array
    }
  },
  "currency": {
    // account currency code
    "code": 'EUR'|'CHF'|'USD',
    // currency symbol
    "symbol": string|null
  }
}

          
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Instanz mieten

Diese API erstellt eine neue GPU-Instanz mit dem gewählten Paket, Image und SSH-Schlüssel.


const API_KEY = 'YOUR_BEARER_API_KEY';
const URL = 'https://api.nosgpu.ch/v1/instances/create';

fetch(URL, {
    method: 'POST',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        package_id: 1, // API GET https://api.nosgpu.ch/v1/catalog/packages: categories[category].packages[].id
        image_id: 1, // API GET https://api.nosgpu.ch/v1/catalog/packages: categories[category].packages[].os[].templates[].image_id (selected package)
        ssh_key_id: 1 // Website only: add your public key at https://www.nosgpu.ch/dashboard/account/ssh-key and copy its ID
    })
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    // Success
    console.log('Instance created:', data.instance);
    console.log('My updated wallet balance:', data.wallet);
})
.catch((error) => {
    console.error('Error during creation:', error.message);
});

Anfrage

Methode:

POST

API-URL: https://api.nosgpu.ch/v1/instances/create

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: erforderlich – application/json

Body:

package_id: erforderlich – Paket-ID aus der JSON-Antwort auf GET https://api.nosgpu.ch/v1/catalog/packages: categories[category].packages[].id.

image_id: erforderlich – ID der Betriebssystemvorlage aus derselben Katalogantwort: categories[category].packages[].os[].templates[].image_id. Wähle eine Vorlage, die zum gewählten Paket gehört.

ssh_key_id: erforderlich – ID des gespeicherten SSH-Schlüssels von der Website-Seite SSH-Schlüssel. Füge dort zuerst den öffentlichen Schlüssel hinzu und kopiere dann seine ID wie beschrieben unter SSH-Schlüssel: Einrichtung auf der Website.

Hier ist category ein Kategoriename aus der Antwort (z. B. vm_gpu_dedicated), und [] bezeichnet ein Array-Element. Dies sind Pfade innerhalb der JSON-Antwort, keine URLs. Der Wert 1 in den Beispielen dient als Platzhalter für die jeweilige ID.

Antwort

Statuscode: 200

Erfolgreiche Antwort

              
  {
    "instance": {
      // your account id  
      "user_id": number,
      // package id
      "package_id": number,
      // hypervisor id
      "hypervisor_id": number,
      // template id
      "image_id": number,
      // instance type id
      "type": number,
      // instance status code
      "status": 'provisioning'|'running'|'stopped'|'error'|'deleting'|'deleted'|'expired',
      // UTC date time
      "updated_at": string,
      // UTC date time
      "created_at": string,
      // instance id
      "id": number,
      // instance name
      "name": string
    },
    "wallet": {
      // your credit after instance creation
      "balance": number,
      "currency": {
        // account/user currency code 
        "code": 'EUR'|'CHF'|'USD',
        // currency symbol if available
        "symbol": string|null
      }
    }
  }

            
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Statuscode: 402

Zahlung erforderlich– Unzureichendes Wallet-Guthaben oder Credits

Statuscode: 422

Validierungsfehler– Ungültige Parameter im Anfrage-Body

Meine Instanzen auflisten

Diese API liefert die paginierte Instanzliste des authentifizierten Benutzers mit Filtern für Kategorie, Status und Zeitraum sowie Daten zur Kostenüberwachung.


const API_KEY = 'YOUR_BEARER_API_KEY';
const LIMIT = 5;
const SKIP = 0;
const URL = 'https://api.nosgpu.ch/v1/instances/list/' + LIMIT + '/' + SKIP;

fetch(URL, {
    method: 'POST',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        category: 'all',
        status: 'active',
        date_from: '2026-02-24',
        date_to: '2026-06-05'
    })
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Instances:', data.instances);
    console.log('Total:', data.tot);
    console.log('Currency:', data.currency);
})
.catch((error) => {
    console.error('Error fetching instances list:', error.message);
});

Anfrage

Methode:

POST

API-URL: https://api.nosgpu.ch/v1/instances/list/{limit}/{skip}

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: erforderlich – application/json

Pfadparameter:

limit: erforderlich – maximale Anzahl zurückzugebender Instanzen

skip: erforderlich – Anzahl zu überspringender Datensätze für die Paginierung

Body:

category: erforderlich – Kategoriefilter, all, vm_gpu_shared, vm_gpu_dedicated, bare_metal, ai_storage, cold_storage, all_storage, all_vm

status: erforderlich – Statusfilter, active, all, stopped, running, delete

date_from: optional – Startdatumfilter im Format YYYY-MM-DD

date_to: optional – Enddatumfilter im Format YYYY-MM-DD

Antwort

Statuscode: 200

Erfolgreiche Antwort

              
{
  "instances": [
    {
      // instance id
      "id": number,
      // generated instance name
      "name": string,
      // instance type id
      "type": number,
      // instance category
      "category": 'vm_gpu_dedicated'|'vm_gpu_shared'|'bare_metal'|'cold_storage'|'ai_storage',
      // current instance status
      "status": 'provisioning'|'running'|'starting'|'stopped'|'stopping'|'rebooting'|'error'|'deleting'|'deleted'|'expired',
      // total accumulated cost
      "total_cost": number,
      // partial cost in selected filter range
      "partial_cost": number,
      "price": {
        // billing unit
        "unit": string,
        // price amount for billing unit
        "amount": number
      }
    }
  ],
  // total number of instances matching current filters
  "tot": number,
  "currency": {
    // account currency code
    "code": 'EUR'|'CHF'|'USD',
    // currency symbol
    "symbol": string|null
  }
}

            
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Statuscode: 422

Validierungsfehler– Ungültige Filter oder Paginierungsparameter

Instanzdetails

Diese API liefert vollständige Details zu einer bestimmten GPU-Instanz, einschließlich Status, Abrechnung, Paketressourcen, Netzwerkzugriff und Authentifizierungsinformationen.


const API_KEY = 'YOUR_BEARER_API_KEY';
const INSTANCE_ID = 1;
const URL = 'https://api.nosgpu.ch/v1/instances/' + INSTANCE_ID + '/details';

fetch(URL, {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    }
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Instance details:', data.instance);
    console.log('Currency:', data.currency);
})
.catch((error) => {
    console.error('Error fetching instance details:', error.message);
});

Anfrage

Methode:

GET

API-URL: https://api.nosgpu.ch/v1/instances/{instance_id}/details

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: optional – application/json

Pfadparameter:

instance_id: erforderlich – Instanz-ID

Antwort

Statuscode: 200

Erfolgreiche Antwort

              
    {
      "instance": {
        // instance id
        "id": number,
        // instance name
        "name": string,
        // instance type id
        "type": number,
        // category label
        "category": 'vm_gpu_dedicated'|'vm_gpu_shared'|'bare_metal'|'cold_storage'|'ai_storage',
        // instance status code
        "status": 'provisioning'|'running'|'starting'|'stopped'|'stopping'|'rebooting'|'error'|'deleting'|'deleted'|'expired',
        // current task state if available
        "task_state": string,
        // UTC date time when instance started
        "started_at": string|null,
        "price": {
          // billing unit
          "unit": string,
          // amount for billing unit
          "amount": number
        },
        // accumulated total instance cost
        "total_cost": number,
        "address": {
          // public ip address
          "public_ip": string,
          // exposed service interface port if available
          "interface_port": string|null
        },
        "auth": {
          // auth method
          "type": 'ssh',
          "value": {
            // SSH public key content
            "public_key": string,
            // SSH key id
            "id": number|null,
            // SSH key name
            "name": string|null
          },
          // default ssh username if available
          "username": string|null
        },
        "billing": [
          {
            // negative or positive billing amount
            "amount": number,
            // UTC date time of billing record
            "created_at": string
          }
        ],
        "metrics": {
          // current metrics snapshot
          "current": object|null,
          // metrics history list
          "history": array
        },
        "package": {
          // package id snapshot
          "id": number,
          "cpu": {
            "brand": string,
            "name": string,
            "cores": number
          },
          "ram": {
            "quantity": string,
            "unit": 'GB'
          },
          "disk": {
            "type": string,
            "quantity": number,
            "unit": 'GB'
          },
          "gpu": {
            "brand": string,
            "name": string,
            "vram_quantity": string,
            "vram_unit": 'GB',
            "slice_quantity": number,
            "slice_quantity_of": number|null,
            "vram_quantity_of": number|null
          },
          "os": {
            "brand": string,
            "version": string,
            "template": {
              "image_id": number,
              "name": string
            }
          },
          "tag": string
        }
      },
      "currency": {
        // account/user currency code
        "code": 'EUR'|'CHF'|'USD',
        // currency symbol if available
        "symbol": string|null
      }
    }
    
            
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Statuscode: 404

Nicht gefunden– Instanz nicht gefunden

Instanzaktionen

Diese API führt eine Aktion auf einer bestimmten Instanz aus. Unterstützte Aktionen sind start, stop und reboot.


const API_KEY = 'YOUR_BEARER_API_KEY';
const INSTANCE_ID = 1;
const ACTION = 'start'; // start | stop | reboot
const URL = 'https://api.nosgpu.ch/v1/instances/' + INSTANCE_ID + '/' + ACTION;

fetch(URL, {
    method: 'PATCH',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    }
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Instance action result:', data.instance);
})
.catch((error) => {
    console.error('Error executing instance action:', error.message);
});

Anfrage

Methode:

PATCH

API-URL: https://api.nosgpu.ch/v1/instances/{instance_id}/{action}

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: optional – application/json

Pfadparameter:

instance_id: erforderlich – Instanz-ID

action: erforderlich – unterstützte Werte sind start, stopund reboot

Antwort

Statuscode: 200

Erfolgreiche Antwort

      
{
  "instance": {
    // instance id
    "id": number,
    // generated instance name
    "name": string,
    // instance category/type label
    "type": 'vm_gpu_dedicated'|'vm_gpu_shared'|'bare_metal'|'cold_storage'|'ai_storage',
    // current instance status after action
    "status": 'provisioning'|'running'|'starting'|'stopped'|'stopping'|'rebooting'|'error'|'deleting'|'deleted'|'expired',
    // instance start datetime in UTC if available
    "started_at": string|null
  }
}

    
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Statuscode: 404

Nicht gefunden– Instanz nicht gefunden

Statuscode: 409

Konflikt– Die Instanz ist für diese Aktion nicht bereit

Instanz löschen

Diese API löscht eine bestimmte Instanz und gibt ihren aktualisierten Status zurück.

Warnung: Das Löschen einer Instanz zerstört die Maschine und alle darauf gespeicherten Daten dauerhaft. Diese Aktion kann nicht rückgängig gemacht werden. Sichere benötigte Daten, bevor du fortfährst.

Das Löschen der Instanz beendet weitere Guthabenabbuchungen für diese Instanz.


const API_KEY = 'YOUR_BEARER_API_KEY';
const INSTANCE_ID = 1;
const URL = 'https://api.nosgpu.ch/v1/instances/' + INSTANCE_ID;

fetch(URL, {
    method: 'DELETE',
    headers: {
        'Authorization': 'Bearer ' + API_KEY,
        'Content-Type': 'application/json'
    }
})
.then(async (response) => {
    const data = await response.json();

    if (!response.ok) {
        throw new Error(JSON.stringify(data));
    }

    console.log('Instance delete result:', data.instance);
})
.catch((error) => {
    console.error('Error deleting instance:', error.message);
});

Anfrage

Methode:

DELETE

API-URL: https://api.nosgpu.ch/v1/instances/{instance_id}

Header:

Authorization: erforderlich – Bearer-Token

Content-Type: optional – application/json

Pfadparameter:

instance_id: erforderlich – Instanz-ID

Antwort

Statuscode: 200

Erfolgreiche Antwort

      
{
  "instance": {
    // instance id
    "id": number,
    // generated instance name
    "name": string,
    // instance category/type label
    "type": 'vm_gpu_dedicated'|'vm_gpu_shared'|'bare_metal'|'cold_storage'|'ai_storage',
    // current instance status after delete action
    "status": 'provisioning'|'running'|'starting'|'stopped'|'stopping'|'rebooting'|'error'|'deleting'|'deleted'|'expired',
    // instance start datetime in UTC if available
    "started_at": string|null
  }
}

    
Statuscode: 401

Nicht autorisiert– Prüfe, ob dein Bearer-Token korrekt ist

Statuscode: 404

Nicht gefunden– Instanz nicht gefunden

Support

Bei Problemen oder Fragen zur NOSGPU-API kontaktiere unser Supportteam.