#!/usr/bin/env python3
"""Cek akses model dgn User-Agent browser."""
import json, re, urllib.request

tools = open('TOOLS.md', encoding='utf-8').read()
m = re.search(r'Replicate API Key[\s\S]*?Token:\*\*\s*`([^`]+)`', tools)
KEY = m.group(1).strip()
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36"
H = {"Authorization": f"Bearer {KEY}", "User-Agent": UA}

for model in ["black-forest-labs/flux-1.1-pro", "bytedance/seedance-2.5", "black-forest-labs/flux-schnell"]:
    try:
        req = urllib.request.Request(f"https://api.replicate.com/v1/models/{model}", headers=H)
        with urllib.request.urlopen(req, timeout=30) as r:
            d = json.loads(r.read())
        latest = d.get("latest_version", {})
        props = (latest.get("openapi_schema", {}).get("components", {}).get("schemas", {}).get("Input", {}).get("properties", {}) or {})
        print(f"OK: {model} | ver {latest.get('id','')[:16]} | keys: {list(props.keys())[:14]}")
    except urllib.error.HTTPError as e:
        print(f"FAIL: {model} | {e.code} {e.read().decode()[:120]}")
