""" Quick script to check if environment variables are set correctly. Run: python check_env.py """ import os import sys def check_env(): """Check and display environment variable status.""" print("=" * 50) print("IITM LLM Quiz Solver - Environment Check") print("=" * 50) print() # Check QUIZ_SECRET quiz_secret = os.getenv("QUIZ_SECRET") if quiz_secret: # Show first and last 4 chars for security masked = f"{quiz_secret[:4]}...{quiz_secret[-4:]}" if len(quiz_secret) > 8 else "***" print(f"✓ QUIZ_SECRET: Set ({masked})") print(f" Length: {len(quiz_secret)} characters") else: print("✗ QUIZ_SECRET: NOT SET (Required)") print(" Set it with: export QUIZ_SECRET='your_secret' (Linux/Mac)") print(" Or: $env:QUIZ_SECRET = 'your_secret' (Windows PowerShell)") print() # Check OpenAI key openai_key = os.getenv("OPENAI_API_KEY") if openai_key: masked = f"{openai_key[:7]}...{openai_key[-4:]}" if len(openai_key) > 11 else "***" print(f"✓ OPENAI_API_KEY: Set ({masked})") print(f" Length: {len(openai_key)} characters") if not openai_key.startswith("sk-"): print(" ⚠ Warning: OpenAI keys usually start with 'sk-'") else: print("✗ OPENAI_API_KEY: NOT SET (Optional)") print(" Set it with: export OPENAI_API_KEY='sk-your-key' (Linux/Mac)") print(" Or: $env:OPENAI_API_KEY = 'sk-your-key' (Windows PowerShell)") print() # Check OpenRouter key openrouter_key = os.getenv("OPENROUTER_API_KEY") if openrouter_key: masked = f"{openrouter_key[:6]}...{openrouter_key[-4:]}" if len(openrouter_key) > 10 else "***" print(f"✓ OPENROUTER_API_KEY: Set ({masked})") print(f" Length: {len(openrouter_key)} characters") if not openrouter_key.startswith("sk-or-"): print(" ⚠ Warning: OpenRouter keys usually start with 'sk-or-'") model = os.getenv("OPENROUTER_MODEL", "gpt-5-nano") print(f" Model: {model}") else: print("✗ OPENROUTER_API_KEY: NOT SET (Optional)") print(" Set it with: export OPENROUTER_API_KEY='sk-or-your-key' (Linux/Mac)") print(" Or: $env:OPENROUTER_API_KEY = 'sk-or-your-key' (Windows PowerShell)") print() # Check PORT (optional) port = os.getenv("PORT", "8000") print(f"PORT: {port} (default: 8000)") print() print("=" * 50) # Summary if quiz_secret: print("✓ Status: Ready to run (QUIZ_SECRET is set)") if openai_key or openrouter_key: provider = [] if openai_key: provider.append("OpenAI") if openrouter_key: provider.append("OpenRouter") print(f"✓ LLM features: Enabled via {', '.join(provider)}") else: print("⚠ LLM features: Disabled (no LLM API keys set)") else: print("✗ Status: NOT READY - QUIZ_SECRET is required") sys.exit(1) print("=" * 50) print() print("To start the server, run:") print(" python -m app.main") print(" or") print(" uvicorn app.main:app --host 0.0.0.0 --port 8000") if __name__ == "__main__": check_env()