import os
import requests
headers = {"Authorization": f"Bearer {os.environ['LIGHTON_API_KEY']}"}
# expires_at is required: null creates a key that never expires
response = requests.post(
"https://api.lighton.ai/api/v3/keys",
headers=headers,
json={"name": "ci-pipeline", "expires_at": None},
)
key = response.json()
print(key["id"], key["key"]) # the full key is returned only here, store it now
# Revoke it when it is no longer needed
response = requests.delete(
f"https://api.lighton.ai/api/v3/keys/{key['id']}",
headers=headers,
)
print(response.status_code) # 204