Translation in progress, please wait some minutes

API del Server GPU (RESTful)

L'API di Trooper.AI offre un accesso completo alla gestione dei GPU Server, inclusi la configurazione, il monitoraggio, la migrazione e le funzioni amministrative. Questa API RESTful Le consente di gestire in modo programmatico la Sua infrastruttura GPU, creare e monitorare ordini per server, gestire modelli e svolgere compiti amministrativi.

Gli endpoint API e la documentazione dell'API sono attualmente in fase Beta. Contattaci per qualsiasi problema: Contatti di Assistenza.

Trova la Sua chiave API nella Console API.

Prova in API Playground

Consiglio pratico: Basta fornire questa documentazione al Suo agente LLM di Sviluppo e lo integrerà automaticamente nel codice.


Panoramica

Ottenga una panoramica rapida sui concetti base dell'API come URL, autenticazione e altro:

URL di base

Codice
https://james.trooper.ai

Autenticazione

La maggior parte degli endpoint richiede autenticazione con Bearer token utilizzando la Sua chiave Trooper API:

http
Authorization: Bearer YOUR_API_KEY

Ottenga la Sua chiave API dalla API Console.

Formato della risposta

Tutte le risposte dell'API sono in formato JSON. Le risposte di successo includono tipicamente:

  • success: Boolean indicating operation success
  • Additional data fields specific to the endpoint

Error responses include:

  • error: String describing the error
  • next: Optional field suggesting next action (e.g., “login”)

Public Endpoints

Get Test Status

GET /api/test

Simple test endpoint to verify API connectivity.

Request

http
GET /api/test

Success Response (200)

json
{
  "test": "meinstring5"
}

Get Available GPU Servers (Public)

GET /api/blibs

Retrieve all publicly available GPU server configurations.

Request

http
GET /api/blibs
Authorization: Bearer YOUR_API_KEY  # Optional - includes your private networks if provided

Success Response (200)

json
[
  {
    "id": 1,
    "name": "powerai.example",
    "gpu_type": "RTX 4090",
    "gpu_num": 1,
    "gpu_ram": 24,
    "cpu_cores": 8,
    "cpu_ram": 32,
    "hdd": 500,
    "price_h": 0.85,
    "is_public": 1,
    "country_code": "DE",
    "is_available": true,
    "available_hosts": ["ai18", "ai89"],
    "fitCount": 2,
    "maxPossibleInstances": 5
  }
]

Error Response (500)

json
{
  "error": "Error fetching Blibs"
}

Authentication Required Endpoints

Get Private GPU Servers

GET /api/blibs-private

Retrieve GPU servers accessible to your account, including private configurations.

Request

http
GET /api/blibs-private
Authorization: Bearer YOUR_API_KEY

Success Response (200)

json
[
  {
    "id": 2,
    "name": "RTX 4090 Dual Private",
    "gpu_type": "RTX 4090",
    "gpu_num": 2,
    "gpu_ram": 24,
    "cpu_cores": 16,
    "cpu_ram": 64,
    "hdd": 1000,
    "price_h": 1.65,
    "is_public": 1,
    "country_code": "DE"
  }
]

Error Response (401)

json
{
  "error": "Missing or invalid Authorization header"
}

Create Server Order

POST /api/order

Create a new GPU server order. You must submit the price provided, otherwise the order will not be accepted. This makes sure the current price matches your expectations!

Apri Console API & Prova

Request

http
POST /api/order
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "blib_id": 1,
  "price_h": 0.85,
  "total_price": 0.85,
  "terms_accepted": true,
  "contract_interval": "HOUR",
  "second_partition_percentage": 20,
  "templates": [
    {
      "id": 1,
      "name": "PyTorch Environment"
    }
  ]
}

Success Response (200)

json
{
  "success": true,
  "orderId": 123
}

Error Response (400)

json
{
  "error": "You must accept the terms and conditions."
}

Error Response (400)

json
{
  "error": "Invalid or missing contract interval."
}

Get Your Server Orders

OTTENI /api/ordini

Retrieve all your server orders with detailed information.

When handling server statuses, consider the interplay between desired_status and current_status. For example, a server might have a desired_status of “stopped”, but its current_status could still be “running” if the stop process is in progress. Your application should account for these transitions and handle them accordingly.

Request

