Skip to main content
The AiHubMix CLI is a collection of utility scripts that allows you to manage your AiHubMix API keys, query account information, and use AI services without going through a web interface. Essentially, it encapsulates API calls (using curl or Python requests) for command-line convenience.

Prerequisites

Before using the AiHubMix CLI, you need to:
  1. An AIHubMix account
  2. Generate an Access Token by clicking “Generate System Access Token” on the AIHubMix Settings page;
  3. Install the necessary Python dependencies:
pip install -U requests openai
The aihubmix_cli.py script can be downloaded here

Features Overview

The AIHubMix CLI offers the following key functionalities:

API Endpoint Overview

EndpointHTTP MethodDescription
/api/user/selfGETRetrieve current user information and account balance
/api/token/GETRetrieve a list of all Keys
/api/token/POSTCreate a new API Key
/api/token/PUTUpdate an existing API Key
/api/token/{token_id}GETRetrieve detailed information for a specific Key
/api/token/{token_id}DELETEDelete a specific Key
/api/token/searchGETSearch for Keys (use ?keyword=search_term)
/api/user/tokenGETRetrieve user Keys
/api/modelsGETRetrieve a list of all available models
/api/user/available_modelsGETRetrieve a list of models available to the current user

Retrieve Balance Information

# Using curl to retrieve balance, balance is quota / 500000
curl -X GET "https://aihubmix.com/api/user/self" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Key Management

Create New Key

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": ""
  }'

Retrieve Key List

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"

Search for Key

curl -X GET "https://aihubmix.com/api/token/search?keyword=search_term" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Update Key

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
  }'

Delete Key

curl -X DELETE "https://aihubmix.com/api/token/Key_ID" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Retrieve User Key

curl -X GET "https://aihubmix.com/api/user/token" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Model Management

Retrieve All Available Models

curl -X GET "https://aihubmix.com/api/models" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Retrieve User’s Available Models

curl -X GET "https://aihubmix.com/api/user/available_models" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Output in JSON Format

All CLI commands support outputting results in JSON format, making it easier for programmatic processing:
python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance --json

Troubleshooting

If you encounter issues, you can try the following solutions:
  1. Connection Issues: If the main domain fails to connect, try using an alternative domain:
    python aihubmix_cli.py --url "https://api.aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance
    
  2. Invalid Access Token: Ensure that the provided access token is a valid key obtained from the AIHubMix website. The format of the access token is usually like fd***.
  3. Insufficient Permissions: Some operations may require specific permissions, so ensure your account has adequate permissions.
  4. Request Failure: Check your network connection or try again later.

Notes

  • The access token is different from the regular API Key used to access AI models.
  • Each user has their own system access token, and the access level is determined by the user’s role (regular user, administrator, or root user).