#!/usr/bin/env python3
"""Cek model image gen Replicate yang bisa diakses akun ini."""
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()

models = [
    "black-forest-labs/flux-schnell",
    "black-forest-labs/flux-kontext",
    "stability-ai/sdxl",
    "stability-ai/stable-diffusion-3.5-large",
    "bytedance/seedream-3.0",
    "google/imagen-3",
    "google/imagen-4",
    "luma/photon",
    "recraft-ai/recraft-v3-archived",
    "nvidia/sana",
    "zylim0702/flux-1-dev",
    "xlabs-ai/flux-dev-lora",
]
for model in models:
    try:
        req = urllib.request.Request(f"https://api.replicate.com/v1/models/{model}",
            headers={"Authorization": f"Bearer {KEY}"})
        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}")