http
GET /api/orders
Authorization: Bearer YOUR_API_KEY

Query Parameters

  • machine_name (optional): Filter by specific machine name

Success Response (200)

json
[
  {
    "order_id": 123,
    "serverId": 123,
    "title": "My PyTorch Server",
    "status": "running",
    "status_user": "running",
    "server_name": "gpu-server-01",
    "machine_name": "ai99_trooperai_000123",
    "ip": "192.168.1.100",
    "ssh_port": 22001,
    "price_h": 0.85,
    "paid_until": "2025-09-26T14:30:00.000Z",
    "contract_interval": "HOUR",
    "is_locked": false,
    "is_low_priority": false,
    "blib_name": "RTX 4090 Single",
    "blib_gpu_type": "RTX 4090",
    "blib_gpu_num": 1,
    "country_code": "DE",
    "template_installs": [
      {
        "id": 1,
        "template_name": "PyTorch Environment",
        "status": 1,
        "status_readable": "Completed"
      }
    ]
  }
]

Error Response (401)

json
{
  "error": "Missing or invalid Authorization header",
  "next": "login"
}

Update Server Status

POST /api/order-status

Update your server order status (running, stopped, restarted, frozen, terminated).

Set "migration_allowed": true if you approve host migration when transitioning from a frozen to running state. This process may take 10–90 minutes and will change the Ports Range and potentially the CPU model/speed.

Request

http
POST /api/order-status
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "serverId": 123,
  "desired_status": "running",
  "migration_allowed": false
}

Success Response (200)

json
{
  "success": true,
  "updated": 1
}

Error Response (403)

json
{
  "success": false,
  "error": "Server is locked and cannot be modified"
}

Update Server Title

POST /api/order-title

Update the display title of your server.

Request

http
POST /api/order-title
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "serverId": 123,
  "title": "My New Server Title"
}

Success Response (200)

json
{
  "success": true,
  "message": "Title updated successfully"
}

Lock/Unlock Server

POST /api/order-lock

Lock or unlock a server to prevent/allow status changes.

Request

http
POST /api/order-lock
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "serverId": 123,
  "is_locked": true
}

Success Response (200)

json
{
  "success": true,
  "updated": 1
}

Get Server Credentials

POST /api/credentials

Retrieve SSH credentials and connection details for your server.

Request

http
POST /api/credentials
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "serverId": 123
}

Success Response (200)

json
{
  "success": true,
  "ssh_password": "generated-password"
}

Error Response (403)

json
{
  "error": "Access denied or server not found"
}

Get Server Status History

GET /api/storia-stato-ordine

Get the last 5 status changes for a server order.

Request

http
GET /api/order-status-history?order_id=123
Authorization: Bearer YOUR_API_KEY

Success Response (200)

json
{
  "success": true,
  "history": [
    {
      "id": 1,
      "status_user": "running",
      "status_txt": "Server started successfully",
      "status_since": "2025-09-25T10:30:00.000Z"
    },
    {
      "id": 2,
      "status_user": "stopped",
      "status_txt": "Server stopped by user",
      "status_since": "2025-09-25T08:15:00.000Z"
    }
  ]
}

Migration Endpoints

Migration is used to bring your GPU server to a different configuration. We don’t recommend to use this for production. But you can try if you like!

Get Migration Options

GET /api/migration-options

Get available server configurations for migration.

Request

http
GET /api/migration-options?order_id=123
Authorization: Bearer YOUR_API_KEY

Success Response (200)

json
{
  "success": true,
  "currentOrder": {
    "id": 123,
    "title": "My Server",
    "status": "running",
    "contract_interval": "HOUR",
    "paid_until": "2025-09-26T14:30:00.000Z"
  },
  "currentBlib": {
    "id": 1,
    "name": "RTX 4090 Single",
    "gpu_type": "RTX 4090",
    "gpu_num": 1,
    "price_h": 0.85
  },
  "availableBlibs": [
    {
      "id": 2,
      "name": "RTX 4090 Dual",
      "gpu_type": "RTX 4090",
      "gpu_num": 2,
      "price_h": 1.65,
      "is_available": true,
      "additionalCostPerCycle": 0.80
    }
  ]
}

Calculate Migration Cost

POST /api/migration-cost

Calculate the cost for migrating to a different server configuration.

Request

