API Key management
The base URL for Gravity's API:
🔑 Creating a New API Key
💬 Need Help?
Last updated
POST /api/v1/keys HTTP/1.1
X-API-Key: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 15
{
"name": "text"
}{
"key": "text",
"name": "text"
}https://sn13.api.macrocosmos.aiimport requests
import json
# === Configuration ===
MAINNET_API_URL = "https://sn13.api.macrocosmos.ai"
MAINNET_API_KEY = "" #pass in master api key
# === Headers for authentication ===
headers = {
'Content-Type': 'application/json',
'X-API-KEY': MAINNET_API_KEY
}
# === Payload to create a new named API key ===
payload = {
"name": "Milo" #input name
}
# === Request to create the key ===
try:
response = requests.post(
f"{MAINNET_API_URL}/api/v1/keys",
headers=headers,
json=payload,
timeout=30
)
response.raise_for_status()
result = response.json()
print("✅ New API key created successfully:")
print(json.dumps(result, indent=2))
except requests.exceptions.HTTPError as e:
print(f"❌ HTTP Error: {e}")
print(f"Response content: {e.response.text}")
except requests.exceptions.RequestException as e:
print(f"❌ Request Error: {e}")
except Exception as e:
print(f"❌ Unexpected Error: {e}")