const fs = require('fs');
const path = require('path');

//node show-models.js, remember to set SAIA_API_KEY in your environment before running the script

const SAIA_API_KEY = process.env.SAIA_API_KEY;
const SAIA_MODELS_URL = "https://chat-ai.academiccloud.de/v1/models";

// Script to list available models
(async () => {
    if (!SAIA_API_KEY) {
        console.error("ERROR: SAIA_API_KEY environment variable is not set!");
        process.exit(1);
    }

    console.log("Fetching available models from SAIA...\n");

    try {
        const response = await fetch(SAIA_MODELS_URL, {
            method: "GET",
            headers: {
                "Authorization": `Bearer ${SAIA_API_KEY}`,
                "Accept": "application/json"
            }
        });

        if (!response.ok) {
            const text = await response.text();
            throw new Error(`SAIA API error (${response.status}): ${text}`);
        }

        const data = await response.json();
        
        console.log("Available models:");
        console.log(JSON.stringify(data, null, 2));
        
        if (data.data && Array.isArray(data.data)) {
            console.log("\n\nModel IDs:");
            data.data.forEach(model => {
                console.log(`- ${model.id}`);
            });
        }

    } catch (error) {
        console.error("Error fetching models:", error);
    }
})();