import os
import requests
headers = {"Authorization": f"Bearer {os.environ['OPENTYPE_API_KEY']}"}
keys = requests.get("https://api.opentype.dev/v1/keys", headers=headers, timeout=30).json()["keys"]
key = next((k for k in keys if k["name"] == "ci-pipeline"), None)
if key is None:
raise RuntimeError("no key named ci-pipeline")
# key["id"] starts with key_. Never put key["secret_prefix"] or a secret in the path.
resp = requests.get(f"https://api.opentype.dev/v1/keys/{key['id']}", headers=headers, timeout=30)
body = resp.json()
if not resp.ok:
raise RuntimeError(f"{body['error']['code']}: {body['error']['message']}")
print(body["state"], body["last_used_at"])