import os
from urllib.request import Request, urlopen
import json

key_path = "/home/iswanjp/mico/.secret/groq.env"
os.environ.setdefault("GROQ_API_KEY", "")

with open(key_path) as f:
    for line in f:
        line = line.strip()
        if "=" in line:
            k, v = line.split("=", 1)
            os.environ[k.strip()] = v.strip()

api_key = os.environ.get("GROQ_API_KEY", "").strip()

if not api_key:
    print("GROQ_API_KEY kosong")
else:
    req = Request(
        "https://api.groq.com/openai/v1/models",
        headers={"Authorization": f"Bearer {api_key}"}
    )
    with urlopen(req) as resp:
        data = json.load(resp)
        print("TERHUBUNG KE GROQ")
        print("Jumlah model:", len(data.get("data", [])))
