Explorer
/tmp/p2zg_credits.py
← Zurück ↓ Download
#!/usr/bin/env python3
"""OpenRouter credit balance via API."""
import json, urllib.request

key = ""
with open("/etc/graphiti/graphiti.env") as f:
    for line in f:
        if line.startswith("OPENROUTER_API_KEY="):
            key = line.split("=", 1)[1].strip()
            break

req = urllib.request.Request(
    "https://openrouter.ai/api/v1/credits",
    headers={"Authorization": f"Bearer {key}"},
)
resp = urllib.request.urlopen(req, timeout=30)
data = json.loads(resp.read())
print(json.dumps(data, indent=2))