import os import requests def test_together_api(): TOGETHER_API_KEY = os.environ.get("TOGETHER_API_KEY") print("🔍 API Key starts with:", TOGETHER_API_KEY[:8] if TOGETHER_API_KEY else "None") if not TOGETHER_API_KEY: raise RuntimeError("❌ TOGETHER_API_KEY not found. Set it in Hugging Face > Settings > Secrets.") url = "https://api.together.xyz/v1/chat/completions" headers = { "Authorization": f"Bearer {TOGETHER_API_KEY}", "Content-Type": "application/json" } payload = { "model": "mistralai/Mixtral-8x7B-Instruct-v0.1", "messages": [{"role": "user", "content": "Write a SQL query to select all rows from table `df`"}], "temperature": 0.2, "max_tokens": 200 } response = requests.post(url, headers=headers, json=payload) print("✅ API call status:", response.status_code) print("📦 Response JSON:", response.json()) test_together_api()