http
POST /api/migration-cost
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "order_id": 123,
  "target_blib_id": 2
}

Success Response (200)

json
{
  "success": true,
  "upgradeCost": 15.50,
  "remainingValue": 12.30,
  "totalDue": 3.20,
  "additionalCostPerCycle": 0.80,
  "nextBillingDate": "2025-09-26T14:30:00.000Z",
  "currentRate": {
    "amount": 0.85,
    "display": "€0.85/hour"
  },
  "newRate": {
    "amount": 1.65,
    "display": "€1.65/hour"
  }
}

Execute Migration

POST /api/buy-migration

Execute the migration to a new server configuration.

IMPORTANTE Se invia dati non validi qui, nulla è garantito. Il team di supporto non può ripristinare il Suo ordine se Lei utilizza impropriamente questa endpoint per l'acquisto di migrazioni. Le raccomandiamo di utilizzare l’UI Dashboard.

Request

http
POST /api/buy-migration
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "order_id": 123,
  "target_blib_id": 2,
  "keep_data": true
}

Success Response (200)

json
{
  "success": true,
  "message": "Migration initiated successfully",
  "new_order_id": 124
}

Error Response (400)

json
{
  "error": "Insufficient budget for migration"
}

Template Management

Get Available Templates

GET /api/templates

Get all available software templates.

Request

http
GET /api/templates
Authorization: Bearer YOUR_API_KEY  # Optional

Success Response (200)

json
[
  {
    "id": 1,
    "name": "PyTorch Environment",
    "description": "Pre-configured PyTorch environment with CUDA support",
    "category": "Machine Learning",
    "is_public": true,
    "options": [
      {
        "id": 1,
        "name": "Python Version",
        "type": "select",
        "default_value": "3.9",
        "possible_values": "3.8,3.9,3.10"
      }
    ]
  }
]

Get Template Configuration

GET /api/configurazione-template

Get template installation configuration for a specific order.

Request

http
GET /api/template-config?order_id=123
Authorization: Bearer YOUR_API_KEY

Success Response (200)

json
{
  "success": true,
  "templates": [
    {
      "install_id": 1,
      "template_id": 1,
      "template_name": "PyTorch Environment",
      "status": 1,
      "status_readable": "Completed",
      "config": {
        "python_version": "3.9"
      }
    }
  ]
}

Install Template

POST /api/installazione-template-add

Install a new template on your server.

Request

http
POST /api/template-install-add
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "order_id": 123,
  "template_id": 1,
  "config": {
    "python_version": "3.9"
  }
}

Success Response (200)

json
{
  "success": true,
  "install_id": 5,
  "message": "Template installation queued"
}

Rimuova modello

POST /api/template-install-elimina

Remove a template installation from your server.

Request

http
POST /api/template-install-delete
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "install_id": 5
}

Success Response (200)

json
{
  "success": true,
  "message": "Template removal initiated"
}

Retry Template Installation

POST /api/template-install-retry

Retry a failed template installation.

Request

http
POST /api/template-install-retry
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Request Body

json
{
  "install_id": 5
}

Success Response (200)

json
{
  "success": true,
  "message": "Template installation retry initiated"
}

Error Codes

HTTP Status Codes

  • 200 OK: Richiesta completata con successo
  • 400 Bad Request: Parametri della richiesta non validi
  • 401 Non autorizzato: Autenticazione mancante o non valida
  • 403 Forbidden: Permessi insufficienti
  • 404 Non trovato: Risorsa non trovata
  • Errore Interno del Server 500: Errore del server

Common Error Messages

  • "Missing or invalid Authorization header": Authentication required
  • "Invalid Trooper key": API key is invalid
  • "Unauthorized access": Insufficient permissions
  • "You must accept the terms and conditions": Terms not accepted in order creation
  • "Invalid or missing contract interval": Contract interval must be HOUR, WEEK, or MONTH
  • "Insufficient budget": Not enough budget for the operation
  • "Server is locked and cannot be modified": Server is locked for modifications

Rate Limiting

API endpoints may be rate-limited to prevent abuse. If you exceed the rate limit, you’ll receive a 429 status code. Implement appropriate retry logic with exponential backoff.

Support

Per il supporto dell'API e domande, contatti: [email protected]

Apri la Console API


Per qualsiasi domanda relativa all'API, contatti pure Support Contacts