AiHubMix CLI is a collection of utility management scripts that allows you to manage your AiHubMix API keys, query account information, and use AI services without needing to access the web interface. It essentially wraps API calls (curl or Python requests) for easier command-line usage.

Prerequisites

Before using the AiHubMix CLI, you’ll need:

  1. An AiHubMix account
  2. An Access Token generated from the AiHubMix Settings page by clicking “Generate System Access Token”
  3. Required Python dependencies:
pip install -U requests openai

The aihubmix_cli.py script can be downloaded here

Model

Feature List

AiHubMix CLI provides the following main functions:

API Endpoints Overview

EndpointHTTP MethodDescription
/api/user/selfGETGet current user information and account balance
/api/token/GETGet list of all API keys
/api/token/POSTCreate a new API key
/api/token/PUTUpdate an existing API key
/api/token/{token_id}GETGet details of a specific API key
/api/token/{token_id}DELETEDelete a specific API key
/api/token/searchGETSearch for API keys (using ?keyword=search_term)
/api/user/tokenGETGet user API key
/api/modelsGETGet list of all available models
/api/user/available_modelsGETGet list of models available to the current user

Account Management

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

API Key Management

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": ""
  }'
curl -X GET "https://aihubmix.com/api/token/" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"
curl -X GET "https://aihubmix.com/api/token/search?keyword=search_term" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"
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
  }'
curl -X DELETE "https://aihubmix.com/api/token/KEY_ID" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"
curl -X GET "https://aihubmix.com/api/user/token" \
  -H "Authorization: YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"

Model Management

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

JSON Format Output

All CLI commands support outputting results in JSON format for programmatic processing:

python aihubmix_cli.py --url "https://aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance --json

Troubleshooting

If you encounter issues, try the following solutions:

  1. Connection Problems: If the main domain connection fails, try using the backup domain:

    python aihubmix_cli.py --url "https://api.aihubmix.com" --token "YOUR_ACCESS_TOKEN" --action get_balance
    
  2. Invalid Access Token: Ensure the provided access token is a valid key obtained from the AiHubMix website. Access tokens typically have a format like fd***.

  3. Insufficient Permissions: Some operations may require specific permissions; ensure your account has sufficient privileges.

  4. Request Failures: Check your network connection or try again later.

Notes

  • The access token is different from the regular API keys used to access AI models
  • Each user has their own system access token, with access levels determined by the user role (regular user, administrator, or root user)