#!/bin/bash # fetch-models.sh - Fetch available models from AI providers # Usage: ./fetch-models.sh [provider] set -e GREEN='\033[0;32m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}╔═══════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ AI PROVIDER MODEL FETCHER ║${NC}" echo -e "${BLUE}╚═══════════════════════════════════════════════════════════════╝${NC}" fetch_openrouter() { if [ -n "$OPENROUTER_API_KEY" ]; then echo -e "\n${GREEN}📦 OpenRouter Models:${NC}" curl -s https://openrouter.ai/api/v1/models \ -H "Authorization: Bearer $OPENROUTER_API_KEY" | \ jq -r '.data[] | " • \(.id)"' | head -30 else echo -e "\n⚠️ OPENROUTER_API_KEY not set" fi } fetch_openai() { if [ -n "$OPENAI_API_KEY" ]; then echo -e "\n${GREEN}📦 OpenAI Models:${NC}" curl -s https://api.openai.com/v1/models \ -H "Authorization: Bearer $OPENAI_API_KEY" | \ jq -r '.data[] | select(.id | test("gpt|o1|o3")) | " • \(.id)"' | sort -u else echo -e "\n⚠️ OPENAI_API_KEY not set" fi } fetch_groq() { if [ -n "$GROQ_API_KEY" ]; then echo -e "\n${GREEN}📦 Groq Models:${NC}" curl -s https://api.groq.com/openai/v1/models \ -H "Authorization: Bearer $GROQ_API_KEY" | \ jq -r '.data[].id' | sed 's/^/ • /' else echo -e "\n⚠️ GROQ_API_KEY not set" fi } fetch_ollama() { echo -e "\n${GREEN}📦 Ollama Models (local):${NC}" if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then curl -s http://localhost:11434/api/tags | jq -r '.models[].name' | sed 's/^/ • /' else echo " ⚠️ Ollama not running on localhost:11434" fi } fetch_together() { if [ -n "$TOGETHER_API_KEY" ]; then echo -e "\n${GREEN}📦 Together AI Models:${NC}" curl -s https://api.together.xyz/v1/models \ -H "Authorization: Bearer $TOGETHER_API_KEY" | \ jq -r '.data[].id' | head -20 | sed 's/^/ • /' else echo -e "\n⚠️ TOGETHER_API_KEY not set" fi } fetch_anthropic() { echo -e "\n${GREEN}📦 Anthropic Models (static list):${NC}" echo " • claude-opus-4-5-20250219" echo " • claude-sonnet-4-5-20250219" echo " • claude-3-5-sonnet-20241022" echo " • claude-3-5-haiku-20241022" echo " • claude-3-opus-20240229" } fetch_google() { if [ -n "$GOOGLE_API_KEY" ]; then echo -e "\n${GREEN}📦 Google Gemini Models:${NC}" curl -s "https://generativelanguage.googleapis.com/v1/models?key=$GOOGLE_API_KEY" | \ jq -r '.models[].name' | sed 's|models/||' | sed 's/^/ • /' else echo -e "\n⚠️ GOOGLE_API_KEY not set" fi } # Main logic case "${1:-all}" in openrouter) fetch_openrouter ;; openai) fetch_openai ;; groq) fetch_groq ;; ollama) fetch_ollama ;; together) fetch_together ;; anthropic) fetch_anthropic ;; google) fetch_google ;; all) fetch_anthropic fetch_openai fetch_google fetch_openrouter fetch_groq fetch_together fetch_ollama ;; *) echo "Usage: $0 [openrouter|openai|groq|ollama|together|anthropic|google|all]" exit 1 ;; esac echo -e "\n${GREEN}✅ Model fetch complete${NC}"