#!/usr/bin/env python3
"""Script to list available models from Nexos.ai API."""
import os
import httpx
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
API_KEY = os.getenv("NEXOS_API_KEY")
BASE_URL = "https://api.nexos.ai/v1"
def list_models():
"""List all available models from Nexos.ai."""
if not API_KEY:
print("ERROR: NEXOS_API_KEY not found in environment")
return
print(f"API Key: {API_KEY[:20]}...{API_KEY[-10:]}")
print(f"Base URL: {BASE_URL}")
print()
headers = {
"Authorization": f"Bearer {API_KEY}",
"Accept": "application/json",
}
try:
with httpx.Client(timeout=30.0) as client:
response = client.get(f"{BASE_URL}/models", headers=headers)
print(f"Status: {response.status_code}")
print()
if response.status_code == 200:
data = response.json()
models = data.get("data", [])
total = data.get("total", len(models))
print(f"Total models: {total}")
print()
# Filter for image-related models
image_models = []
for model in models:
model_id = model.get("id", "")
# Check if it's an image model
if any(
keyword in model_id.lower()
for keyword in ["imagen", "flux", "dall", "image", "gpt-image"]
):
image_models.append(model)
if image_models:
print("=== IMAGE GENERATION MODELS ===")
for model in image_models:
print(f" ID: {model.get('id')}")
print(f" Nexos ID: {model.get('nexos_model_id')}")
print(f" Owned by: {model.get('owned_by')}")
print()
else:
print("No image models found. Showing first 20 models:")
for model in models[:20]:
print(f" ID: {model.get('id')}")
print(f" Nexos ID: {model.get('nexos_model_id')}")
print(f" Owned by: {model.get('owned_by')}")
print()
if len(models) > 20:
print(f"... and {len(models) - 20} more models")
else:
print(f"Error response: {response.text}")
except Exception as e:
print(f"ERROR: {type(e).__name__}: {e}")
if __name__ == "__main__":
list_models()