> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kontoinformationen per API abrufen

> Verwalten Sie Schlüssel, Konten und verfügbare Modelllisten in der Kommandozeile mit dem AiHubMix CLI-Hilfsskript.

Die AiHubMix CLI ist eine Sammlung von Hilfsskripten, mit denen Sie Ihre AiHubMix-API-Schlüssel verwalten, Kontoinformationen abfragen und KI-Dienste nutzen können, ohne über die Weboberfläche gehen zu müssen. Sie kapselt im Wesentlichen API-Aufrufe (per curl oder Python `requests`) für die bequeme Nutzung in der Kommandozeile.

<Tip>
  Wir empfehlen das neue Kommandozeilen-Tool der nächsten Generation [AIHubMix CLI (Kommandozeilen-Tool)](/de/api/aihubmix-cli): einzelne Binärdatei, keine Laufzeitabhängigkeiten (kein Python erforderlich), ressourcenorientierte Befehle wie `aihubmix keys list` sowie `jq`- und AI-Agent-freundlich. Diese Seite enthält die alte Python-Skript-Nutzung als Referenz.
</Tip>

## Voraussetzungen

Bevor Sie die AiHubMix CLI verwenden, benötigen Sie:

1. Ein [AIHubMix-Konto](https://aihubmix.com)
2. Einen Access Token, den Sie auf der [AIHubMix-Einstellungsseite](https://aihubmix.com/setting) per Klick auf „Generate System Access Token" erstellen können.
3. Die erforderlichen Python-Abhängigkeiten:

```bash theme={null}
pip install -U requests openai
```

<Info>
  Das Skript `aihubmix_cli.py` kann [hier heruntergeladen werden](https://github.com/jerlinn/inferHub).
</Info>

## Funktionsübersicht

Die AIHubMix CLI bietet folgende Kernfunktionen:

### Übersicht der API-Endpoints

| Endpoint                     | HTTP-Methode | Beschreibung                                                     |
| ---------------------------- | ------------ | ---------------------------------------------------------------- |
| `/api/user/self`             | GET          | Aktuelle Benutzerinformationen und Kontoguthaben abrufen         |
| `/api/token/`                | GET          | Liste aller Keys abrufen                                         |
| `/api/token/`                | POST         | Einen neuen API Key erstellen                                    |
| `/api/token/`                | PUT          | Einen vorhandenen API Key aktualisieren                          |
| `/api/token/{token_id}`      | GET          | Detailinformationen eines bestimmten Keys abrufen                |
| `/api/token/{token_id}`      | DELETE       | Einen bestimmten Key löschen                                     |
| `/api/token/search`          | GET          | Nach Keys suchen (`?keyword=search_term`)                        |
| `/api/user/token`            | GET          | Benutzer-Keys abrufen                                            |
| `/api/user/available_models` | GET          | Liste der für den aktuellen Benutzer verfügbaren Modelle abrufen |

### Kontostand abrufen

<CodeGroup>
  ```shell theme={null}
  # Mit curl den Kontostand abrufen, Saldo = quota / 500000
  curl -X GET "https://aihubmix.com/api/user/self" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Retrieve account balance
  response = requests.get(f"{api_url}/api/user/self", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          user_data = data.get("data", {})
          quota = user_data.get('quota', 0)
          usd_balance = quota / 500000  # $1 equals 500,000 quota
          print(f"Username: {user_data.get('username', 'Unknown')}")
          print(f"Display Name: {user_data.get('display_name', 'Unknown')}")
          print(f"Current Quota: {quota}")
          print(f"Available USD: ${usd_balance:.2f}")
      else:
          print(f"Request failed: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance
  ```

  ```shell theme={null}
  # Verbleibende Quota eines Keys abrufen
  curl 'https://aihubmix.com/dashboard/billing/remain' \
    -H 'authorization: Bearer sk-***' \
  ```
</CodeGroup>

### Schlüsselverwaltung

#### Neuen Schlüssel erstellen

<CodeGroup>
  ```shell theme={null}
  curl -X POST "https://aihubmix.com/api/token/" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "New Key Name",
      "expired_time": -1,
      "remain_quota": 500000,
      "unlimited_quota": false,
      "subnet": ""
    }'
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Create New Key
  payload = {
      "name": "New Key Name",
      "expired_time": -1,  # Never expires
      "remain_quota": 500000,
      "unlimited_quota": False,
      "subnet": ""
  }

  response = requests.post(f"{api_url}/api/token/", headers=headers, json=payload)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          token_data = data.get("data", {})
          print(f"New Key: {token_data.get('key', 'Unknown')}")
          print(f"Key ID: {token_data.get('id', 'Unknown')}")
      else:
          print(f"Failed to create Key: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action create_token --name "New Key Name" --expires -1 --quota 500000
  ```
</CodeGroup>

#### Schlüsselliste abrufen

<CodeGroup>
  ```shell theme={null}
  curl -X GET "https://aihubmix.com/api/token/?num=20" \ # Adjust num parameter to change the number of output data.
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Retrieve Key List
  response = requests.get(f"{api_url}/api/token/", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          tokens_data = data.get("data", [])
          print(f"Key List (Total {len(tokens_data)}):")
          for token in tokens_data:
              print(f"Key ID: {token.get('id', 'Unknown')}")
              print(f"Key Name: {token.get('name', 'Unknown')}")
              print(f"Key: {token.get('key', 'Unknown')}")
              print("---")
      else:
          print(f"Failed to retrieve Key list: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_tokens
  ```
</CodeGroup>

#### Nach Schlüssel suchen

<CodeGroup>
  ```shell theme={null}
  curl -X GET "https://aihubmix.com/api/token/search?keyword=search_term" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Search Keyword
  query = "search_term"

  # Search Key
  response = requests.get(f"{api_url}/api/token/search?keyword={query}", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          tokens_data = data.get("data", [])
          print(f"Search Results (Total {len(tokens_data)}):")
          for token in tokens_data:
              print(f"Key ID: {token.get('id', 'Unknown')}")
              print(f"Key Name: {token.get('name', 'Unknown')}")
              print(f"Key: {token.get('key', 'Unknown')}")
              print("---")
      else:
          print(f"Failed to search Key: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action search_tokens --query "search_term"
  ```
</CodeGroup>

#### Schlüssel aktualisieren

<CodeGroup>
  ```shell theme={null}
  curl -X PUT "https://aihubmix.com/api/token/" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "id": "Key_ID",
      "name": "New Name",
      "expired_time": 86400,
      "remain_quota": 100000,
      "status": 1
    }'
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Update Key
  key_id = "Key_ID"  # Replace with the actual Key ID
  payload = {
      "id": key_id,
      "name": "New Name",
      "expired_time": 86400,  # Expires after 24 hours
      "remain_quota": 100000,
      "status": 1  # 1-Enabled, 0-Disabled
  }

  response = requests.put(f"{api_url}/api/token/", headers=headers, json=payload)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          print(f"Key updated successfully")
          if "data" in data:
              token_data = data.get("data", {})
              print(f"Name: {token_data.get('name', 'Unknown')}")
              print(f"Expiration Time: {token_data.get('expired_time', 'Unknown')}")
      else:
          print(f"Failed to update Key: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action update_token --id "Key_ID" --name "New Name" --expires 86400 --quota 100000 --status 1
  ```
</CodeGroup>

#### Schlüssel löschen

<CodeGroup>
  ```shell theme={null}
  curl -X DELETE "https://aihubmix.com/api/token/Key_ID" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Delete Key
  key_id = "Key_ID"  # Replace with the actual Key ID

  response = requests.delete(f"{api_url}/api/token/{key_id}", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          print(f"Key deleted successfully")
      else:
          print(f"Failed to delete Key: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action delete_token --id "Key_ID"
  ```
</CodeGroup>

#### Benutzer-Key abrufen

<CodeGroup>
  ```shell theme={null}
  curl -X GET "https://aihubmix.com/api/user/token" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Retrieve User Key
  response = requests.get(f"{api_url}/api/user/token", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          user_token = data.get("data", {}).get("token")
          print(f"User Key: {user_token}")
      else:
          print(f"Failed to retrieve User Key: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_user_token
  ```
</CodeGroup>

### Modellverwaltung

#### Verfügbare Modelle des Benutzers abrufen

<CodeGroup>
  ```shell theme={null}
  curl -X GET "https://aihubmix.com/api/user/available_models" \
    -H "Authorization: YOUR_ACCESS_TOKEN" \
    -H "Content-Type: application/json"
  ```

  ```py theme={null}
  import requests
  import json

  # API Configuration
  api_url = "https://aihubmix.com"
  access_token = "YOUR_ACCESS_TOKEN"
  headers = {
      "Authorization": access_token,
      "Content-Type": "application/json"
  }

  # Retrieve User's Available Models
  response = requests.get(f"{api_url}/api/user/available_models", headers=headers)
  if response.status_code == 200:
      data = response.json()
      if data.get("success", False):
          models_data = data.get("data", [])
          print(f"User's Available Model List (Total {len(models_data)}):")
          for i, model in enumerate(models_data, 1):
              print(f"  {i}. {model}")
      else:
          print(f"Failed to retrieve user's available models: {data.get('message', 'Unknown error')}")
  else:
      print(f"Request failed, status code: {response.status_code}")
  ```

  ```shell theme={null}
  python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_available_models
  ```
</CodeGroup>

## Ausgabe im JSON-Format

Alle CLI-Befehle unterstützen die Ausgabe im JSON-Format, was die programmatische Weiterverarbeitung erleichtert:

```bash theme={null}
python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance --json
```

## Fehlerbehebung

Bei Problemen können Sie Folgendes versuchen:

1. **Verbindungsprobleme**: Wenn die Hauptdomain nicht erreichbar ist, versuchen Sie eine alternative Domain:

   ```bash theme={null}
   python aihubmix_cli.py --url "https://api.aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance
   ```
2. **Ungültiger Access Token**: Stellen Sie sicher, dass der angegebene Access Token ein gültiger Schlüssel von der AIHubMix-Website ist. Das Format eines Access Tokens lautet üblicherweise z. B. `fd***`.
3. **Unzureichende Berechtigungen**: Manche Operationen erfordern bestimmte Berechtigungen; stellen Sie sicher, dass Ihr Konto über die nötigen Rechte verfügt.
4. **Fehlgeschlagener Request**: Prüfen Sie Ihre Netzwerkverbindung oder versuchen Sie es später erneut.

## Hinweise

* Der Access Token ist nicht identisch mit dem regulären API-Schlüssel, der für den Zugriff auf KI-Modelle verwendet wird.
* Jeder Benutzer hat seinen eigenen System-Access-Token; die Zugriffsebene wird durch die Benutzerrolle (regulärer Benutzer, Administrator oder Root-Benutzer) bestimmt.

***

Zuletzt aktualisiert: 2026-06-01
